diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 11a9c309..dc8f801e 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -12,18 +12,18 @@ #include "../flashcart_utils.h" #include "ed64_ll.h" #include "ed64.h" +#include "ed64_state.h" -// #include "../menu/settings.h" -// This is a trial hack before using the settings API. +// FIXME: Use one file using the ed64_pseudo_writeback_t struct. #ifndef LAST_SAVE_FILE_PATH -#define LAST_SAVE_FILE_PATH "/menu/last_rom.tmp" +#define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp" #endif #ifndef RESET_CHECK_FILE_PATH -#define RESET_CHECK_FILE_PATH "/menu/reset.tmp" +#define RESET_CHECK_FILE_PATH "/menu/ed_reset.tmp" #endif #ifndef FLASHRAM_CHECK_FILE_PATH -#define FLASHRAM_CHECK_FILE_PATH "/menu/flashram.tmp" +#define FLASHRAM_CHECK_FILE_PATH "/menu/ed_flashram.tmp" #endif extern int ed_exit (void); diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c new file mode 100644 index 00000000..57a5f5ab --- /dev/null +++ b/src/flashcart/ed64/ed64_state.c @@ -0,0 +1,42 @@ +#include +#include + +#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 ed64_pseudo_writeback_t init = { + .is_warm_start = false, + .last_rom_save_type = false, + .last_rom_path = "" +}; + + +void ed64_state_load (ed64_pseudo_writeback_t *state) { + if (!file_exists(ED64_STATE_FILE_PATH)) { + ed64_state_save(&init); + } + + 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->last_rom_path = strdup(mini_get_string(ini, "ed64", "last_rom_path", init.last_rom_path)); + + mini_free(ini); +} + +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_string(ini, "ed64", "last_rom_path", state->last_rom_path); + + mini_save(ini); + + mini_free(ini); +} diff --git a/src/flashcart/ed64/ed64_state.h b/src/flashcart/ed64/ed64_state.h new file mode 100644 index 00000000..7cd6d768 --- /dev/null +++ b/src/flashcart/ed64/ed64_state.h @@ -0,0 +1,26 @@ +/** + * @file settings.h + * @brief Menu Settings + * @ingroup menu + */ + +#ifndef FLASHCART_ED64_STATE_H__ +#define LASHCART_ED64_STATE_H__ + +#include + +/** @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 path to the last loaded ROM */ + char *last_rom_path; +} ed64_pseudo_writeback_t; + +void ed64_state_load (ed64_pseudo_writeback_t *state); +void ed64_state_save (ed64_pseudo_writeback_t *state); + + +#endif \ No newline at end of file