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_ll.c \
flashcart/sc64/sc64.c \ flashcart/sc64/sc64.c \
flashcart/ed64/ed64_ll.c \ flashcart/ed64/ed64_ll.c \
flashcart/ed64/ed64_state.c \
flashcart/ed64/ed64.c \ flashcart/ed64/ed64.c \
libs/libspng/spng/spng.c \ libs/libspng/spng/spng.c \
libs/mini.c/src/mini.c \ libs/mini.c/src/mini.c \

View File

@ -15,16 +15,12 @@
#include "ed64_state.h" #include "ed64_state.h"
static ed64_pseudo_writeback_t current_state;
// FIXME: Use one file using the ed64_pseudo_writeback_t struct. // FIXME: Use one file using the ed64_pseudo_writeback_t struct.
#ifndef LAST_SAVE_FILE_PATH #ifndef LAST_SAVE_FILE_PATH
#define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp" #define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp"
#endif #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); 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. // older everdrives cannot save during gameplay so we need to the reset method.
// works by checking if a file exists. // 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 if (current_state.is_warm_start == true) {
f_unlink(strip_sd_prefix(RESET_CHECK_FILE_PATH));
// 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 // finds the last save location
FIL lrp_fil; 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 // everdrive doesn't care about the save type other than flash sram and eeprom
// so minus flashram we can just check the size // 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); ed64_ll_get_fram(cartsave_data, save_size);
// deletes flag // 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 else if (save_size > KiB(2)) { // sram
ed64_ll_get_sram(cartsave_data, save_size); 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); 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 // 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 // this tells the cart to use flash instead of sram 128 since they are the same size
FIL flashfil; current_state.is_fram_save_type = true;
if (f_open(&flashfil, strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH), FA_CREATE_ALWAYS) != FR_OK) { ed64_state_save(&current_state);
f_close(&flashfil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&flashfil) != FR_OK) {
return FLASHCART_OK;
}
break; break;
default: default:
break; break;
@ -280,18 +273,8 @@ static flashcart_err_t ed64_load_save (char *save_path) {
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
FIL rsfil; current_state.is_warm_start = true;
ed64_state_save(&current_state);
// 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;
}
return FLASHCART_OK; return FLASHCART_OK;
} }

View File

@ -10,7 +10,7 @@
static ed64_pseudo_writeback_t init = { static ed64_pseudo_writeback_t init = {
.is_warm_start = false, .is_warm_start = false,
.last_rom_save_type = false, .is_fram_save_type = false,
.last_rom_path = "" .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); 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->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)); state->last_rom_path = strdup(mini_get_string(ini, "ed64", "last_rom_path", init.last_rom_path));
mini_free(ini); 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_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", "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_set_string(ini, "ed64", "last_rom_path", state->last_rom_path);
mini_save(ini); mini_save(ini);

View File

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