From 43852fe7d1e5382eb9d6b5ee944e97ac94b744af Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 24 Oct 2023 00:35:28 +0100 Subject: [PATCH 01/42] Improve savetype state --- src/flashcart/ed64/ed64.c | 44 ++++++++++++++------------------- src/flashcart/ed64/ed64_state.c | 6 ++--- src/flashcart/ed64/ed64_state.h | 2 +- src/menu/settings.c | 10 -------- src/menu/settings.h | 3 --- 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 666e45d91..a37e91919 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -33,11 +33,7 @@ static flashcart_err_t ed64_init (void) { if (current_state.is_expecting_save_writeback == true) { - // make sure next boot doesnt trigger the check changing its state. - current_state.is_expecting_save_writeback = false; - ed64_state_save(¤t_state); - - // Now save the content back to the SD card! + // save the content back to the SD card! FIL fil; UINT bw; uint8_t cartsave_data[KiB(128)]; @@ -53,11 +49,8 @@ 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 (current_state.is_fram_save_type == true) { // flashram is bugged atm + if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { // flashram is bugged atm ed64_ll_get_fram(cartsave_data, save_size); - // deletes flag - current_state.is_fram_save_type = false; - ed64_state_save(¤t_state); } else if (save_size > KiB(32)) { // sram 128 ed64_ll_get_sram(cartsave_data, save_size); @@ -77,12 +70,12 @@ static flashcart_err_t ed64_init (void) { return FLASHCART_ERR_LOAD; } } - else { - current_state.is_expecting_save_writeback = false; - current_state.is_fram_save_type = false; - current_state.last_save_path = ""; - ed64_state_save(¤t_state); - } + + // make sure next boot doesnt trigger the check changing its state. + current_state.is_expecting_save_writeback = false; + current_state.is_save_type = SAVE_TYPE_NONE; + current_state.last_save_path = ""; + ed64_state_save(¤t_state); } return FLASHCART_OK; } @@ -216,10 +209,10 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - size_t save_size = file_get_size(strip_sd_prefix(save_path)); - uint8_t cartsave_data[save_size]; + size_t save_file_size = file_get_size(strip_sd_prefix(save_path)); + uint8_t cartsave_data[save_file_size]; - if (f_read(&fil, cartsave_data, save_size, &br) != FR_OK) { + if (f_read(&fil, cartsave_data, save_file_size, &br) != FR_OK) { f_close(&fil); return FLASHCART_ERR_LOAD; } @@ -228,25 +221,21 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - current_state.is_fram_save_type = false; + current_state.is_save_type = SAVE_TYPE_NONE; ed64_save_type_t type = ed64_ll_get_save_type(); switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, save_size); + ed64_ll_set_eeprom(cartsave_data, save_file_size); break; case SAVE_TYPE_SRAM: - ed64_ll_set_sram(cartsave_data, save_size); + ed64_ll_set_sram(cartsave_data, save_file_size); case SAVE_TYPE_SRAM_128K: ed64_ll_set_sram_128(cartsave_data, KiB(128)); break; case SAVE_TYPE_FLASHRAM: ed64_ll_set_fram(cartsave_data, KiB(128)); - // 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 - current_state.is_fram_save_type = true; - ed64_state_save(¤t_state); break; case SAVE_TYPE_DD64_CART_PORT: break; @@ -254,7 +243,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { break; } - + //current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() current_state.last_save_path = save_path; current_state.is_expecting_save_writeback = true; ed64_state_save(¤t_state); @@ -292,6 +281,9 @@ static flashcart_err_t ed64_set_save_type (flashcart_save_type_t save_type) { ed64_ll_set_save_type(type); + current_state.is_save_type = type; + ed64_state_save(¤t_state); + return FLASHCART_OK; } diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c index ee29bab78..c285e75c3 100644 --- a/src/flashcart/ed64/ed64_state.c +++ b/src/flashcart/ed64/ed64_state.c @@ -10,7 +10,7 @@ static ed64_pseudo_writeback_t init = { .is_expecting_save_writeback = false, - .is_fram_save_type = false, + .is_save_type = 0, .last_save_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_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); + state->is_save_type = mini_get_int(ini, "ed64", "is_save_type", init.is_save_type); state->last_save_path = strdup(mini_get_string(ini, "ed64", "last_save_path", init.last_save_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_expecting_save_writeback", state->is_expecting_save_writeback); - mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type); + mini_set_int(ini, "ed64", "is_fram_save_type", state->is_save_type); 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 3f53a1480..83f3dd262 100644 --- a/src/flashcart/ed64/ed64_state.h +++ b/src/flashcart/ed64/ed64_state.h @@ -12,7 +12,7 @@ typedef struct { /** @brief The reset button was used */ bool is_expecting_save_writeback; /** @brief The last save type was flash ram */ - bool is_fram_save_type; + int is_save_type; /** @brief The path to the last loaded ROM */ char *last_save_path; } ed64_pseudo_writeback_t; diff --git a/src/menu/settings.c b/src/menu/settings.c index bb85a108a..686b460f5 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -14,9 +14,6 @@ static settings_t init = { .default_directory = "/", .use_saves_folder = true, - /* flashcart specific feature flags */ - .last_rom_path = "/", - /* Beta feature flags */ .bgm_enabled = false, .sound_enabled = false, @@ -37,10 +34,6 @@ void settings_load (settings_t *settings) { settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory)); settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder); - /* flashcart specific feature flags */ - settings->last_rom_path = strdup(mini_get_string(ini, "menu", "last_rom_path", init.last_rom_path)); - - /* Beta feature flags, they might not be in the file */ settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled); @@ -58,9 +51,6 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "show_hidden_files", settings->hidden_files_enabled); mini_set_string(ini, "menu", "default_directory", settings->default_directory); mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder); - - /* flashcart specific feature flags */ - mini_set_string(ini, "menu", "last_rom_path", init.last_rom_path); /* Beta feature flags, they should not save until production ready! */ // mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); diff --git a/src/menu/settings.h b/src/menu/settings.h index a9a334f42..844dc5f6b 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -31,9 +31,6 @@ typedef struct { /** @brief Enable rumble feedback */ bool rumble_enabled; - /** @brief filepath of last ROM (for save writeback emulation if required) */ - char *last_rom_path; - /** @brief Enable auto firmware updates */ bool auto_firmware_update_enabled; From 55268cfd2cad28d1362c5141e9bbf89f73463308 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 24 Oct 2023 00:52:19 +0100 Subject: [PATCH 02/42] Improve writeback --- src/flashcart/ed64/ed64.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index a37e91919..5b0c85197 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -39,7 +39,7 @@ static flashcart_err_t ed64_init (void) { uint8_t cartsave_data[KiB(128)]; // find the path to last save - if (file_exists(strip_sd_prefix(current_state.last_save_path))) { + if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); @@ -49,16 +49,16 @@ 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 (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { // flashram is bugged atm + if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { ed64_ll_get_fram(cartsave_data, save_size); } - else if (save_size > KiB(32)) { // sram 128 + else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K) { ed64_ll_get_sram(cartsave_data, save_size); } - else if (save_size > KiB(2)) { // sram + else if (current_state.is_save_type == SAVE_TYPE_SRAM) { ed64_ll_get_sram(cartsave_data, save_size); } - else { // eeprom + else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { ed64_ll_get_eeprom(cartsave_data, save_size); } From 63292bab030f586845e47c8179633e178b2dfeb8 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 14:22:29 +0100 Subject: [PATCH 03/42] Fix rom size Improve file load --- src/flashcart/ed64/ed64.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 5b0c85197..1f605f29c 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -52,10 +52,7 @@ static flashcart_err_t ed64_init (void) { if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { ed64_ll_get_fram(cartsave_data, save_size); } - else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K) { - ed64_ll_get_sram(cartsave_data, save_size); - } - else if (current_state.is_save_type == SAVE_TYPE_SRAM) { + else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K || current_state.is_save_type == SAVE_TYPE_SRAM) { ed64_ll_get_sram(cartsave_data, save_size); } else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { @@ -118,7 +115,7 @@ static flashcart_err_t ed64_load_rom (char *rom_path, flashcart_progress_callbac return FLASHCART_ERR_LOAD; } - if (rom_size == MiB(64)) { + if (rom_size <= MiB(64)) { ed64_save_type_t type = ed64_ll_get_save_type(); switch (type) { case SAVE_TYPE_SRAM: From 047e74cfae1ad01c51b758e2b48d9f779ff03927 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 14:44:55 +0100 Subject: [PATCH 04/42] Use switch rather than if --- src/flashcart/ed64/ed64.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 1f605f29c..524251a5d 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,7 +14,9 @@ #include "ed64.h" #include "ed64_state.h" - +/** + * The ED64's current state + */ static ed64_pseudo_writeback_t current_state; extern int ed_exit (void); @@ -47,16 +49,22 @@ static flashcart_err_t ed64_init (void) { return FLASHCART_ERR_LOAD; } - // everdrive doesn't care about the save type other than flash sram and eeprom - // so minus flashram we can just check the size - if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { - ed64_ll_get_fram(cartsave_data, save_size); - } - else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K || current_state.is_save_type == SAVE_TYPE_SRAM) { - ed64_ll_get_sram(cartsave_data, save_size); - } - else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { - ed64_ll_get_eeprom(cartsave_data, save_size); + switch (current_state.is_save_type) { + case SAVE_TYPE_EEPROM_4K: + case SAVE_TYPE_EEPROM_16K: + ed64_ll_get_eeprom(cartsave_data, save_size); + break; + case SAVE_TYPE_SRAM: + case SAVE_TYPE_SRAM_128K: + ed64_ll_get_sram(cartsave_data, save_size); + break; + case SAVE_TYPE_FLASHRAM: + ed64_ll_get_fram(cartsave_data, save_size); + break; + case SAVE_TYPE_DD64_CART_PORT: + break; + default: + break; } if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { From 41d05d2204971ccce9593dd6a9813d80ff21412f Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 16:01:07 +0100 Subject: [PATCH 05/42] Improve some comments --- src/flashcart/ed64/ed64.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 524251a5d..7846a89fc 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -33,6 +33,8 @@ static flashcart_err_t ed64_init (void) { ed64_state_load(¤t_state); + // FIXME: should be checking whether the console was a hot restart here! + // Cold restarts are only available with battery backup. if (current_state.is_expecting_save_writeback == true) { // save the content back to the SD card! @@ -117,7 +119,7 @@ static flashcart_err_t ed64_load_rom (char *rom_path, flashcart_progress_callbac // FIXME: if the cart is not V3 or X5 or X7, we need probably need to - 128KiB for save compatibility. // Or somehow warn that certain ROM's will have corruption due to the address space being used for saves. - // Conker's Bad Fur Day doesn't have this issue because eeprom data is at a fixed address in pif ram. + // EEPROM saves should be unaffected. if (rom_size > MiB(64)) { f_close(&fil); return FLASHCART_ERR_LOAD; @@ -177,6 +179,7 @@ static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uin // FIXME: if the cart is not V3 or X5 or X7, we need probably need to - 128KiB for save compatibility. // Or somehow warn that certain ROM's will have corruption due to the address space being used for saves. + // EEPROM saves should be unaffected. if (file_size > (MiB(64) - rom_offset)) { f_close(&fil); From b3cdc6bb5dbca00ff002021f0f3fe5bc42c15a83 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 18:04:53 +0100 Subject: [PATCH 06/42] Add device variant (requires full implementation) --- src/flashcart/ed64/ed64.c | 11 ++++++----- src/flashcart/ed64/ed64_ll.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 7846a89fc..8bda01906 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,6 +14,9 @@ #include "ed64.h" #include "ed64_state.h" + +// static ed64_device_variant_t device_variant = DEVICE_VARIANT_UNKNOWN; + /** * The ED64's current state */ @@ -207,7 +210,7 @@ static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uin return FLASHCART_OK; } -static flashcart_err_t ed64_load_save (char *save_path) { +static flashcart_err_t ed64_load_save (char *save_path) { // from file FIL fil; UINT br; @@ -229,9 +232,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - current_state.is_save_type = SAVE_TYPE_NONE; - - ed64_save_type_t type = ed64_ll_get_save_type(); + ed64_save_type_t type = ed64_ll_get_save_type(); // current_state.is_save_type; switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: @@ -251,7 +252,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { break; } - //current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() + current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() current_state.last_save_path = save_path; current_state.is_expecting_save_writeback = true; ed64_state_save(¤t_state); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index e44362629..b2b66fcbe 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -51,6 +51,18 @@ */ +typedef enum { + DEVICE_VARIANT_UNKNOWN = 0x0000, + // // DEVICE_VARIANT_X7_0 = 0x4000, + // // DEVICE_VARIANT_X5_0 = 0x4000, + DEVICE_VARIANT_V3_0 = 0x3000, + DEVICE_VARIANT_V2_5 = 0x2500, + DEVICE_VARIANT_V2_0 = 0x2000, + // DEVICE_VARIANT_V1_0 = 0x1000, + // // DEVICE_VARIANT_P1_0 = 0x1000, +} ed64_device_variant_t; + + typedef enum { SAVE_TYPE_NONE = 0, SAVE_TYPE_SRAM = 1, From db4c73c7aa4bfb04f1c98712bacaed841037746a Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 19:07:58 +0100 Subject: [PATCH 07/42] Move save on init to a seperate function. --- src/flashcart/ed64/ed64.c | 103 +++++++++++++++++++---------------- src/flashcart/ed64/ed64_ll.c | 2 + 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 8bda01906..2ec1d8cb6 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,7 +14,9 @@ #include "ed64.h" #include "ed64_state.h" - +/** + * The ED64's variant, read from the CPLD + */ // static ed64_device_variant_t device_variant = DEVICE_VARIANT_UNKNOWN; /** @@ -23,6 +25,7 @@ static ed64_pseudo_writeback_t current_state; extern int ed_exit (void); +static flashcart_err_t ed64_pesudo_set_save_writeback (void); static flashcart_err_t ed64_init (void) { @@ -40,52 +43,7 @@ static flashcart_err_t ed64_init (void) { // Cold restarts are only available with battery backup. if (current_state.is_expecting_save_writeback == true) { - // save the content back to the SD card! - FIL fil; - UINT bw; - uint8_t cartsave_data[KiB(128)]; - - // find the path to last save - if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { - - int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); - - 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; - } - - switch (current_state.is_save_type) { - case SAVE_TYPE_EEPROM_4K: - case SAVE_TYPE_EEPROM_16K: - ed64_ll_get_eeprom(cartsave_data, save_size); - break; - case SAVE_TYPE_SRAM: - case SAVE_TYPE_SRAM_128K: - ed64_ll_get_sram(cartsave_data, save_size); - break; - case SAVE_TYPE_FLASHRAM: - ed64_ll_get_fram(cartsave_data, save_size); - break; - case SAVE_TYPE_DD64_CART_PORT: - break; - default: - break; - } - - if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - - if (f_close(&fil) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - } - - // make sure next boot doesnt trigger the check changing its state. - current_state.is_expecting_save_writeback = false; - current_state.is_save_type = SAVE_TYPE_NONE; - current_state.last_save_path = ""; - ed64_state_save(¤t_state); + return ed64_pesudo_set_save_writeback(); } return FLASHCART_OK; } @@ -296,6 +254,57 @@ static flashcart_err_t ed64_set_save_type (flashcart_save_type_t save_type) { return FLASHCART_OK; } +static flashcart_err_t ed64_pesudo_set_save_writeback (void) { + // save the content back to the SD card! + FIL fil; + UINT bw; + uint8_t cartsave_data[KiB(128)]; + + // find the path to last save + if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { + + int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); + + 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; + } + + switch (current_state.is_save_type) { + case SAVE_TYPE_EEPROM_4K: + case SAVE_TYPE_EEPROM_16K: + ed64_ll_get_eeprom(cartsave_data, save_size); + break; + case SAVE_TYPE_SRAM: + case SAVE_TYPE_SRAM_128K: + ed64_ll_get_sram(cartsave_data, save_size); + break; + case SAVE_TYPE_FLASHRAM: + ed64_ll_get_fram(cartsave_data, save_size); + break; + case SAVE_TYPE_DD64_CART_PORT: + break; + default: + break; + } + + if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + if (f_close(&fil) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + } + + // make sure next boot doesn't trigger the check changing its state. + current_state.is_expecting_save_writeback = false; + current_state.is_save_type = SAVE_TYPE_NONE; + current_state.last_save_path = ""; + ed64_state_save(¤t_state); + + return FLASHCART_OK; +} + static flashcart_t flashcart_ed64 = { .init = ed64_init, .deinit = ed64_deinit, diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 23b2fe025..70e2e8105 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -25,6 +25,8 @@ typedef enum { } ed64_registers_t; +// #define DEVICE_VARIANT_MASK (0xF000) + void pi_initialize (void); void pi_initialize_sram (void); void pi_dma_from_cart (void* dest, void* src, unsigned long size); From 05675e8043fca6e421c3abf5b4746f8b93ded2f4 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 19:36:16 +0100 Subject: [PATCH 08/42] Start adding device variants --- src/flashcart/64drive/64drive_ll.c | 8 ++++---- src/flashcart/ed64/ed64_ll.c | 2 +- src/flashcart/ed64/ed64_ll.h | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/flashcart/64drive/64drive_ll.c b/src/flashcart/64drive/64drive_ll.c index fb00a89c0..d0a02ce0a 100644 --- a/src/flashcart/64drive/64drive_ll.c +++ b/src/flashcart/64drive/64drive_ll.c @@ -6,8 +6,8 @@ #define CI_STATUS_BUSY (1 << 12) -#define DEVICE_VARIANT_MASK (0xFFFF) -#define FPGA_REVISION_MASK (0xFFFF) +#define D64_DEVICE_VARIANT_MASK (0xFFFF) +#define D64_FPGA_REVISION_MASK (0xFFFF) typedef enum { @@ -46,8 +46,8 @@ bool d64_ll_get_version (d64_device_variant_t *device_variant, uint16_t *fpga_re if (d64_ll_ci_wait()) { return true; } - *device_variant = (d64_device_variant_t) (io_read((uint32_t) (&d64_regs->VARIANT)) & DEVICE_VARIANT_MASK); - *fpga_revision = (io_read((uint32_t) (&d64_regs->REVISION)) & FPGA_REVISION_MASK); + *device_variant = (d64_device_variant_t) (io_read((uint32_t) (&d64_regs->VARIANT)) & D64_DEVICE_VARIANT_MASK); + *fpga_revision = (io_read((uint32_t) (&d64_regs->REVISION)) & D64_FPGA_REVISION_MASK); *bootloader_version = io_read((uint32_t) (&d64_regs->PERSISTENT)); return d64_ll_ci_wait(); } diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 70e2e8105..b634c196e 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -25,7 +25,7 @@ typedef enum { } ed64_registers_t; -// #define DEVICE_VARIANT_MASK (0xF000) +#define ED64_DEVICE_VARIANT_MASK (0xF000) void pi_initialize (void); void pi_initialize_sram (void); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index b2b66fcbe..7798091bb 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -52,14 +52,14 @@ typedef enum { - DEVICE_VARIANT_UNKNOWN = 0x0000, - // // DEVICE_VARIANT_X7_0 = 0x4000, - // // DEVICE_VARIANT_X5_0 = 0x4000, + DEVICE_VARIANT_UNKNOWN = 0xFFFF, + DEVICE_VARIANT_X7_0 = 0x7000, + DEVICE_VARIANT_X5_0 = 0x5000, DEVICE_VARIANT_V3_0 = 0x3000, - DEVICE_VARIANT_V2_5 = 0x2500, - DEVICE_VARIANT_V2_0 = 0x2000, - // DEVICE_VARIANT_V1_0 = 0x1000, - // // DEVICE_VARIANT_P1_0 = 0x1000, + DEVICE_VARIANT_V2_5 = 0x2000, + DEVICE_VARIANT_V2_0 = 0x0000, + DEVICE_VARIANT_V1_0 = 0x0000, + DEVICE_VARIANT_P1_0 = 0x0000 } ed64_device_variant_t; From c88e69cbc8e1a239c67ee0ced032412d302c603b Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 22:48:37 +0100 Subject: [PATCH 09/42] Update ed64_ll.c Improve save registers --- src/flashcart/ed64/ed64_ll.c | 94 +++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index b634c196e..810755ee0 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -8,23 +8,26 @@ /* ED64 configuration registers base address */ #define ED64_CONFIG_REGS_BASE (0xA8040000) +/* ED64 configuration registers */ typedef enum { - // REG_CFG = 0, - // REG_STATUS = 1, - // REG_DMA_LENGTH = 2, - // REG_DMA_RAM_ADDR = 3, - // REG_MSG = 4, - // REG_DMA_CFG = 5, - // REG_SPI = 6, - // REG_SPI_CFG = 7, - // REG_KEY = 8, - REG_SAV_CFG = 9, - // REG_SEC = 10, /* Sectors?? */ - // REG_FPGA_VERSION = 11, /* Altera (Intel) MAX */ - // REG_GPIO = 12, - -} ed64_registers_t; - + // REG_CFG = 0x00, + // REG_STATUS = 0x01, + // REG_DMA_LENGTH = 0x02, + // REG_DMA_RAM_ADDR = 0x03, + // REG_MSG = 0x04, + // REG_DMA_CFG = 0x05, + // REG_SPI = 0x06, + // REG_SPI_CFG = 0x07, + // REG_KEY = 0x08, + REG_SAV_CFG = 0x09, + // REG_SEC = 0x0A, /* Sectors?? */ + // REG_FPGA_VERSION = 0x0B, //11, /* Altera (Intel) MAX */ + // REG_GPIO = 0x0C, //12, + +} ed64_ci_registers_id_t; + + +/* ED64 Device Variant Mask */ #define ED64_DEVICE_VARIANT_MASK (0xF000) void pi_initialize (void); @@ -38,13 +41,14 @@ void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size); void ed64_ll_set_sdcard_timing (void); -#define SAV_EEP_ON 1 -#define SAV_SRM_ON 2 -#define SAV_EEP_SIZE 4 -#define SAV_SRM_SIZE 8 - -#define SAV_RAM_BANK 128 -#define SAV_RAM_BANK_APPLY 32768 +typedef enum { + SAV_EEP_ON_OFF = 0x01, + SAV_SRM_ON_OFF = 0x02, + SAV_EEP_SMALL_BIG = 0x04, + SAV_SRM_SMALL_BIG = 0x08, + SAV_RAM_BANK = 128, + SAV_RAM_BANK_APPLY = 32768 +} ed64_v_save_register_id_t; uint32_t ed64_ll_reg_read (uint32_t reg); void ed64_ll_reg_write (uint32_t reg, uint32_t data); @@ -78,46 +82,46 @@ ed64_save_type_t ed64_ll_get_save_type (void) { void ed64_ll_set_save_type (ed64_save_type_t type) { uint16_t save_cfg; - uint8_t eeprom_on, sram_on, eeprom_size, sram_size, ram_bank; + uint8_t is_eeprom, is_sram, is_eeprom_16k, is_sram_128k, using_ram_bank; ed64_ll_save_type = type; - eeprom_on = 0; - sram_on = 0; - eeprom_size = 0; - sram_size = 0; - ram_bank = ed64_ll_sram_bank; + is_eeprom = false; + is_sram = false; + is_eeprom_16k = false; + is_sram_128k = false; + using_ram_bank = ed64_ll_sram_bank; switch (type) { case SAVE_TYPE_EEPROM_16K: - eeprom_on = 1; - eeprom_size = 1; + is_eeprom = true; + is_eeprom_16k = true; break; case SAVE_TYPE_EEPROM_4K: - eeprom_on = 1; + is_eeprom = true; break; case SAVE_TYPE_SRAM: - sram_on = 1; + is_sram = true; break; case SAVE_TYPE_SRAM_128K: - sram_on = 1; - sram_size = 1; + is_sram = true; + is_sram_128k = true; break; case SAVE_TYPE_FLASHRAM: - sram_on = 0; - sram_size = 1; + is_sram = false; + is_sram_128k = true; break; default: - sram_on = 0; - sram_size = 0; - ram_bank = 1; + is_sram = false; + is_sram_128k = false; + using_ram_bank = 1; break; } - if (eeprom_on)save_cfg |= SAV_EEP_ON; - if (sram_on)save_cfg |= SAV_SRM_ON; - if (eeprom_size)save_cfg |= SAV_EEP_SIZE; - if (sram_size)save_cfg |= SAV_SRM_SIZE; - if (ram_bank)save_cfg |= SAV_RAM_BANK; + if (is_eeprom)save_cfg |= SAV_EEP_ON_OFF; + if (is_sram)save_cfg |= SAV_SRM_ON_OFF; + if (is_eeprom_16k)save_cfg |= SAV_EEP_SMALL_BIG; + if (is_sram_128k)save_cfg |= SAV_SRM_SMALL_BIG; + if (using_ram_bank)save_cfg |= SAV_RAM_BANK; save_cfg |= SAV_RAM_BANK_APPLY; ed64_ll_reg_write(REG_SAV_CFG, save_cfg); From 404f977c073070fc547abe4e9bc5dd306ced8c83 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sun, 29 Oct 2023 00:04:15 +0100 Subject: [PATCH 10/42] Work on EEPROM get and set --- src/flashcart/ed64/ed64.c | 4 +-- src/flashcart/ed64/ed64_ll.c | 49 ++++++++++++++++++++++++++++-------- src/flashcart/ed64/ed64_ll.h | 4 +-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 2ec1d8cb6..4cc1975ea 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -194,7 +194,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, save_file_size); + ed64_ll_set_eeprom(cartsave_data, type, false); break; case SAVE_TYPE_SRAM: ed64_ll_set_sram(cartsave_data, save_file_size); @@ -272,7 +272,7 @@ static flashcart_err_t ed64_pesudo_set_save_writeback (void) { switch (current_state.is_save_type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_get_eeprom(cartsave_data, save_size); + ed64_ll_get_eeprom(cartsave_data, current_state.is_save_type); break; case SAVE_TYPE_SRAM: case SAVE_TYPE_SRAM_128K: diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 810755ee0..5680fd3a0 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -287,14 +287,22 @@ int ed64_ll_get_sram (uint8_t *buffer, int size) { } -int ed64_ll_get_eeprom (uint8_t *buffer, int size) { +void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { - int blocks=size/8; - for( int b = 0; b < blocks; b++ ) { - eeprom_read( b, &buffer[b * 8] ); + + uint32_t i; + uint32_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (slen == 0) { + return; } - return 1; + ed64_ll_set_save_type(eep_type); + eeprom_present(); + + for (i = 0; i < slen * 512; i += 8) { + eeprom_read(i / 8, &buffer[i]); + } + ed64_ll_set_save_type(SAVE_TYPE_NONE); } @@ -373,15 +381,36 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { } -int ed64_ll_set_eeprom (uint8_t *buffer, int size) { +uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { - int blocks=size/8; - for( int b = 0; b < blocks; b++ ) { - eeprom_write( b, &buffer[b * 8] ); + uint8_t buff[2048]; + uint32_t i; + uint8_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (slen == 0) { + return 0; } - return 1; + ed64_ll_set_save_type(eep_type); + eeprom_present(); + + for (i = 0; i < slen * 512; i += 8) { + eeprom_write(i / 8, &src[i]); + } + + if (verify) { + for (i = 0; i < slen * 512; i += 8) { + eeprom_read(i / 8, &buff[i]); + } + for (i = 0; i < slen * 512; i++) { + if (src[i] != buff[i]) { + return 1; //ERR_EEP_CHECK; + } + } + } + + ed64_ll_set_save_type(SAVE_TYPE_NONE); + return 0; } int ed64_ll_set_fram (uint8_t *buffer, int size) { diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 7798091bb..2cbfc07bb 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -83,12 +83,12 @@ void ed64_ll_set_save_type (ed64_save_type_t type); int ed64_ll_get_sram_128 (uint8_t *buffer, int size); int ed64_ll_get_sram (uint8_t *buffer, int size); -int ed64_ll_get_eeprom (uint8_t *buffer, int size); +void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t type); int ed64_ll_get_fram (uint8_t *buffer, int size); int ed64_ll_set_sram_128 (uint8_t *buffer, int size); int ed64_ll_set_sram (uint8_t *buffer, int size); -int ed64_ll_set_eeprom (uint8_t *buffer, int size); +uint8_t ed64_ll_set_eeprom (uint8_t *src, uint8_t eep_type, bool verify); int ed64_ll_set_fram (uint8_t *buffer, int size); /** @} */ /* ed64 */ From b06e8f258b5b7ae91c8ac218981d077710a51ffd Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 19:19:51 +0000 Subject: [PATCH 11/42] Fix eeprom get-set --- src/flashcart/ed64/ed64.c | 1 + src/flashcart/ed64/ed64_ll.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 4cc1975ea..75cabe8c8 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -41,6 +41,7 @@ static flashcart_err_t ed64_init (void) { // FIXME: should be checking whether the console was a hot restart here! // Cold restarts are only available with battery backup. + // if (sys_reset_type() != RESET_COLD || RTC == true) if (current_state.is_expecting_save_writeback == true) { return ed64_pesudo_set_save_writeback(); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 5680fd3a0..c1d2d1e60 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -291,15 +291,15 @@ void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { uint32_t i; - uint32_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (slen == 0) { + uint32_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (size == 0) { return; } ed64_ll_set_save_type(eep_type); eeprom_present(); - for (i = 0; i < slen * 512; i += 8) { + for (i = 0; i < size; i += 8) { eeprom_read(i / 8, &buffer[i]); } ed64_ll_set_save_type(SAVE_TYPE_NONE); @@ -383,26 +383,27 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { - uint8_t buff[2048]; + uint8_t buffer[2048]; uint32_t i; - uint8_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (slen == 0) { + uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + + if (size == 0) { return 0; } ed64_ll_set_save_type(eep_type); eeprom_present(); - for (i = 0; i < slen * 512; i += 8) { + for (i = 0; i < size; i += 8) { eeprom_write(i / 8, &src[i]); } if (verify) { - for (i = 0; i < slen * 512; i += 8) { - eeprom_read(i / 8, &buff[i]); + for (i = 0; i < size; i += 8) { + eeprom_read(i / 8, &buffer[i]); } - for (i = 0; i < slen * 512; i++) { - if (src[i] != buff[i]) { + for (i = 0; i < size; i++) { + if (src[i] != buffer[i]) { return 1; //ERR_EEP_CHECK; } } From a4878112c1cf3e21ab5b278241e0072c5233b84e Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 21:33:54 +0000 Subject: [PATCH 12/42] Further EEPROM improvements Possibly corrects a few last commits. --- src/flashcart/ed64/ed64.c | 2 +- src/flashcart/ed64/ed64_ll.c | 51 ++++++++++++++++++------------------ src/flashcart/ed64/ed64_ll.h | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 75cabe8c8..fab2775df 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -195,7 +195,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, type, false); + ed64_ll_set_eeprom(cartsave_data, type); break; case SAVE_TYPE_SRAM: ed64_ll_set_sram(cartsave_data, save_file_size); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index c1d2d1e60..ff0e3c2f2 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -289,18 +289,16 @@ int ed64_ll_get_sram (uint8_t *buffer, int size) { void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { - - uint32_t i; uint32_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (size == 0) { - return; - } - ed64_ll_set_save_type(eep_type); - eeprom_present(); + if (size != 0) { + ed64_ll_set_save_type(eep_type); + if (eeprom_present()) { // FIXME: does not correctly check type. - for (i = 0; i < size; i += 8) { - eeprom_read(i / 8, &buffer[i]); + for (uint32_t i = 0; i < size; i += 8) { + eeprom_read(i / 8, &buffer[i]); + } + } } ed64_ll_set_save_type(SAVE_TYPE_NONE); @@ -381,32 +379,35 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { } -uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { +// uint8_t ed64_ll_set_eeprom(uint8_t *buffer, eeprom_type_t eep_type, bool verify) { +uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { - uint8_t buffer[2048]; - uint32_t i; uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (size == 0) { + if (size == 0) { // SAVE_TYPE_NONE return 0; } ed64_ll_set_save_type(eep_type); - eeprom_present(); - for (i = 0; i < size; i += 8) { - eeprom_write(i / 8, &src[i]); - } + if (eeprom_present()) { // FIXME: does not correctly check type. - if (verify) { - for (i = 0; i < size; i += 8) { - eeprom_read(i / 8, &buffer[i]); - } - for (i = 0; i < size; i++) { - if (src[i] != buffer[i]) { - return 1; //ERR_EEP_CHECK; - } + for (uint32_t i = 0; i < size; i += 8) { + eeprom_write(i / 8, &buffer[i]); } + + // if (verify) { // FIXME: This is a smoke test and should be seperated! + // uint8_t tmp_buffer[2048]; + // uint32_t j; + // for (j = 0; j < size; j += 8) { + // eeprom_read(j / 8, &tmp_buffer[j]); + // } + // for (j = 0; j < size; j++) { + // if (buffer[j] != tmp_buffer[j]) { + // return 1; //ERR_EEP_CHECK; + // } + // } + // } } ed64_ll_set_save_type(SAVE_TYPE_NONE); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 2cbfc07bb..77393210c 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -88,7 +88,7 @@ int ed64_ll_get_fram (uint8_t *buffer, int size); int ed64_ll_set_sram_128 (uint8_t *buffer, int size); int ed64_ll_set_sram (uint8_t *buffer, int size); -uint8_t ed64_ll_set_eeprom (uint8_t *src, uint8_t eep_type, bool verify); +uint8_t ed64_ll_set_eeprom (uint8_t *buffer, uint8_t eep_type); int ed64_ll_set_fram (uint8_t *buffer, int size); /** @} */ /* ed64 */ From 9a217afc0f263f4f21748b450fcab4c265e0a8cc Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 21:46:10 +0000 Subject: [PATCH 13/42] Dont reset save types --- src/flashcart/ed64/ed64_ll.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index ff0e3c2f2..6aa06606e 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -300,7 +300,6 @@ void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { } } } - ed64_ll_set_save_type(SAVE_TYPE_NONE); } @@ -379,7 +378,6 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { } -// uint8_t ed64_ll_set_eeprom(uint8_t *buffer, eeprom_type_t eep_type, bool verify) { uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; @@ -395,23 +393,8 @@ uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { for (uint32_t i = 0; i < size; i += 8) { eeprom_write(i / 8, &buffer[i]); } - - // if (verify) { // FIXME: This is a smoke test and should be seperated! - // uint8_t tmp_buffer[2048]; - // uint32_t j; - // for (j = 0; j < size; j += 8) { - // eeprom_read(j / 8, &tmp_buffer[j]); - // } - // for (j = 0; j < size; j++) { - // if (buffer[j] != tmp_buffer[j]) { - // return 1; //ERR_EEP_CHECK; - // } - // } - // } } - ed64_ll_set_save_type(SAVE_TYPE_NONE); - return 0; } From bb6b6e28b94bff8c5fe42441b6dce1a331586861 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:50:17 +0000 Subject: [PATCH 14/42] Update submodules --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 4b38fd561..72a313d98 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 +Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d diff --git a/src/libs/mini.c b/src/libs/mini.c index 6229658b9..f713e3c98 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e +Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 diff --git a/src/libs/miniz b/src/libs/miniz index 18795fa61..9ae305f6e 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 +Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b From ea8d8c4a8c8d19783a67a8ce988332cbc8b3927f Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:51:16 +0000 Subject: [PATCH 15/42] Revert "Update submodules" This reverts commit bb6b6e28b94bff8c5fe42441b6dce1a331586861. --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 72a313d98..4b38fd561 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d +Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 diff --git a/src/libs/mini.c b/src/libs/mini.c index f713e3c98..6229658b9 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 +Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e diff --git a/src/libs/miniz b/src/libs/miniz index 9ae305f6e..18795fa61 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b +Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 From f89d7a58d0658263da131b427a40bcc2e05b63b7 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:51:39 +0000 Subject: [PATCH 16/42] Revert, main was correct! --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 4b38fd561..72a313d98 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 +Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d diff --git a/src/libs/mini.c b/src/libs/mini.c index 6229658b9..f713e3c98 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e +Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 diff --git a/src/libs/miniz b/src/libs/miniz index 18795fa61..9ae305f6e 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 +Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b From 5c15273697d58c5f09a09fdaf67db7cee7f1ef53 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 18:02:07 +0000 Subject: [PATCH 17/42] Revert "Revert, main was correct!" This reverts commit f89d7a58d0658263da131b427a40bcc2e05b63b7. --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 72a313d98..4b38fd561 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d +Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 diff --git a/src/libs/mini.c b/src/libs/mini.c index f713e3c98..6229658b9 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 +Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e diff --git a/src/libs/miniz b/src/libs/miniz index 9ae305f6e..18795fa61 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b +Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 From 98b5837d4cd107d9fe3cfd453a3bb5126c0ea9c3 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 24 Oct 2023 00:35:28 +0100 Subject: [PATCH 18/42] Improve savetype state --- src/flashcart/ed64/ed64.c | 45 ++++++++++++++------------------- src/flashcart/ed64/ed64_state.c | 6 ++--- src/flashcart/ed64/ed64_state.h | 2 +- src/menu/settings.c | 2 +- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index b32543e10..c4cf7745e 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -33,11 +33,7 @@ static flashcart_err_t ed64_init (void) { if (current_state.is_expecting_save_writeback == true) { - // make sure next boot doesnt trigger the check changing its state. - current_state.is_expecting_save_writeback = false; - ed64_state_save(¤t_state); - - // Now save the content back to the SD card! + // save the content back to the SD card! FIL fil; UINT bw; uint8_t cartsave_data[KiB(128)]; @@ -53,11 +49,8 @@ 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 (current_state.is_fram_save_type == true) { // flashram is bugged atm + if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { // flashram is bugged atm ed64_ll_get_fram(cartsave_data, save_size); - // deletes flag - current_state.is_fram_save_type = false; - ed64_state_save(¤t_state); } else if (save_size > KiB(2)) { // sram ed64_ll_get_sram(cartsave_data, save_size); @@ -74,12 +67,12 @@ static flashcart_err_t ed64_init (void) { return FLASHCART_ERR_LOAD; } } - else { - current_state.is_expecting_save_writeback = false; - current_state.is_fram_save_type = false; - current_state.last_save_path = ""; - ed64_state_save(¤t_state); - } + + // make sure next boot doesnt trigger the check changing its state. + current_state.is_expecting_save_writeback = false; + current_state.is_save_type = SAVE_TYPE_NONE; + current_state.last_save_path = ""; + ed64_state_save(¤t_state); } return FLASHCART_OK; } @@ -216,10 +209,10 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - size_t save_size = file_get_size(save_path); - uint8_t cartsave_data[save_size]; + size_t save_file_size = file_get_size(strip_sd_prefix(save_path)); + uint8_t cartsave_data[save_file_size]; - if (f_read(&fil, cartsave_data, save_size, &br) != FR_OK) { + if (f_read(&fil, cartsave_data, save_file_size, &br) != FR_OK) { f_close(&fil); return FLASHCART_ERR_LOAD; } @@ -228,30 +221,27 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - current_state.is_fram_save_type = false; + current_state.is_save_type = SAVE_TYPE_NONE; ed64_save_type_t type = ed64_ll_get_save_type(); switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, save_size); + ed64_ll_set_eeprom(cartsave_data, save_file_size); break; case SAVE_TYPE_SRAM: + ed64_ll_set_sram(cartsave_data, save_file_size); case SAVE_TYPE_SRAM_128K: ed64_ll_set_sram(cartsave_data, save_size); break; case SAVE_TYPE_FLASHRAM: - 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 - current_state.is_fram_save_type = true; - ed64_state_save(¤t_state); + ed64_ll_set_fram(cartsave_data, KiB(128)); break; default: break; } - + //current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() current_state.last_save_path = save_path; current_state.is_expecting_save_writeback = true; ed64_state_save(¤t_state); @@ -289,6 +279,9 @@ static flashcart_err_t ed64_set_save_type (flashcart_save_type_t save_type) { ed64_ll_set_save_type(type); + current_state.is_save_type = type; + ed64_state_save(¤t_state); + return FLASHCART_OK; } diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c index 3604e6573..6295c0af2 100644 --- a/src/flashcart/ed64/ed64_state.c +++ b/src/flashcart/ed64/ed64_state.c @@ -10,7 +10,7 @@ static ed64_pseudo_writeback_t init = { .is_expecting_save_writeback = false, - .is_fram_save_type = false, + .is_save_type = 0, .last_save_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_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); + state->is_save_type = mini_get_int(ini, "ed64", "is_save_type", init.is_save_type); state->last_save_path = strdup(mini_get_string(ini, "ed64", "last_save_path", init.last_save_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_expecting_save_writeback", state->is_expecting_save_writeback); - mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type); + mini_set_int(ini, "ed64", "is_fram_save_type", state->is_save_type); mini_set_string(ini, "ed64", "last_save_path", state->last_save_path); mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS); diff --git a/src/flashcart/ed64/ed64_state.h b/src/flashcart/ed64/ed64_state.h index 3f53a1480..83f3dd262 100644 --- a/src/flashcart/ed64/ed64_state.h +++ b/src/flashcart/ed64/ed64_state.h @@ -12,7 +12,7 @@ typedef struct { /** @brief The reset button was used */ bool is_expecting_save_writeback; /** @brief The last save type was flash ram */ - bool is_fram_save_type; + int is_save_type; /** @brief The path to the last loaded ROM */ char *last_save_path; } ed64_pseudo_writeback_t; diff --git a/src/menu/settings.c b/src/menu/settings.c index 882293c64..d5f865eaa 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -32,7 +32,7 @@ void settings_load (settings_t *settings) { settings->hidden_files_enabled = mini_get_bool(ini, "menu", "show_hidden_files", init.hidden_files_enabled); settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory)); settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder); - + /* Beta feature flags, they might not be in the file */ settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled); From 6d383ab04558c2cd6c170583cbee99a273c4878e Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 24 Oct 2023 00:52:19 +0100 Subject: [PATCH 19/42] Improve writeback --- src/flashcart/ed64/ed64.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index c4cf7745e..fb70fbcfd 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -39,7 +39,7 @@ static flashcart_err_t ed64_init (void) { uint8_t cartsave_data[KiB(128)]; // find the path to last save - if (file_exists(strip_sd_prefix(current_state.last_save_path))) { + if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { int save_size = file_get_size(current_state.last_save_path); @@ -49,13 +49,13 @@ 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 (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { // flashram is bugged atm + if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { ed64_ll_get_fram(cartsave_data, save_size); } else if (save_size > KiB(2)) { // sram ed64_ll_get_sram(cartsave_data, save_size); } - else { // eeprom + else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { ed64_ll_get_eeprom(cartsave_data, save_size); } From 6836226b44473b28ef21bf90c5d0a24e0d437df0 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 14:22:29 +0100 Subject: [PATCH 20/42] Fix rom size Improve file load --- src/flashcart/ed64/ed64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index fb70fbcfd..ebaa1603d 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -52,7 +52,7 @@ static flashcart_err_t ed64_init (void) { if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { ed64_ll_get_fram(cartsave_data, save_size); } - else if (save_size > KiB(2)) { // sram + else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K || current_state.is_save_type == SAVE_TYPE_SRAM) { ed64_ll_get_sram(cartsave_data, save_size); } else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { From 5e7163dcfa60953a9c477ff01cbd985794cce26c Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 14:44:55 +0100 Subject: [PATCH 21/42] Use switch rather than if --- src/flashcart/ed64/ed64.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index ebaa1603d..adf51aa26 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,7 +14,9 @@ #include "ed64.h" #include "ed64_state.h" - +/** + * The ED64's current state + */ static ed64_pseudo_writeback_t current_state; extern int ed_exit (void); @@ -47,16 +49,22 @@ static flashcart_err_t ed64_init (void) { return FLASHCART_ERR_LOAD; } - // everdrive doesn't care about the save type other than flash sram and eeprom - // so minus flashram we can just check the size - if (current_state.is_save_type == SAVE_TYPE_FLASHRAM) { - ed64_ll_get_fram(cartsave_data, save_size); - } - else if (current_state.is_save_type == SAVE_TYPE_SRAM_128K || current_state.is_save_type == SAVE_TYPE_SRAM) { - ed64_ll_get_sram(cartsave_data, save_size); - } - else if (current_state.is_save_type == SAVE_TYPE_EEPROM_16K || current_state.is_save_type == SAVE_TYPE_EEPROM_4K) { - ed64_ll_get_eeprom(cartsave_data, save_size); + switch (current_state.is_save_type) { + case SAVE_TYPE_EEPROM_4K: + case SAVE_TYPE_EEPROM_16K: + ed64_ll_get_eeprom(cartsave_data, save_size); + break; + case SAVE_TYPE_SRAM: + case SAVE_TYPE_SRAM_128K: + ed64_ll_get_sram(cartsave_data, save_size); + break; + case SAVE_TYPE_FLASHRAM: + ed64_ll_get_fram(cartsave_data, save_size); + break; + case SAVE_TYPE_DD64_CART_PORT: + break; + default: + break; } if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { From 2c4c7e14eb8c9640b91aa2336571709c7c16d41b Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 16:01:07 +0100 Subject: [PATCH 22/42] Improve some comments --- src/flashcart/ed64/ed64.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index adf51aa26..cfe4f3c3b 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -33,6 +33,8 @@ static flashcart_err_t ed64_init (void) { ed64_state_load(¤t_state); + // FIXME: should be checking whether the console was a hot restart here! + // Cold restarts are only available with battery backup. if (current_state.is_expecting_save_writeback == true) { // save the content back to the SD card! @@ -117,7 +119,7 @@ static flashcart_err_t ed64_load_rom (char *rom_path, flashcart_progress_callbac // FIXME: if the cart is not V3 or X5 or X7, we need probably need to - 128KiB for save compatibility. // Or somehow warn that certain ROM's will have corruption due to the address space being used for saves. - // Conker's Bad Fur Day doesn't have this issue because eeprom data is at a fixed address in pif ram. + // EEPROM saves should be unaffected. if (rom_size > MiB(64)) { f_close(&fil); return FLASHCART_ERR_LOAD; @@ -180,6 +182,7 @@ static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uin // FIXME: if the cart is not V3 or X5 or X7, we need probably need to - 128KiB for save compatibility. // Or somehow warn that certain ROM's will have corruption due to the address space being used for saves. + // EEPROM saves should be unaffected. if (file_size > (MiB(64) - rom_offset)) { f_close(&fil); From e689bab6d809b856a80ea07d43cac7d073a93192 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 18:04:53 +0100 Subject: [PATCH 23/42] Add device variant (requires full implementation) --- src/flashcart/ed64/ed64.c | 11 ++++++----- src/flashcart/ed64/ed64_ll.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index cfe4f3c3b..3d9108447 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,6 +14,9 @@ #include "ed64.h" #include "ed64_state.h" + +// static ed64_device_variant_t device_variant = DEVICE_VARIANT_UNKNOWN; + /** * The ED64's current state */ @@ -210,7 +213,7 @@ static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uin return FLASHCART_OK; } -static flashcart_err_t ed64_load_save (char *save_path) { +static flashcart_err_t ed64_load_save (char *save_path) { // from file FIL fil; UINT br; @@ -232,9 +235,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { return FLASHCART_ERR_LOAD; } - current_state.is_save_type = SAVE_TYPE_NONE; - - ed64_save_type_t type = ed64_ll_get_save_type(); + ed64_save_type_t type = ed64_ll_get_save_type(); // current_state.is_save_type; switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: @@ -252,7 +253,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { break; } - //current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() + current_state.is_save_type = type; // SHOULD HAVE BEEN SET FROM ed64_set_save_type() current_state.last_save_path = save_path; current_state.is_expecting_save_writeback = true; ed64_state_save(¤t_state); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 2ea4ab4b4..9fe0a76d9 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -53,6 +53,18 @@ */ +typedef enum { + DEVICE_VARIANT_UNKNOWN = 0x0000, + // // DEVICE_VARIANT_X7_0 = 0x4000, + // // DEVICE_VARIANT_X5_0 = 0x4000, + DEVICE_VARIANT_V3_0 = 0x3000, + DEVICE_VARIANT_V2_5 = 0x2500, + DEVICE_VARIANT_V2_0 = 0x2000, + // DEVICE_VARIANT_V1_0 = 0x1000, + // // DEVICE_VARIANT_P1_0 = 0x1000, +} ed64_device_variant_t; + + typedef enum { SAVE_TYPE_NONE = 0, SAVE_TYPE_SRAM = 1, From f92df1967af4024996b216c4e2352420314be37c Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 19:07:58 +0100 Subject: [PATCH 24/42] Move save on init to a seperate function. --- src/flashcart/ed64/ed64.c | 56 +++++++++++++++++++++++++++++++++++- src/flashcart/ed64/ed64_ll.c | 2 ++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 3d9108447..df3980e26 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -14,7 +14,9 @@ #include "ed64.h" #include "ed64_state.h" - +/** + * The ED64's variant, read from the CPLD + */ // static ed64_device_variant_t device_variant = DEVICE_VARIANT_UNKNOWN; /** @@ -23,6 +25,7 @@ static ed64_pseudo_writeback_t current_state; extern int ed_exit (void); +static flashcart_err_t ed64_pesudo_set_save_writeback (void); static flashcart_err_t ed64_init (void) { @@ -297,6 +300,57 @@ static flashcart_err_t ed64_set_save_type (flashcart_save_type_t save_type) { return FLASHCART_OK; } +static flashcart_err_t ed64_pesudo_set_save_writeback (void) { + // save the content back to the SD card! + FIL fil; + UINT bw; + uint8_t cartsave_data[KiB(128)]; + + // find the path to last save + if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { + + int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); + + 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; + } + + switch (current_state.is_save_type) { + case SAVE_TYPE_EEPROM_4K: + case SAVE_TYPE_EEPROM_16K: + ed64_ll_get_eeprom(cartsave_data, save_size); + break; + case SAVE_TYPE_SRAM: + case SAVE_TYPE_SRAM_128K: + ed64_ll_get_sram(cartsave_data, save_size); + break; + case SAVE_TYPE_FLASHRAM: + ed64_ll_get_fram(cartsave_data, save_size); + break; + case SAVE_TYPE_DD64_CART_PORT: + break; + default: + break; + } + + if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + if (f_close(&fil) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + } + + // make sure next boot doesn't trigger the check changing its state. + current_state.is_expecting_save_writeback = false; + current_state.is_save_type = SAVE_TYPE_NONE; + current_state.last_save_path = ""; + ed64_state_save(¤t_state); + + return FLASHCART_OK; +} + static flashcart_t flashcart_ed64 = { .init = ed64_init, .deinit = ed64_deinit, diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index faea332db..225661b19 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -34,6 +34,8 @@ typedef enum { } ed64_registers_t; +// #define DEVICE_VARIANT_MASK (0xF000) + void pi_initialize (void); void pi_dma_wait (void); void pi_initialize_sram (void); From 13c8b02f374435ecb2eb444bdcdce207147a4b63 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 19:36:16 +0100 Subject: [PATCH 25/42] Start adding device variants --- src/flashcart/ed64/ed64_ll.c | 2 +- src/flashcart/ed64/ed64_ll.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 225661b19..5a9b7f5b8 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -34,7 +34,7 @@ typedef enum { } ed64_registers_t; -// #define DEVICE_VARIANT_MASK (0xF000) +#define ED64_DEVICE_VARIANT_MASK (0xF000) void pi_initialize (void); void pi_dma_wait (void); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 9fe0a76d9..1279cd4b1 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -54,14 +54,14 @@ typedef enum { - DEVICE_VARIANT_UNKNOWN = 0x0000, - // // DEVICE_VARIANT_X7_0 = 0x4000, - // // DEVICE_VARIANT_X5_0 = 0x4000, + DEVICE_VARIANT_UNKNOWN = 0xFFFF, + DEVICE_VARIANT_X7_0 = 0x7000, + DEVICE_VARIANT_X5_0 = 0x5000, DEVICE_VARIANT_V3_0 = 0x3000, - DEVICE_VARIANT_V2_5 = 0x2500, - DEVICE_VARIANT_V2_0 = 0x2000, - // DEVICE_VARIANT_V1_0 = 0x1000, - // // DEVICE_VARIANT_P1_0 = 0x1000, + DEVICE_VARIANT_V2_5 = 0x2000, + DEVICE_VARIANT_V2_0 = 0x0000, + DEVICE_VARIANT_V1_0 = 0x0000, + DEVICE_VARIANT_P1_0 = 0x0000 } ed64_device_variant_t; From 54ee1d65c1e6f36c0de71d0270af556bcab4c841 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Oct 2023 22:48:37 +0100 Subject: [PATCH 26/42] Update ed64_ll.c Improve save registers --- src/flashcart/ed64/ed64_ll.c | 94 +++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 5a9b7f5b8..3e5cb3c3c 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -17,23 +17,26 @@ void sleep (unsigned long ms) { /* ED64 configuration registers base address */ #define ED64_CONFIG_REGS_BASE (0xA8040000) +/* ED64 configuration registers */ typedef enum { - // REG_CFG = 0, - // REG_STATUS = 1, - // REG_DMA_LENGTH = 2, - // REG_DMA_RAM_ADDR = 3, - // REG_MSG = 4, - // REG_DMA_CFG = 5, - // REG_SPI = 6, - // REG_SPI_CFG = 7, - // REG_KEY = 8, - REG_SAV_CFG = 9, - // REG_SEC = 10, /* Sectors?? */ - // REG_FPGA_VERSION = 11, /* Altera (Intel) MAX */ - // REG_GPIO = 12, - -} ed64_registers_t; - + // REG_CFG = 0x00, + // REG_STATUS = 0x01, + // REG_DMA_LENGTH = 0x02, + // REG_DMA_RAM_ADDR = 0x03, + // REG_MSG = 0x04, + // REG_DMA_CFG = 0x05, + // REG_SPI = 0x06, + // REG_SPI_CFG = 0x07, + // REG_KEY = 0x08, + REG_SAV_CFG = 0x09, + // REG_SEC = 0x0A, /* Sectors?? */ + // REG_FPGA_VERSION = 0x0B, //11, /* Altera (Intel) MAX */ + // REG_GPIO = 0x0C, //12, + +} ed64_ci_registers_id_t; + + +/* ED64 Device Variant Mask */ #define ED64_DEVICE_VARIANT_MASK (0xF000) void pi_initialize (void); @@ -44,13 +47,14 @@ void pi_dma_to_sram (void* src, unsigned long offset, unsigned long size); void ed64_ll_set_sdcard_timing (void); -#define SAV_EEP_ON 1 -#define SAV_SRM_ON 2 -#define SAV_EEP_SIZE 4 -#define SAV_SRM_SIZE 8 - -#define SAV_RAM_BANK 128 -#define SAV_RAM_BANK_APPLY 32768 +typedef enum { + SAV_EEP_ON_OFF = 0x01, + SAV_SRM_ON_OFF = 0x02, + SAV_EEP_SMALL_BIG = 0x04, + SAV_SRM_SMALL_BIG = 0x08, + SAV_RAM_BANK = 128, + SAV_RAM_BANK_APPLY = 32768 +} ed64_v_save_register_id_t; void ed64_ll_reg_write (uint32_t reg, uint32_t data); @@ -75,46 +79,46 @@ ed64_save_type_t ed64_ll_get_save_type (void) { void ed64_ll_set_save_type (ed64_save_type_t type) { uint16_t save_cfg; - uint8_t eeprom_on, sram_on, eeprom_size, sram_size, ram_bank; + uint8_t is_eeprom, is_sram, is_eeprom_16k, is_sram_128k, using_ram_bank; ed64_ll_save_type = type; - eeprom_on = 0; - sram_on = 0; - eeprom_size = 0; - sram_size = 0; - ram_bank = ed64_ll_sram_bank; + is_eeprom = false; + is_sram = false; + is_eeprom_16k = false; + is_sram_128k = false; + using_ram_bank = ed64_ll_sram_bank; switch (type) { case SAVE_TYPE_EEPROM_16K: - eeprom_on = 1; - eeprom_size = 1; + is_eeprom = true; + is_eeprom_16k = true; break; case SAVE_TYPE_EEPROM_4K: - eeprom_on = 1; + is_eeprom = true; break; case SAVE_TYPE_SRAM: - sram_on = 1; + is_sram = true; break; case SAVE_TYPE_SRAM_128K: - sram_on = 1; - sram_size = 1; + is_sram = true; + is_sram_128k = true; break; case SAVE_TYPE_FLASHRAM: - sram_on = 0; - sram_size = 1; + is_sram = false; + is_sram_128k = true; break; default: - sram_on = 0; - sram_size = 0; - ram_bank = 1; + is_sram = false; + is_sram_128k = false; + using_ram_bank = 1; break; } - if (eeprom_on)save_cfg |= SAV_EEP_ON; - if (sram_on)save_cfg |= SAV_SRM_ON; - if (eeprom_size)save_cfg |= SAV_EEP_SIZE; - if (sram_size)save_cfg |= SAV_SRM_SIZE; - if (ram_bank)save_cfg |= SAV_RAM_BANK; + if (is_eeprom)save_cfg |= SAV_EEP_ON_OFF; + if (is_sram)save_cfg |= SAV_SRM_ON_OFF; + if (is_eeprom_16k)save_cfg |= SAV_EEP_SMALL_BIG; + if (is_sram_128k)save_cfg |= SAV_SRM_SMALL_BIG; + if (using_ram_bank)save_cfg |= SAV_RAM_BANK; save_cfg |= SAV_RAM_BANK_APPLY; ed64_ll_reg_write(REG_SAV_CFG, save_cfg); From d66301ef5dfa94db93d82d0601b92681737d20ec Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sun, 29 Oct 2023 00:04:15 +0100 Subject: [PATCH 27/42] Work on EEPROM get and set --- src/flashcart/ed64/ed64.c | 4 +- src/flashcart/ed64/ed64_ll.c | 255 +++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 2 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index df3980e26..13ba4abb1 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -242,7 +242,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, save_file_size); + ed64_ll_set_eeprom(cartsave_data, type, false); break; case SAVE_TYPE_SRAM: ed64_ll_set_sram(cartsave_data, save_file_size); @@ -318,7 +318,7 @@ static flashcart_err_t ed64_pesudo_set_save_writeback (void) { switch (current_state.is_save_type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_get_eeprom(cartsave_data, save_size); + ed64_ll_get_eeprom(cartsave_data, current_state.is_save_type); break; case SAVE_TYPE_SRAM: case SAVE_TYPE_SRAM_128K: diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 3e5cb3c3c..398c4cdac 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -204,6 +204,261 @@ void pi_dma_to_sram (void *src, unsigned long offset, unsigned long size) { } +void pi_dma_from_cart (void* dest, void* src, unsigned long size) { + + dma_wait(); + + io_write(PI_STATUS_REG, 0x03); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); + io_write(PI_CART_ADDR_REG, K0_TO_PHYS(src)); + io_write(PI_WR_LEN_REG, (size - 1)); + +} + + +void pi_dma_to_cart (void* dest, void* src, unsigned long size) { + + dma_wait(); + + io_write(PI_STATUS_REG, 0x02); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); + io_write(PI_CART_ADDR_REG, K0_TO_PHYS(dest)); + io_write(PI_RD_LEN_REG, (size - 1)); + +} + + +// Wrapper to support unaligned access to memory +void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size) { + + if (!dest || !src || !size) return; + + unsigned long unalignedSrc = ((unsigned long)src) % 2; + unsigned long unalignedDest = ((unsigned long)dest) % 8; + + //FIXME: Do i really need to check if size is 16bit aligned? + if (!unalignedDest && !unalignedSrc && !(size % 2)) { + pi_dma_from_cart(dest, src, size); + dma_wait(); + + return; + } + + void* newSrc = (void*)(((unsigned long)src) - unalignedSrc); + unsigned long newSize = (size + unalignedSrc) + ((size + unalignedSrc) % 2); + + unsigned char *buffer = memalign(8, newSize); + pi_dma_from_cart(buffer, newSrc, newSize); + dma_wait(); + + memcpy(dest, (buffer + unalignedSrc), size); + + free(buffer); + +} + + +int ed64_ll_get_sram_128 (uint8_t *buffer, int size) { + + dma_wait(); + + io_write(PI_BSD_DOM2_LAT_REG, 0x05); + io_write(PI_BSD_DOM2_PWD_REG, 0x0C); + io_write(PI_BSD_DOM2_PGS_REG, 0x0D); + io_write(PI_BSD_DOM2_RLS_REG, 0x02); + + dma_wait(); + + pi_initialize(); + + dma_wait(); + + // Offset Large RAM size 128KiB with a 16KiB nudge to allocate enough space + // We do this because 128Kib is not recognised and a 32KiB allocates too little + pi_dma_from_sram(buffer, -(size - KiB(16)), size); + + dma_wait(); + + io_write(PI_BSD_DOM2_LAT_REG, 0x40); + io_write(PI_BSD_DOM2_PWD_REG, 0x12); + io_write(PI_BSD_DOM2_PGS_REG, 0x07); + io_write(PI_BSD_DOM2_RLS_REG, 0x03); + + return 1; + +} + + +int ed64_ll_get_sram (uint8_t *buffer, int size) { + + dma_wait(); + + io_write(PI_BSD_DOM2_LAT_REG, 0x05); + io_write(PI_BSD_DOM2_PWD_REG, 0x0C); + io_write(PI_BSD_DOM2_PGS_REG, 0x0D); + io_write(PI_BSD_DOM2_RLS_REG, 0x02); + + dma_wait(); + + pi_initialize(); + + dma_wait(); + + pi_dma_from_sram(buffer, 0, size) ; + + dma_wait(); + + io_write(PI_BSD_DOM2_LAT_REG, 0x40); + io_write(PI_BSD_DOM2_PWD_REG, 0x12); + io_write(PI_BSD_DOM2_PGS_REG, 0x07); + io_write(PI_BSD_DOM2_RLS_REG, 0x03); + + return 1; + +} + +void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { + + + uint32_t i; + uint32_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (slen == 0) { + return; + } + + ed64_ll_set_save_type(eep_type); + eeprom_present(); + + for (i = 0; i < slen * 512; i += 8) { + eeprom_read(i / 8, &buffer[i]); + } + ed64_ll_set_save_type(SAVE_TYPE_NONE); + +} + + +int ed64_ll_get_fram (uint8_t *buffer, int size) { + + ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 + dma_wait(); + + ed64_ll_get_sram_128(buffer, size); + data_cache_hit_writeback_invalidate(buffer, size); + + dma_wait(); + ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); + + return 1; + +} + +/* +sram upload +*/ + + +int ed64_ll_set_sram_128 (uint8_t *buffer, int size) { + + //half working + dma_wait(); + //Timing + pi_initialize_sram(); + + //Readmode + pi_initialize(); + + data_cache_hit_writeback_invalidate(buffer,size); + dma_wait(); + + // Offset Large RAM size 128KiB with a 16KiB nudge to allocate enough space + // We do this because 128Kib is not recognised and a 32KiB allocates too little + pi_dma_to_sram(buffer, -(size - KiB(16)), size); + data_cache_hit_writeback_invalidate(buffer,size); + + //Wait + dma_wait(); + //Restore evd Timing + ed64_ll_set_sdcard_timing(); + + return 1; + +} + + +int ed64_ll_set_sram (uint8_t *buffer, int size) { + + //half working + dma_wait(); + //Timing + pi_initialize_sram(); + + //Readmode + pi_initialize(); + + data_cache_hit_writeback_invalidate(buffer,size); + dma_wait(); + + pi_dma_to_sram(buffer, 0, size); + data_cache_hit_writeback_invalidate(buffer,size); + + //Wait + dma_wait(); + //Restore evd Timing + ed64_ll_set_sdcard_timing(); + + return 1; + +} + + +uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { + + uint8_t buff[2048]; + uint32_t i; + uint8_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (slen == 0) { + return 0; + } + + ed64_ll_set_save_type(eep_type); + eeprom_present(); + + for (i = 0; i < slen * 512; i += 8) { + eeprom_write(i / 8, &src[i]); + } + + if (verify) { + for (i = 0; i < slen * 512; i += 8) { + eeprom_read(i / 8, &buff[i]); + } + for (i = 0; i < slen * 512; i++) { + if (src[i] != buff[i]) { + return 1; //ERR_EEP_CHECK; + } + } + } + + ed64_ll_set_save_type(SAVE_TYPE_NONE); + + return 0; +} + +int ed64_ll_set_fram (uint8_t *buffer, int size) { + + ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); + dma_wait(); + + ed64_ll_set_sram_128(buffer, size); + data_cache_hit_writeback_invalidate(buffer, size); + + dma_wait(); + ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); + + return 1; + +} + + void ed64_ll_set_sdcard_timing (void) { io_write(PI_BSD_DOM1_LAT_REG, 0x40); From 899581812f42fd9db4381edd77240fe440f00e6d Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 19:19:51 +0000 Subject: [PATCH 28/42] Fix eeprom get-set --- src/flashcart/ed64/ed64.c | 1 + src/flashcart/ed64/ed64_ll.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 13ba4abb1..b0e0927a3 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -41,6 +41,7 @@ static flashcart_err_t ed64_init (void) { // FIXME: should be checking whether the console was a hot restart here! // Cold restarts are only available with battery backup. + // if (sys_reset_type() != RESET_COLD || RTC == true) if (current_state.is_expecting_save_writeback == true) { // save the content back to the SD card! diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 398c4cdac..51e85ad58 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -321,15 +321,15 @@ void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { uint32_t i; - uint32_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (slen == 0) { + uint32_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + if (size == 0) { return; } ed64_ll_set_save_type(eep_type); eeprom_present(); - for (i = 0; i < slen * 512; i += 8) { + for (i = 0; i < size; i += 8) { eeprom_read(i / 8, &buffer[i]); } ed64_ll_set_save_type(SAVE_TYPE_NONE); @@ -413,26 +413,27 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { - uint8_t buff[2048]; + uint8_t buffer[2048]; uint32_t i; - uint8_t slen = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (slen == 0) { + uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; + + if (size == 0) { return 0; } ed64_ll_set_save_type(eep_type); eeprom_present(); - for (i = 0; i < slen * 512; i += 8) { + for (i = 0; i < size; i += 8) { eeprom_write(i / 8, &src[i]); } if (verify) { - for (i = 0; i < slen * 512; i += 8) { - eeprom_read(i / 8, &buff[i]); + for (i = 0; i < size; i += 8) { + eeprom_read(i / 8, &buffer[i]); } - for (i = 0; i < slen * 512; i++) { - if (src[i] != buff[i]) { + for (i = 0; i < size; i++) { + if (src[i] != buffer[i]) { return 1; //ERR_EEP_CHECK; } } From 4946cc4e7b105472ea29e6ba02c3413f6b456c59 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 21:33:54 +0000 Subject: [PATCH 29/42] Further EEPROM improvements Possibly corrects a few last commits. --- src/flashcart/ed64/ed64.c | 2 +- src/flashcart/ed64/ed64_ll.c | 51 ++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index b0e0927a3..1913ae977 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -243,7 +243,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file switch (type) { case SAVE_TYPE_EEPROM_4K: case SAVE_TYPE_EEPROM_16K: - ed64_ll_set_eeprom(cartsave_data, type, false); + ed64_ll_set_eeprom(cartsave_data, type); break; case SAVE_TYPE_SRAM: ed64_ll_set_sram(cartsave_data, save_file_size); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 51e85ad58..b8c19ad11 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -319,18 +319,16 @@ int ed64_ll_get_sram (uint8_t *buffer, int size) { void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { - - uint32_t i; uint32_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (size == 0) { - return; - } - ed64_ll_set_save_type(eep_type); - eeprom_present(); + if (size != 0) { + ed64_ll_set_save_type(eep_type); + if (eeprom_present()) { // FIXME: does not correctly check type. - for (i = 0; i < size; i += 8) { - eeprom_read(i / 8, &buffer[i]); + for (uint32_t i = 0; i < size; i += 8) { + eeprom_read(i / 8, &buffer[i]); + } + } } ed64_ll_set_save_type(SAVE_TYPE_NONE); @@ -411,32 +409,35 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { } -uint8_t ed64_ll_set_eeprom(uint8_t *src, uint8_t eep_type, bool verify) { +// uint8_t ed64_ll_set_eeprom(uint8_t *buffer, eeprom_type_t eep_type, bool verify) { +uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { - uint8_t buffer[2048]; - uint32_t i; uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; - if (size == 0) { + if (size == 0) { // SAVE_TYPE_NONE return 0; } ed64_ll_set_save_type(eep_type); - eeprom_present(); - for (i = 0; i < size; i += 8) { - eeprom_write(i / 8, &src[i]); - } + if (eeprom_present()) { // FIXME: does not correctly check type. - if (verify) { - for (i = 0; i < size; i += 8) { - eeprom_read(i / 8, &buffer[i]); - } - for (i = 0; i < size; i++) { - if (src[i] != buffer[i]) { - return 1; //ERR_EEP_CHECK; - } + for (uint32_t i = 0; i < size; i += 8) { + eeprom_write(i / 8, &buffer[i]); } + + // if (verify) { // FIXME: This is a smoke test and should be seperated! + // uint8_t tmp_buffer[2048]; + // uint32_t j; + // for (j = 0; j < size; j += 8) { + // eeprom_read(j / 8, &tmp_buffer[j]); + // } + // for (j = 0; j < size; j++) { + // if (buffer[j] != tmp_buffer[j]) { + // return 1; //ERR_EEP_CHECK; + // } + // } + // } } ed64_ll_set_save_type(SAVE_TYPE_NONE); From 8988f597ae1bd153bfbe39e1566e193255231110 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Mon, 30 Oct 2023 21:46:10 +0000 Subject: [PATCH 30/42] Dont reset save types --- src/flashcart/ed64/ed64_ll.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index b8c19ad11..c249e664b 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -330,7 +330,6 @@ void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { } } } - ed64_ll_set_save_type(SAVE_TYPE_NONE); } @@ -409,7 +408,6 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { } -// uint8_t ed64_ll_set_eeprom(uint8_t *buffer, eeprom_type_t eep_type, bool verify) { uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { uint8_t size = eep_type == SAVE_TYPE_EEPROM_16K ? 4 : SAVE_TYPE_EEPROM_4K ? 1 : 0; @@ -425,23 +423,8 @@ uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { for (uint32_t i = 0; i < size; i += 8) { eeprom_write(i / 8, &buffer[i]); } - - // if (verify) { // FIXME: This is a smoke test and should be seperated! - // uint8_t tmp_buffer[2048]; - // uint32_t j; - // for (j = 0; j < size; j += 8) { - // eeprom_read(j / 8, &tmp_buffer[j]); - // } - // for (j = 0; j < size; j++) { - // if (buffer[j] != tmp_buffer[j]) { - // return 1; //ERR_EEP_CHECK; - // } - // } - // } } - ed64_ll_set_save_type(SAVE_TYPE_NONE); - return 0; } From 89eb0eaee21f53d50e8964465727ff73ac02d114 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:50:17 +0000 Subject: [PATCH 31/42] Update submodules --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 4b38fd561..72a313d98 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 +Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d diff --git a/src/libs/mini.c b/src/libs/mini.c index 6229658b9..f713e3c98 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e +Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 diff --git a/src/libs/miniz b/src/libs/miniz index 18795fa61..9ae305f6e 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 +Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b From 6d28a80cfb513a8f7e06771a2d0cbca6fba291d1 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:51:16 +0000 Subject: [PATCH 32/42] Revert "Update submodules" This reverts commit bb6b6e28b94bff8c5fe42441b6dce1a331586861. --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 72a313d98..4b38fd561 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d +Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 diff --git a/src/libs/mini.c b/src/libs/mini.c index f713e3c98..6229658b9 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 +Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e diff --git a/src/libs/miniz b/src/libs/miniz index 9ae305f6e..18795fa61 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b +Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 From 2ff945852905089643c9ff3cf853f8481653f717 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 17:51:39 +0000 Subject: [PATCH 33/42] Revert, main was correct! --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 4b38fd561..72a313d98 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 +Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d diff --git a/src/libs/mini.c b/src/libs/mini.c index 6229658b9..f713e3c98 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e +Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 diff --git a/src/libs/miniz b/src/libs/miniz index 18795fa61..9ae305f6e 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 +Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b From c6aa993945deb722a7ebc1118a4eda23551d86b1 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 10 Nov 2023 18:02:07 +0000 Subject: [PATCH 34/42] Revert "Revert, main was correct!" This reverts commit f89d7a58d0658263da131b427a40bcc2e05b63b7. --- libdragon | 2 +- src/libs/mini.c | 2 +- src/libs/miniz | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdragon b/libdragon index 72a313d98..4b38fd561 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 72a313d987ed8e0d78f921a16c58b367ffe9f56d +Subproject commit 4b38fd5618007e7ed9040107d0f7e52f2de81a22 diff --git a/src/libs/mini.c b/src/libs/mini.c index f713e3c98..6229658b9 160000 --- a/src/libs/mini.c +++ b/src/libs/mini.c @@ -1 +1 @@ -Subproject commit f713e3c98ee2340a90334da6084c34ec2109a7e6 +Subproject commit 6229658b9d275fb760bcee119104bdbd7873536e diff --git a/src/libs/miniz b/src/libs/miniz index 9ae305f6e..18795fa61 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 9ae305f6e109f8f1fbd2130458f1ee6197269b3b +Subproject commit 18795fa61e590521381ba9e1fa4a4ab362b095f6 From 70ebf8efe57e1fde90e9fd499c5b3fc766c2e751 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 14 Nov 2023 22:31:46 +0000 Subject: [PATCH 35/42] Part re-align from merge --- src/flashcart/ed64/ed64.c | 62 +-------- src/flashcart/ed64/ed64_ll.c | 258 +++-------------------------------- src/flashcart/ed64/ed64_ll.h | 13 +- 3 files changed, 29 insertions(+), 304 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 1913ae977..cd8f737ac 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -44,52 +44,7 @@ static flashcart_err_t ed64_init (void) { // if (sys_reset_type() != RESET_COLD || RTC == true) if (current_state.is_expecting_save_writeback == true) { - // save the content back to the SD card! - FIL fil; - UINT bw; - uint8_t cartsave_data[KiB(128)]; - - // find the path to last save - if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { - - int save_size = file_get_size(current_state.last_save_path); - - 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; - } - - switch (current_state.is_save_type) { - case SAVE_TYPE_EEPROM_4K: - case SAVE_TYPE_EEPROM_16K: - ed64_ll_get_eeprom(cartsave_data, save_size); - break; - case SAVE_TYPE_SRAM: - case SAVE_TYPE_SRAM_128K: - ed64_ll_get_sram(cartsave_data, save_size); - break; - case SAVE_TYPE_FLASHRAM: - ed64_ll_get_fram(cartsave_data, save_size); - break; - case SAVE_TYPE_DD64_CART_PORT: - break; - default: - break; - } - - if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - - if (f_close(&fil) != FR_OK) { - return FLASHCART_ERR_LOAD; - } - } - - // make sure next boot doesnt trigger the check changing its state. - current_state.is_expecting_save_writeback = false; - current_state.is_save_type = SAVE_TYPE_NONE; - current_state.last_save_path = ""; - ed64_state_save(¤t_state); + return ed64_pesudo_set_save_writeback(); } return FLASHCART_OK; } @@ -134,7 +89,7 @@ static flashcart_err_t ed64_load_rom (char *rom_path, flashcart_progress_callbac // FIXME: is this actually needed? /* - if (rom_size == MiB(64)) { + if (rom_size <= MiB(64)) { ed64_save_type_t type = ed64_ll_get_save_type(); switch (type) { case SAVE_TYPE_SRAM: @@ -235,10 +190,6 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file return FLASHCART_ERR_LOAD; } - if (br != save_size) { - return FLASHCART_ERR_LOAD; - } - ed64_save_type_t type = ed64_ll_get_save_type(); // current_state.is_save_type; switch (type) { case SAVE_TYPE_EEPROM_4K: @@ -246,12 +197,13 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file ed64_ll_set_eeprom(cartsave_data, type); break; case SAVE_TYPE_SRAM: - ed64_ll_set_sram(cartsave_data, save_file_size); case SAVE_TYPE_SRAM_128K: - ed64_ll_set_sram(cartsave_data, save_size); + ed64_ll_set_sram(cartsave_data, save_file_size); break; case SAVE_TYPE_FLASHRAM: - ed64_ll_set_fram(cartsave_data, KiB(128)); + ed64_ll_set_fram(cartsave_data, save_file_size); + break; + case SAVE_TYPE_DD64_CART_PORT: break; default: break; @@ -310,7 +262,7 @@ static flashcart_err_t ed64_pesudo_set_save_writeback (void) { // find the path to last save if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { - int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path)); + int save_size = file_get_size(current_state.last_save_path); 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; diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index c249e664b..cf17b006d 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -3,16 +3,9 @@ #include "utils/utils.h" #include "ed64_ll.h" -//FIXME find a better solution, perferably a libdragon one -void sleep (unsigned long ms); -void sleep (unsigned long ms) { - - unsigned long current_ms = get_ticks_ms(); - - while (get_ticks_ms() - current_ms < ms); - -} +/* ED64 save location base address */ +#define ED_SAVE_ADDR_BASE (0xA8000000) /* ED64 configuration registers base address */ #define ED64_CONFIG_REGS_BASE (0xA8040000) @@ -40,10 +33,13 @@ typedef enum { #define ED64_DEVICE_VARIANT_MASK (0xF000) void pi_initialize (void); -void pi_dma_wait (void); void pi_initialize_sram (void); +void pi_dma_from_cart (void* dest, void* src, unsigned long size); +void pi_dma_to_cart (void* dest, void* src, unsigned long size); void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size); void pi_dma_to_sram (void* src, unsigned long offset, unsigned long size); +void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size); + void ed64_ll_set_sdcard_timing (void); @@ -58,6 +54,10 @@ typedef enum { void ed64_ll_reg_write (uint32_t reg, uint32_t data); +uint8_t ed64_ll_sram_bank; +ed64_save_type_t ed64_ll_save_type; + + void ed64_ll_reg_write (uint32_t reg, uint32_t data) { *(volatile uint32_t *) (ED64_CONFIG_REGS_BASE); @@ -66,9 +66,6 @@ void ed64_ll_reg_write (uint32_t reg, uint32_t data) { } -uint8_t ed64_ll_sram_bank; -ed64_save_type_t ed64_ll_save_type; - ed64_save_type_t ed64_ll_get_save_type (void) { @@ -131,47 +128,14 @@ void ed64_ll_set_sram_bank (uint8_t bank) { } -// FIXME Id like to use libdragon's equivelant for this -void _data_cache_invalidate_all (void) { - asm( - "li $8,0x80000000;" - "li $9,0x80000000;" - "addu $9,$9,0x1FF0;" - "cacheloop:;" - "cache 1,0($8);" - "cache 1,16($8);" - "cache 1,32($8);" - "cache 1,48($8);" - "cache 1,64($8);" - "cache 1,80($8);" - "cache 1,96($8);" - "addu $8,$8,112;" - "bne $8,$9,cacheloop;" - "cache 1,0($8);" - : // no outputs - : // no inputs - : "$8", "$9" // trashed registers - ); -} - - -// register related functions - -// FIXME i dont actually think the alt64 names are do what they are saying they are doing -// a proper rename is in order? void pi_initialize (void) { - pi_dma_wait(); + dma_wait(); io_write(PI_STATUS_REG, 0x03); } -void pi_dma_wait (void) { - while (io_read(PI_STATUS_REG) & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)); - -} - // Inits PI for sram transfer void pi_initialize_sram (void) { @@ -185,21 +149,21 @@ void pi_initialize_sram (void) { void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size) { io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - io_write(PI_CART_ADDR_REG, (PI_SAVE_ADDR + offset)); + io_write(PI_CART_ADDR_REG, (ED_SAVE_ADDR_BASE + offset)); asm volatile ("" : : : "memory"); io_write(PI_WR_LEN_REG, (size - 1)); asm volatile ("" : : : "memory"); } + void pi_dma_to_sram (void *src, unsigned long offset, unsigned long size) { - pi_dma_wait(); + dma_wait(); io_write(PI_STATUS_REG, 2); io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - io_write(PI_CART_ADDR_REG, (PI_SAVE_ADDR + offset)); - _data_cache_invalidate_all(); + io_write(PI_CART_ADDR_REG, (ED_SAVE_ADDR_BASE + offset)); io_write(PI_RD_LEN_REG, (size - 1)); } @@ -258,38 +222,7 @@ void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size) { } -int ed64_ll_get_sram_128 (uint8_t *buffer, int size) { - - dma_wait(); - - io_write(PI_BSD_DOM2_LAT_REG, 0x05); - io_write(PI_BSD_DOM2_PWD_REG, 0x0C); - io_write(PI_BSD_DOM2_PGS_REG, 0x0D); - io_write(PI_BSD_DOM2_RLS_REG, 0x02); - - dma_wait(); - - pi_initialize(); - - dma_wait(); - - // Offset Large RAM size 128KiB with a 16KiB nudge to allocate enough space - // We do this because 128Kib is not recognised and a 32KiB allocates too little - pi_dma_from_sram(buffer, -(size - KiB(16)), size); - - dma_wait(); - - io_write(PI_BSD_DOM2_LAT_REG, 0x40); - io_write(PI_BSD_DOM2_PWD_REG, 0x12); - io_write(PI_BSD_DOM2_PGS_REG, 0x07); - io_write(PI_BSD_DOM2_RLS_REG, 0x03); - - return 1; - -} - - -int ed64_ll_get_sram (uint8_t *buffer, int size) { +void ed64_ll_get_sram (uint8_t *buffer, int size) { dma_wait(); @@ -313,8 +246,6 @@ int ed64_ll_get_sram (uint8_t *buffer, int size) { io_write(PI_BSD_DOM2_PGS_REG, 0x07); io_write(PI_BSD_DOM2_RLS_REG, 0x03); - return 1; - } void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { @@ -334,7 +265,7 @@ void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t eep_type) { } -int ed64_ll_get_fram (uint8_t *buffer, int size) { +void ed64_ll_get_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 dma_wait(); @@ -345,44 +276,10 @@ int ed64_ll_get_fram (uint8_t *buffer, int size) { dma_wait(); ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); - return 1; - } -/* -sram upload -*/ - - -int ed64_ll_set_sram_128 (uint8_t *buffer, int size) { - - //half working - dma_wait(); - //Timing - pi_initialize_sram(); - //Readmode - pi_initialize(); - - data_cache_hit_writeback_invalidate(buffer,size); - dma_wait(); - - // Offset Large RAM size 128KiB with a 16KiB nudge to allocate enough space - // We do this because 128Kib is not recognised and a 32KiB allocates too little - pi_dma_to_sram(buffer, -(size - KiB(16)), size); - data_cache_hit_writeback_invalidate(buffer,size); - - //Wait - dma_wait(); - //Restore evd Timing - ed64_ll_set_sdcard_timing(); - - return 1; - -} - - -int ed64_ll_set_sram (uint8_t *buffer, int size) { +void ed64_ll_set_sram (uint8_t *buffer, int size) { //half working dma_wait(); @@ -403,8 +300,6 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { //Restore evd Timing ed64_ll_set_sdcard_timing(); - return 1; - } @@ -428,7 +323,7 @@ uint8_t ed64_ll_set_eeprom(uint8_t *buffer, uint8_t eep_type) { return 0; } -int ed64_ll_set_fram (uint8_t *buffer, int size) { +void ed64_ll_set_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); dma_wait(); @@ -439,8 +334,6 @@ int ed64_ll_set_fram (uint8_t *buffer, int size) { dma_wait(); ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); - return 1; - } @@ -457,116 +350,3 @@ void ed64_ll_set_sdcard_timing (void) { io_write(PI_BSD_DOM2_RLS_REG, 0x03); } - - -void ed64_ll_get_sram (uint8_t *buffer, int size) { - - pi_initialize_sram(); - - dma_wait(); - - pi_initialize(); - - sleep(250); - - // checks if the save isnt large and if so grabs it from the large save area - if(size == KiB(32)) - { - pi_dma_from_sram(buffer, 0, size) ; - } - else - { - pi_dma_from_sram(buffer, -KiB(64), size) ; - } - - dma_wait(); - - ed64_ll_set_sdcard_timing(); - -} - -void ed64_ll_get_eeprom (uint8_t *buffer, int size) { - - int blocks=size/8; - for( int b = 0; b < blocks; b++ ) { - eeprom_read( b, &buffer[b * 8] ); - } - -} - - -void ed64_ll_get_fram (uint8_t *buffer, int size) { - - ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 - sleep(512); - - data_cache_hit_writeback_invalidate(buffer,size); - dma_wait(); - - ed64_ll_get_sram(buffer, size); - - sleep(512); - ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); - -} - -/* -sram upload -*/ - - -void ed64_ll_set_sram (uint8_t *buffer, int size) { - - pi_dma_wait(); - - //Timing - pi_initialize_sram(); - - //Readmode - pi_initialize(); - - data_cache_hit_writeback_invalidate(buffer,size); - dma_wait(); - - // checks if you are no using a large save and if you are puts it in the large save area - if(size == KiB(32)) - { - pi_dma_to_sram(buffer, 0, size) ; - } - else - { - pi_dma_to_sram(buffer, -KiB(64), size) ; - } - - //Wait - pi_dma_wait(); - - //Restore evd Timing - ed64_ll_set_sdcard_timing(); - -} - - -void ed64_ll_set_eeprom (uint8_t *buffer, int size) { - - int blocks=size/8; - for( int b = 0; b < blocks; b++ ) { - eeprom_write( b, &buffer[b * 8] ); - } - -} - -void ed64_ll_set_fram (uint8_t *buffer, int size) { - - ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); - sleep(512); - - data_cache_hit_writeback_invalidate(buffer,size); - dma_wait(); - - ed64_ll_set_sram(buffer, size); - - sleep(512); - ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); - -} diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 1279cd4b1..7b94abbff 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -12,13 +12,10 @@ #include #include -/* ED64 save location base address */ -#define PI_SAVE_ADDR 0xA8000000 - // FIXME: redefined because its in a .c instead of a .h #define PI_BASE_REG 0x04600000 - /////////////////////////////////////////////////////// + #define PI_STATUS_ERROR 0x04 #define PI_STATUS_IO_BUSY 0x02 #define PI_STATUS_DMA_BUSY 0x01 @@ -55,8 +52,6 @@ typedef enum { DEVICE_VARIANT_UNKNOWN = 0xFFFF, - DEVICE_VARIANT_X7_0 = 0x7000, - DEVICE_VARIANT_X5_0 = 0x5000, DEVICE_VARIANT_V3_0 = 0x3000, DEVICE_VARIANT_V2_5 = 0x2000, DEVICE_VARIANT_V2_0 = 0x0000, @@ -79,18 +74,16 @@ typedef enum { #define ROM_ADDRESS (0xB0000000) /* Save functions */ -void pi_initialize_sram (void); -void _data_cache_invalidate_all (void); void ed64_ll_set_sram_bank (uint8_t bank); ed64_save_type_t ed64_ll_get_save_type (); void ed64_ll_set_save_type (ed64_save_type_t type); void ed64_ll_get_sram (uint8_t *buffer, int size); -void ed64_ll_get_eeprom (uint8_t *buffer, int size); +void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t type); void ed64_ll_get_fram (uint8_t *buffer, int size); void ed64_ll_set_sram (uint8_t *buffer, int size); -void ed64_ll_set_eeprom (uint8_t *buffer, int size); +uint8_t ed64_ll_set_eeprom (uint8_t *buffer, uint8_t eep_type); void ed64_ll_set_fram (uint8_t *buffer, int size); /** @} */ /* ed64 */ From 68c32b2d3448fd09d6def6c30c809471e5fb15ea Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 14 Nov 2023 22:40:10 +0000 Subject: [PATCH 36/42] Update ed64_ll.c Fix sram (maybe) --- src/flashcart/ed64/ed64_ll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index cf17b006d..646b46845 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -270,7 +270,7 @@ void ed64_ll_get_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 dma_wait(); - ed64_ll_get_sram_128(buffer, size); + ed64_ll_get_sram(buffer, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); @@ -328,7 +328,7 @@ void ed64_ll_set_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); dma_wait(); - ed64_ll_set_sram_128(buffer, size); + ed64_ll_set_sram(buffer, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); From 8cb97019e2c6c46241de3bcb1f850ed0184d3d8c Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 15 Nov 2023 00:34:02 +0000 Subject: [PATCH 37/42] Work on SRAM Fix missing function. --- src/flashcart/ed64/ed64.c | 2 +- src/flashcart/ed64/ed64_ll.c | 136 +++++++++++------------------------ src/flashcart/ed64/ed64_ll.h | 2 +- 3 files changed, 42 insertions(+), 98 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index cd8f737ac..bdd0d7fab 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -275,7 +275,7 @@ static flashcart_err_t ed64_pesudo_set_save_writeback (void) { break; case SAVE_TYPE_SRAM: case SAVE_TYPE_SRAM_128K: - ed64_ll_get_sram(cartsave_data, save_size); + ed64_ll_get_sram(cartsave_data, 0, save_size); break; case SAVE_TYPE_FLASHRAM: ed64_ll_get_fram(cartsave_data, save_size); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 646b46845..4d312dc8a 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -5,7 +5,7 @@ /* ED64 save location base address */ -#define ED_SAVE_ADDR_BASE (0xA8000000) +#define ED64_SAVE_ADDR_BASE (0xA8000000) /* ED64 configuration registers base address */ #define ED64_CONFIG_REGS_BASE (0xA8040000) @@ -38,10 +38,6 @@ void pi_dma_from_cart (void* dest, void* src, unsigned long size); void pi_dma_to_cart (void* dest, void* src, unsigned long size); void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size); void pi_dma_to_sram (void* src, unsigned long offset, unsigned long size); -void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size); - -void ed64_ll_set_sdcard_timing (void); - typedef enum { SAV_EEP_ON_OFF = 0x01, @@ -136,7 +132,7 @@ void pi_initialize (void) { } -// Inits PI for sram transfer +// Inits PI for sram transfers void pi_initialize_sram (void) { io_write(PI_BSD_DOM2_LAT_REG, 0x05); @@ -147,37 +143,34 @@ void pi_initialize_sram (void) { } void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size) { - io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - io_write(PI_CART_ADDR_REG, (ED_SAVE_ADDR_BASE + offset)); + io_write(PI_CART_ADDR_REG, (ED64_SAVE_ADDR_BASE + offset)); asm volatile ("" : : : "memory"); io_write(PI_WR_LEN_REG, (size - 1)); asm volatile ("" : : : "memory"); - } - void pi_dma_to_sram (void *src, unsigned long offset, unsigned long size) { dma_wait(); io_write(PI_STATUS_REG, 2); io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - io_write(PI_CART_ADDR_REG, (ED_SAVE_ADDR_BASE + offset)); + io_write(PI_CART_ADDR_REG, (ED64_SAVE_ADDR_BASE + offset)); io_write(PI_RD_LEN_REG, (size - 1)); } -void pi_dma_from_cart (void* dest, void* src, unsigned long size) { +// void pi_dma_from_cart (void* dest, void* src, unsigned long size) { - dma_wait(); +// dma_wait(); - io_write(PI_STATUS_REG, 0x03); - io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - io_write(PI_CART_ADDR_REG, K0_TO_PHYS(src)); - io_write(PI_WR_LEN_REG, (size - 1)); +// io_write(PI_STATUS_REG, 0x03); +// io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); +// io_write(PI_CART_ADDR_REG, K0_TO_PHYS(src)); +// io_write(PI_WR_LEN_REG, (size - 1)); -} +// } void pi_dma_to_cart (void* dest, void* src, unsigned long size) { @@ -191,60 +184,26 @@ void pi_dma_to_cart (void* dest, void* src, unsigned long size) { } +void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size) { -// Wrapper to support unaligned access to memory -void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size) { - - if (!dest || !src || !size) return; - - unsigned long unalignedSrc = ((unsigned long)src) % 2; - unsigned long unalignedDest = ((unsigned long)dest) % 8; - - //FIXME: Do i really need to check if size is 16bit aligned? - if (!unalignedDest && !unalignedSrc && !(size % 2)) { - pi_dma_from_cart(dest, src, size); - dma_wait(); - - return; - } - - void* newSrc = (void*)(((unsigned long)src) - unalignedSrc); - unsigned long newSize = (size + unalignedSrc) + ((size + unalignedSrc) % 2); - - unsigned char *buffer = memalign(8, newSize); - pi_dma_from_cart(buffer, newSrc, newSize); - dma_wait(); - - memcpy(dest, (buffer + unalignedSrc), size); - - free(buffer); - -} - + // TODO: potentially set the type so it can be used rather than an offset from the initial address. -void ed64_ll_get_sram (uint8_t *buffer, int size) { + // collect current timings + uint32_t initalLatReg = io_read(PI_BSD_DOM2_LAT_REG); + uint32_t initalPwdReg = io_read(PI_BSD_DOM2_PWD_REG); + uint32_t initalPgsReg = io_read(PI_BSD_DOM2_PGS_REG); + uint32_t initalRlsReg = io_read(PI_BSD_DOM2_RLS_REG); - dma_wait(); - - io_write(PI_BSD_DOM2_LAT_REG, 0x05); - io_write(PI_BSD_DOM2_PWD_REG, 0x0C); - io_write(PI_BSD_DOM2_PGS_REG, 0x0D); - io_write(PI_BSD_DOM2_RLS_REG, 0x02); - - dma_wait(); - - pi_initialize(); - - dma_wait(); + // set temporary timings for SRAM + pi_initialize_sram(); - pi_dma_from_sram(buffer, 0, size) ; + pi_dma_from_sram(buffer, address_offset, size); - dma_wait(); - - io_write(PI_BSD_DOM2_LAT_REG, 0x40); - io_write(PI_BSD_DOM2_PWD_REG, 0x12); - io_write(PI_BSD_DOM2_PGS_REG, 0x07); - io_write(PI_BSD_DOM2_RLS_REG, 0x03); + // restore inital timings + io_write(PI_BSD_DOM2_LAT_REG, initalLatReg); + io_write(PI_BSD_DOM2_PWD_REG, initalPwdReg); + io_write(PI_BSD_DOM2_PGS_REG, initalPgsReg); + io_write(PI_BSD_DOM2_RLS_REG, initalRlsReg); } @@ -270,7 +229,7 @@ void ed64_ll_get_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 dma_wait(); - ed64_ll_get_sram(buffer, size); + ed64_ll_get_sram(buffer, 0, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); @@ -281,24 +240,24 @@ void ed64_ll_get_fram (uint8_t *buffer, int size) { void ed64_ll_set_sram (uint8_t *buffer, int size) { - //half working - dma_wait(); - //Timing - pi_initialize_sram(); + // TODO: potentially set the type so it can be used as an offset from the initial address. - //Readmode - pi_initialize(); + // collect current timings + uint32_t initalLatReg = io_read(PI_BSD_DOM2_LAT_REG); + uint32_t initalPwdReg = io_read(PI_BSD_DOM2_PWD_REG); + uint32_t initalPgsReg = io_read(PI_BSD_DOM2_PGS_REG); + uint32_t initalRlsReg = io_read(PI_BSD_DOM2_RLS_REG); - data_cache_hit_writeback_invalidate(buffer,size); - dma_wait(); + // set temporary timings for SRAM + pi_initialize_sram(); pi_dma_to_sram(buffer, 0, size); - data_cache_hit_writeback_invalidate(buffer,size); - //Wait - dma_wait(); - //Restore evd Timing - ed64_ll_set_sdcard_timing(); + // restore inital timings + io_write(PI_BSD_DOM2_LAT_REG, initalLatReg); + io_write(PI_BSD_DOM2_PWD_REG, initalPwdReg); + io_write(PI_BSD_DOM2_PGS_REG, initalPgsReg); + io_write(PI_BSD_DOM2_RLS_REG, initalRlsReg); } @@ -335,18 +294,3 @@ void ed64_ll_set_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); } - - -void ed64_ll_set_sdcard_timing (void) { - - io_write(PI_BSD_DOM1_LAT_REG, 0x40); - io_write(PI_BSD_DOM1_PWD_REG, 0x12); - io_write(PI_BSD_DOM1_PGS_REG, 0x07); - io_write(PI_BSD_DOM1_RLS_REG, 0x03); - - io_write(PI_BSD_DOM2_LAT_REG, 0x40); - io_write(PI_BSD_DOM2_PWD_REG, 0x12); - io_write(PI_BSD_DOM2_PGS_REG, 0x07); - io_write(PI_BSD_DOM2_RLS_REG, 0x03); - -} diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 7b94abbff..f96a6f39c 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -78,7 +78,7 @@ void ed64_ll_set_sram_bank (uint8_t bank); ed64_save_type_t ed64_ll_get_save_type (); void ed64_ll_set_save_type (ed64_save_type_t type); -void ed64_ll_get_sram (uint8_t *buffer, int size); +void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size); void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t type); void ed64_ll_get_fram (uint8_t *buffer, int size); From 4ca274227f3837a27786d7b7f3b081aef3df5e9b Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 15 Nov 2023 01:53:42 +0000 Subject: [PATCH 38/42] Attempted SRAM improvements --- src/flashcart/ed64/ed64.c | 2 +- src/flashcart/ed64/ed64_ll.c | 57 ++++-------------------------------- src/flashcart/ed64/ed64_ll.h | 2 +- 3 files changed, 7 insertions(+), 54 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index bdd0d7fab..c8eca9def 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -198,7 +198,7 @@ static flashcart_err_t ed64_load_save (char *save_path) { // from file break; case SAVE_TYPE_SRAM: case SAVE_TYPE_SRAM_128K: - ed64_ll_set_sram(cartsave_data, save_file_size); + ed64_ll_set_sram(cartsave_data, 0, save_file_size); break; case SAVE_TYPE_FLASHRAM: ed64_ll_set_fram(cartsave_data, save_file_size); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 4d312dc8a..4cbf1a798 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -2,6 +2,7 @@ #include #include "utils/utils.h" #include "ed64_ll.h" +#include "../flashcart_utils.h" /* ED64 save location base address */ @@ -34,10 +35,6 @@ typedef enum { void pi_initialize (void); void pi_initialize_sram (void); -void pi_dma_from_cart (void* dest, void* src, unsigned long size); -void pi_dma_to_cart (void* dest, void* src, unsigned long size); -void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size); -void pi_dma_to_sram (void* src, unsigned long offset, unsigned long size); typedef enum { SAV_EEP_ON_OFF = 0x01, @@ -142,48 +139,6 @@ void pi_initialize_sram (void) { } -void pi_dma_from_sram (void *dest, unsigned long offset, unsigned long size) { - io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - io_write(PI_CART_ADDR_REG, (ED64_SAVE_ADDR_BASE + offset)); - asm volatile ("" : : : "memory"); - io_write(PI_WR_LEN_REG, (size - 1)); - asm volatile ("" : : : "memory"); -} - -void pi_dma_to_sram (void *src, unsigned long offset, unsigned long size) { - - dma_wait(); - - io_write(PI_STATUS_REG, 2); - io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - io_write(PI_CART_ADDR_REG, (ED64_SAVE_ADDR_BASE + offset)); - io_write(PI_RD_LEN_REG, (size - 1)); - -} - -// void pi_dma_from_cart (void* dest, void* src, unsigned long size) { - -// dma_wait(); - -// io_write(PI_STATUS_REG, 0x03); -// io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); -// io_write(PI_CART_ADDR_REG, K0_TO_PHYS(src)); -// io_write(PI_WR_LEN_REG, (size - 1)); - -// } - - -void pi_dma_to_cart (void* dest, void* src, unsigned long size) { - - dma_wait(); - - io_write(PI_STATUS_REG, 0x02); - io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - io_write(PI_CART_ADDR_REG, K0_TO_PHYS(dest)); - io_write(PI_RD_LEN_REG, (size - 1)); - -} - void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size) { // TODO: potentially set the type so it can be used rather than an offset from the initial address. @@ -197,7 +152,7 @@ void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size) // set temporary timings for SRAM pi_initialize_sram(); - pi_dma_from_sram(buffer, address_offset, size); + pi_dma_read_data((void*)(ED64_SAVE_ADDR_BASE + address_offset), buffer, size); // restore inital timings io_write(PI_BSD_DOM2_LAT_REG, initalLatReg); @@ -238,9 +193,7 @@ void ed64_ll_get_fram (uint8_t *buffer, int size) { } -void ed64_ll_set_sram (uint8_t *buffer, int size) { - - // TODO: potentially set the type so it can be used as an offset from the initial address. +void ed64_ll_set_sram (uint8_t *buffer, uint32_t address_offset, int size) { // collect current timings uint32_t initalLatReg = io_read(PI_BSD_DOM2_LAT_REG); @@ -251,7 +204,7 @@ void ed64_ll_set_sram (uint8_t *buffer, int size) { // set temporary timings for SRAM pi_initialize_sram(); - pi_dma_to_sram(buffer, 0, size); + pi_dma_write_data(buffer, (void*)(ED64_SAVE_ADDR_BASE + address_offset), size); // restore inital timings io_write(PI_BSD_DOM2_LAT_REG, initalLatReg); @@ -287,7 +240,7 @@ void ed64_ll_set_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); dma_wait(); - ed64_ll_set_sram(buffer, size); + ed64_ll_set_sram(buffer, 0, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index f96a6f39c..65f0edc13 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -82,7 +82,7 @@ void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size); void ed64_ll_get_eeprom (uint8_t *buffer, uint8_t type); void ed64_ll_get_fram (uint8_t *buffer, int size); -void ed64_ll_set_sram (uint8_t *buffer, int size); +void ed64_ll_set_sram (uint8_t *buffer, uint32_t address_offset, int size); uint8_t ed64_ll_set_eeprom (uint8_t *buffer, uint8_t eep_type); void ed64_ll_set_fram (uint8_t *buffer, int size); From 9f770277616a7c5b6627eeb948e455bb10bcdc68 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 15 Nov 2023 02:06:44 +0000 Subject: [PATCH 39/42] Remove pi_initalize Improve naming for SRAM timings --- src/flashcart/ed64/ed64_ll.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 4cbf1a798..bce292fae 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -33,8 +33,7 @@ typedef enum { /* ED64 Device Variant Mask */ #define ED64_DEVICE_VARIANT_MASK (0xF000) -void pi_initialize (void); -void pi_initialize_sram (void); +void set_sram_pi_regs (void); typedef enum { SAV_EEP_ON_OFF = 0x01, @@ -121,16 +120,8 @@ void ed64_ll_set_sram_bank (uint8_t bank) { } - -void pi_initialize (void) { - - dma_wait(); - io_write(PI_STATUS_REG, 0x03); - -} - // Inits PI for sram transfers -void pi_initialize_sram (void) { +void set_sram_pi_regs (void) { io_write(PI_BSD_DOM2_LAT_REG, 0x05); io_write(PI_BSD_DOM2_PWD_REG, 0x0C); @@ -150,7 +141,7 @@ void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size) uint32_t initalRlsReg = io_read(PI_BSD_DOM2_RLS_REG); // set temporary timings for SRAM - pi_initialize_sram(); + set_sram_pi_regs(); pi_dma_read_data((void*)(ED64_SAVE_ADDR_BASE + address_offset), buffer, size); @@ -202,7 +193,7 @@ void ed64_ll_set_sram (uint8_t *buffer, uint32_t address_offset, int size) { uint32_t initalRlsReg = io_read(PI_BSD_DOM2_RLS_REG); // set temporary timings for SRAM - pi_initialize_sram(); + set_sram_pi_regs(); pi_dma_write_data(buffer, (void*)(ED64_SAVE_ADDR_BASE + address_offset), size); From 81cdd46c531553703e5b5713816e22a55cdfe27d Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 15 Nov 2023 02:23:09 +0000 Subject: [PATCH 40/42] minor comment improvements --- src/flashcart/ed64/ed64_ll.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index bce292fae..3f095286d 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -143,6 +143,7 @@ void ed64_ll_get_sram (uint8_t *buffer, uint32_t address_offset, uint32_t size) // set temporary timings for SRAM set_sram_pi_regs(); + // read data pi_dma_read_data((void*)(ED64_SAVE_ADDR_BASE + address_offset), buffer, size); // restore inital timings @@ -195,6 +196,7 @@ void ed64_ll_set_sram (uint8_t *buffer, uint32_t address_offset, int size) { // set temporary timings for SRAM set_sram_pi_regs(); + // write data pi_dma_write_data(buffer, (void*)(ED64_SAVE_ADDR_BASE + address_offset), size); // restore inital timings From 7a9f7ce0f06ffcd9b916013eb55ab8b2ba0d7b15 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 15 Nov 2023 02:26:04 +0000 Subject: [PATCH 41/42] space fix --- src/menu/settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/menu/settings.c b/src/menu/settings.c index d5f865eaa..882293c64 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -32,7 +32,7 @@ void settings_load (settings_t *settings) { settings->hidden_files_enabled = mini_get_bool(ini, "menu", "show_hidden_files", init.hidden_files_enabled); settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory)); settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder); - + /* Beta feature flags, they might not be in the file */ settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled); From c23a66c494b9b6f4c9f637da674b50bee6b31259 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Thu, 16 Nov 2023 21:08:49 +0000 Subject: [PATCH 42/42] Ensure load on NMI reset only Speculative fix --- src/flashcart/ed64/ed64.c | 12 +++++++++--- src/flashcart/ed64/ed64_state.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index c8eca9def..14688bfd8 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -37,15 +37,17 @@ 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. + // load the ed64 state file ed64_state_load(¤t_state); - // FIXME: should be checking whether the console was a hot restart here! // Cold restarts are only available with battery backup. - // if (sys_reset_type() != RESET_COLD || RTC == true) + // FIXME: add hot restarts with: ` || RTC == true` + if (current_state.is_expecting_save_writeback == true) { return ed64_pesudo_set_save_writeback(); } + return FLASHCART_OK; } @@ -260,7 +262,11 @@ static flashcart_err_t ed64_pesudo_set_save_writeback (void) { uint8_t cartsave_data[KiB(128)]; // find the path to last save - if (file_exists(strip_sd_prefix(current_state.last_save_path)) && current_state.is_save_type != SAVE_TYPE_NONE) { + if ( + file_exists(strip_sd_prefix(current_state.last_save_path)) + && current_state.is_save_type != SAVE_TYPE_NONE + && sys_reset_type() != RESET_COLD + ) { int save_size = file_get_size(current_state.last_save_path); diff --git a/src/flashcart/ed64/ed64_state.c b/src/flashcart/ed64/ed64_state.c index 6295c0af2..03f630739 100644 --- a/src/flashcart/ed64/ed64_state.c +++ b/src/flashcart/ed64/ed64_state.c @@ -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_expecting_save_writeback", state->is_expecting_save_writeback); - mini_set_int(ini, "ed64", "is_fram_save_type", state->is_save_type); + mini_set_int(ini, "ed64", "is_save_type", state->is_save_type); mini_set_string(ini, "ed64", "last_save_path", state->last_save_path); mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS);