diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 046c14c4..626e1e2a 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,6 +14,11 @@ #include "ed64.h" #include "ed64_state.h" +#define ED64_STATE_FILE "ed64_state.ini" + +#ifndef ED64_OS_DIRECTORY +#define ED64_OS_DIRECTORY "/ED64" +#endif static ed64_pseudo_writeback_t current_state; @@ -29,6 +34,9 @@ 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. + // FIXME: should put the file in the OS dir, but different if a clone (ED64P). + char *state_path = "sd:/menu/"ED64_STATE_FILE; + ed64_state_init(state_path); ed64_state_load(¤t_state); if (current_state.is_expecting_save_writeback == true) { diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c index 3604e657..31e3e424 100644 --- a/src/flashcart/ed64/ed64_state.c +++ b/src/flashcart/ed64/ed64_state.c @@ -4,9 +4,7 @@ #include "ed64_state.h" #include "utils/fs.h" -#ifndef ED64_STATE_FILE_PATH -#define ED64_STATE_FILE_PATH "sd:/menu/ed64_state.ini" -#endif +static char *ed64_state_path = NULL; static ed64_pseudo_writeback_t init = { .is_expecting_save_writeback = false, @@ -14,13 +12,19 @@ static ed64_pseudo_writeback_t init = { .last_save_path = "" }; +void ed64_state_init (char *path) { + if (ed64_state_path) { + free(ed64_state_path); + } + ed64_state_path = strdup(path); +} void ed64_state_load (ed64_pseudo_writeback_t *state) { - if (!file_exists(ED64_STATE_FILE_PATH)) { + if (!file_exists(ed64_state_path)) { ed64_state_save(&init); } - mini_t *ini = mini_try_load(ED64_STATE_FILE_PATH); + mini_t *ini = mini_try_load(ed64_state_path); state->is_expecting_save_writeback = mini_get_bool(ini, "ed64", "is_expecting_save_writeback", init.is_expecting_save_writeback); state->is_fram_save_type = mini_get_bool(ini, "ed64", "is_fram_save_type", init.is_fram_save_type); @@ -30,7 +34,7 @@ void ed64_state_load (ed64_pseudo_writeback_t *state) { } 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_path); mini_set_bool(ini, "ed64", "is_expecting_save_writeback", state->is_expecting_save_writeback); mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type); diff --git a/src/flashcart/ed64/ed64_state.h b/src/flashcart/ed64/ed64_state.h index 3f53a148..4759768c 100644 --- a/src/flashcart/ed64/ed64_state.h +++ b/src/flashcart/ed64/ed64_state.h @@ -17,6 +17,8 @@ typedef struct { char *last_save_path; } ed64_pseudo_writeback_t; +/** @brief Init ED64 state path */ +void ed64_state_init (char *path); void ed64_state_load (ed64_pseudo_writeback_t *state); void ed64_state_save (ed64_pseudo_writeback_t *state);