cleaned up code slightly

This commit is contained in:
ariahiro64 2023-10-15 20:48:30 -04:00
parent 01b802ea41
commit 346371afa5

View File

@ -67,6 +67,7 @@ static flashcart_err_t ed64_init (void) {
// everdrive doesnt care about the save type other than eeprom // everdrive doesnt care about the save type other than eeprom
// so we can just check the size // so we can just check the size
if (save_size > KiB(2)) { if (save_size > KiB(2)) {
getSRAM(cartsave_data, save_size); getSRAM(cartsave_data, save_size);
} else { } else {
@ -160,6 +161,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. // 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. // Or somehow warn that certain ROM's will have corruption due to the address space being used for saves.
if (file_size > (MiB(64) - rom_offset)) { if (file_size > (MiB(64) - rom_offset)) {
f_close(&fil); f_close(&fil);
return FLASHCART_ERR_ARGS; return FLASHCART_ERR_ARGS;
@ -189,10 +191,12 @@ static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uin
static flashcart_err_t ed64_load_save (char *save_path) { static flashcart_err_t ed64_load_save (char *save_path) {
FIL fil; FIL fil;
UINT br; UINT br;
if (f_open(&fil, strip_sd_prefix(save_path), FA_READ) != FR_OK) { if (f_open(&fil, strip_sd_prefix(save_path), FA_READ) != FR_OK) {
f_close(&fil); f_close(&fil);
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
size_t save_size = f_size(&fil); size_t save_size = f_size(&fil);
uint8_t cartsave_data[save_size]; uint8_t cartsave_data[save_size];
@ -204,16 +208,22 @@ static flashcart_err_t ed64_load_save (char *save_path) {
if (f_close(&fil) != FR_OK) { if (f_close(&fil) != FR_OK) {
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
// everdrive doesnt care about the save type other than eeprom // everdrive doesnt care about the save type other than eeprom
// so we can just check the size // so we can just check the size
if (save_size >= KiB(32)) { //sram and flash if (save_size >= KiB(32)) { //sram and flash
setSRAM(cartsave_data, save_size); setSRAM(cartsave_data, save_size);
} else if (save_size >= 512){ // eeprom } else if (save_size >= 512){ // eeprom
setEeprom(cartsave_data, save_size); setEeprom(cartsave_data, save_size);
} }
FIL lsp_fil; FIL lsp_fil;
UINT lsp_bw ; UINT lsp_bw;
// probably not nessacery
f_unlink(LAST_SAVE_FILE_PATH); f_unlink(LAST_SAVE_FILE_PATH);
if (f_open(&lsp_fil, LAST_SAVE_FILE_PATH, FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) { if (f_open(&lsp_fil, LAST_SAVE_FILE_PATH, FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
@ -221,16 +231,31 @@ static flashcart_err_t ed64_load_save (char *save_path) {
f_close(&lsp_fil); f_close(&lsp_fil);
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
if (f_close(&lsp_fil) != FR_OK) { if (f_close(&lsp_fil) != FR_OK) {
return FLASHCART_ERR_LOAD; return FLASHCART_ERR_LOAD;
} }
FIL rsfil; FIL rsfil;
UINT rsbr; UINT rsbr;
TCHAR reset_byte[1]; TCHAR reset_byte[1];
f_open(&rsfil, "/menu/RESET",FA_CREATE_ALWAYS); // this wries a 1 byte file as it only needs to exist to detect a reset
f_write(&rsfil, (void *)reset_byte, 1, &rsbr);
if (f_open(&rsfil, "/menu/RESET",FA_CREATE_ALWAYS) != FR_OK) {
f_close(&rsfil); f_close(&rsfil);
return FLASHCART_ERR_LOAD;
}
if (f_write(&rsfil, (void *)reset_byte, 1, &rsbr) != FR_OK) {
f_close(&rsfil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&rsfil) != FR_OK) {
return FLASHCART_OK;
}
return FLASHCART_OK; return FLASHCART_OK;
} }