From ad69abdf57d49e27a0670393c9a42a0c196ba17d Mon Sep 17 00:00:00 2001 From: smesgr9000 Date: Sat, 1 Jun 2024 09:58:23 +0200 Subject: [PATCH] use common function to create file/folder and increment foldern counter --- Cart_Reader/N64.ino | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index dab9c8f..e8d08a1 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -48,9 +48,6 @@ String CRC2 = ""; unsigned long flashSize; #endif -static const char N64_EEP_FILENAME_FMT[] PROGMEM = "%s.eep"; -static const char N64_SAVE_DIRNAME_FMT[] PROGMEM = "N64/SAVE/%s/%d"; - /****************************************** Menu *****************************************/ @@ -2281,22 +2278,7 @@ boolean readEepromPageList(byte* output, byte page_number, byte page_count) { void readEeprom() { if ((saveType == 5) || (saveType == 6)) { // Get name, add extension and convert to char array for sd lib - snprintf_P(fileName, sizeof(fileName), N64_EEP_FILENAME_FMT, romName); - - // create a new folder for the save file - EEPROM_readAnything(0, foldern); - snprintf_P(folder, sizeof(folder), N64_SAVE_DIRNAME_FMT, romName, foldern); - sd.mkdir(folder, true); - sd.chdir(folder); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); - - // Open file on sd card - if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_FatalError(create_file_STR); - } + createFolderAndOpenFile("N64", "SAVE", romName, "eep"); for (int i = 0; i < eepPages; i += sizeof(sdBuffer) / 8) { // If any missing bytes error out @@ -2421,16 +2403,7 @@ void readSram(unsigned long sramSize, byte flashramType) { } else { print_FatalError(F("Savetype Error")); } - createFolder("N64", "SAVE", romName, suffix); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); - - // Open file on sd card - if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_FatalError(sd_error_STR); - } + createFolderAndOpenFile("N64", "SAVE", romName, suffix); for (unsigned long currByte = sramBase; currByte < (sramBase + (sramSize / flashramType)); currByte += offset) { // Set the address