From d677712b51e6d8c5d95d7d115aa1c114b6931777 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 21 Oct 2023 01:57:50 +0100 Subject: [PATCH] Finish state conversion for last save path (hopefully not broken). --- src/flashcart/ed64/ed64.c | 56 ++++++--------------------------- src/flashcart/ed64/ed64_state.c | 6 ++-- src/flashcart/ed64/ed64_state.h | 2 +- 3 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index e9022a31..89df5e71 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -17,11 +17,6 @@ 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 - extern int ed_exit (void); static flashcart_err_t ed64_init (void) { @@ -42,38 +37,17 @@ static flashcart_err_t ed64_init (void) { current_state.is_warm_start = false; ed64_state_save(¤t_state); - // finds the last save location - FIL lrp_fil; - UINT lrp_br; - - if (f_open(&lrp_fil, strip_sd_prefix(LAST_SAVE_FILE_PATH), FA_READ) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - - int lrp_size = f_size(&lrp_fil); - - TCHAR lrp_path[lrp_size++]; - - if (f_read(&lrp_fil, lrp_path, lrp_size, &lrp_br) != FR_OK) { - f_close(&lrp_fil); - return FLASHCART_ERR_LOAD; - } - - if (f_close(&lrp_fil) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - // Now save the content back to the SD card! FIL fil; - UINT br; + UINT bw; uint8_t cartsave_data[KiB(128)]; // find the path to last save - if (file_exists(strip_sd_prefix(lrp_path))) { + if (file_exists(strip_sd_prefix(current_state.last_save_path))) { - int save_size = file_get_size(strip_sd_prefix(lrp_path)); + int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); - if ((f_open(&fil, strip_sd_prefix(lrp_path), FA_CREATE_ALWAYS | FA_READ | FA_WRITE)) != FR_OK) { + if ((f_open(&fil, strip_sd_prefix(current_state.last_save_path), FA_CREATE_ALWAYS | FA_READ | FA_WRITE)) != FR_OK) { return FLASHCART_ERR_LOAD; } @@ -92,7 +66,7 @@ static flashcart_err_t ed64_init (void) { ed64_ll_get_eeprom(cartsave_data, save_size); } - if (f_write(&fil, cartsave_data, save_size, &br) != FR_OK) { + if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { return FLASHCART_ERR_LOAD; } @@ -100,6 +74,10 @@ static flashcart_err_t ed64_init (void) { return FLASHCART_ERR_LOAD; } } + else { + current_state.last_save_path = ""; + ed64_state_save(¤t_state); + } } return FLASHCART_OK; } @@ -258,21 +236,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { } - FIL lsp_fil; - UINT lsp_bw; - - if (f_open(&lsp_fil, strip_sd_prefix(LAST_SAVE_FILE_PATH), FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - if (f_write(&lsp_fil, strip_sd_prefix(save_path), strlen(save_path), &lsp_bw) != FR_OK) { - f_close(&lsp_fil); - return FLASHCART_ERR_LOAD; - } - - if (f_close(&lsp_fil) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - + current_state.last_save_path = save_path; current_state.is_warm_start = true; ed64_state_save(¤t_state); diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c index 392f677f..39dcc640 100644 --- a/src/flashcart/ed64/ed64_state.c +++ b/src/flashcart/ed64/ed64_state.c @@ -11,7 +11,7 @@ static ed64_pseudo_writeback_t init = { .is_warm_start = false, .is_fram_save_type = false, - .last_rom_path = "" + .last_save_path = "" }; @@ -24,7 +24,7 @@ void ed64_state_load (ed64_pseudo_writeback_t *state) { state->is_warm_start = mini_get_bool(ini, "ed64", "is_warm_start", init.is_warm_start); 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_save_path = strdup(mini_get_string(ini, "ed64", "last_save_path", init.last_save_path)); mini_free(ini); } @@ -34,7 +34,7 @@ void ed64_state_save (ed64_pseudo_writeback_t *state) { mini_set_bool(ini, "ed64", "is_warm_start", state->is_warm_start); 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_save_path", state->last_save_path); mini_save(ini); diff --git a/src/flashcart/ed64/ed64_state.h b/src/flashcart/ed64/ed64_state.h index 2ea719e0..ee4b20bd 100644 --- a/src/flashcart/ed64/ed64_state.h +++ b/src/flashcart/ed64/ed64_state.h @@ -14,7 +14,7 @@ typedef struct { /** @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; + char *last_save_path; } ed64_pseudo_writeback_t; void ed64_state_load (ed64_pseudo_writeback_t *state);