Move to struct for reset and fram state.

This commit is contained in:
Robin Jones 2023-10-21 00:40:02 +01:00
parent 7b4a675193
commit ff218daa09
4 changed files with 23 additions and 39 deletions

View File

@ -24,6 +24,7 @@ SRCS = \
flashcart/sc64/sc64_ll.c \
flashcart/sc64/sc64.c \
flashcart/ed64/ed64_ll.c \
flashcart/ed64/ed64_state.c \
flashcart/ed64/ed64.c \
libs/libspng/spng/spng.c \
libs/mini.c/src/mini.c \

View File

@ -15,16 +15,12 @@
#include "ed64_state.h"
static ed64_pseudo_writeback_t current_state;
// FIXME: Use one file using the ed64_pseudo_writeback_t struct.
#ifndef LAST_SAVE_FILE_PATH
#define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp"
#endif
#ifndef RESET_CHECK_FILE_PATH
#define RESET_CHECK_FILE_PATH "/menu/ed_reset.tmp"
#endif
#ifndef FLASHRAM_CHECK_FILE_PATH
#define FLASHRAM_CHECK_FILE_PATH "/menu/ed_flashram.tmp"
#endif
extern int ed_exit (void);
@ -38,10 +34,13 @@ static flashcart_err_t ed64_init (void) {
// older everdrives cannot save during gameplay so we need to the reset method.
// works by checking if a file exists.
if (file_exists(strip_sd_prefix(RESET_CHECK_FILE_PATH))) {
ed64_state_load(&current_state);
// make sure next boot doesnt trigger the check by deleting the reset file
f_unlink(strip_sd_prefix(RESET_CHECK_FILE_PATH));
if (current_state.is_warm_start == true) {
// make sure next boot doesnt trigger the check changing its state.
current_state.is_warm_start = false;
ed64_state_save(&current_state);
// finds the last save location
FIL lrp_fil;
@ -80,10 +79,11 @@ static flashcart_err_t ed64_init (void) {
// everdrive doesn't care about the save type other than flash sram and eeprom
// so minus flashram we can just check the size
if (file_exists(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH))) { // flashram is bugged atm
if (current_state.is_fram_save_type == true) { // flashram is bugged atm
ed64_ll_get_fram(cartsave_data, save_size);
// deletes flag
f_unlink(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH));
current_state.is_fram_save_type = false;
ed64_state_save(&current_state);
}
else if (save_size > KiB(2)) { // sram
ed64_ll_get_sram(cartsave_data, save_size);
@ -250,15 +250,8 @@ static flashcart_err_t ed64_load_save (char *save_path) {
ed64_ll_set_fram(cartsave_data, save_size);
// a cold and warm boot has no way of seeing save types and most types can be determined by size
// this tells the cart to use flash instead of sram 128 since they are the same size
FIL flashfil;
if (f_open(&flashfil, strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH), FA_CREATE_ALWAYS) != FR_OK) {
f_close(&flashfil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&flashfil) != FR_OK) {
return FLASHCART_OK;
}
current_state.is_fram_save_type = true;
ed64_state_save(&current_state);
break;
default:
break;
@ -280,18 +273,8 @@ static flashcart_err_t ed64_load_save (char *save_path) {
return FLASHCART_ERR_LOAD;
}
FIL rsfil;
// simulate a unix touch command to create a file as it only needs to exist to detect a reset
if (f_open(&rsfil, strip_sd_prefix(RESET_CHECK_FILE_PATH), FA_CREATE_ALWAYS) != FR_OK) {
f_close(&rsfil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&rsfil) != FR_OK) {
return FLASHCART_OK;
}
current_state.is_warm_start = true;
ed64_state_save(&current_state);
return FLASHCART_OK;
}

View File

@ -10,7 +10,7 @@
static ed64_pseudo_writeback_t init = {
.is_warm_start = false,
.last_rom_save_type = false,
.is_fram_save_type = false,
.last_rom_path = ""
};
@ -23,7 +23,7 @@ void ed64_state_load (ed64_pseudo_writeback_t *state) {
mini_t *ini = mini_try_load(ED64_STATE_FILE_PATH);
state->is_warm_start = mini_get_bool(ini, "ed64", "is_warm_start", init.is_warm_start);
state->last_rom_save_type = mini_get_bool(ini, "ed64", "last_rom_save_type", init.last_rom_save_type);
state->is_fram_save_type = mini_get_bool(ini, "ed64", "is_fram_save_type", init.is_fram_save_type);
state->last_rom_path = strdup(mini_get_string(ini, "ed64", "last_rom_path", init.last_rom_path));
mini_free(ini);
@ -33,7 +33,7 @@ void ed64_state_save (ed64_pseudo_writeback_t *state) {
mini_t *ini = mini_create(ED64_STATE_FILE_PATH);
mini_set_bool(ini, "ed64", "is_warm_start", state->is_warm_start);
mini_set_bool(ini, "ed64", "last_rom_save_type", state->last_rom_save_type);
mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type);
mini_set_string(ini, "ed64", "last_rom_path", state->last_rom_path);
mini_save(ini);

View File

@ -5,16 +5,16 @@
*/
#ifndef FLASHCART_ED64_STATE_H__
#define LASHCART_ED64_STATE_H__
#define FLASHCART_ED64_STATE_H__
#include <stdint.h>
/** @brief ed64 pseudo Writeback Structure */
/** @brief ED64 Pseudo Writeback Structure */
typedef struct {
/** @brief The reset button was used */
bool is_warm_start;
/** @brief The last save type used */
bool last_rom_save_type; // FIXME: for the moment only a bool for flashram
/** @brief The last save type was flash ram */
bool is_fram_save_type;
/** @brief The path to the last loaded ROM */
char *last_rom_path;
} ed64_pseudo_writeback_t;