From 78bf1462d00df5cfbc9447b25577e9ec3d128b66 Mon Sep 17 00:00:00 2001 From: smesgr9000 Date: Sun, 26 May 2024 21:48:57 +0200 Subject: [PATCH] replace custom folder creation function with common --- Cart_Reader/N64.ino | 35 ++++------------------------------- Cart_Reader/SUPRACAN.ino | 29 ++++++----------------------- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 51ca9359..1ff92530 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -4194,22 +4194,8 @@ void resetGameshark_N64() { // Read rom and save to the SD card void backupGameshark_N64() { - // create a new folder - EEPROM_readAnything(0, foldern); - sprintf(fileName, "GS%d", foldern); - strcat(fileName, ".z64"); - sd.mkdir("N64/ROM/Gameshark", true); - sd.chdir("N64/ROM/Gameshark"); - - display_Clear(); - print_Msg(F("Saving ")); - print_Msg(fileName); - println_Msg(F("...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + createFolder("N64", "ROM", "GameShark", "z64"); + printAndIncrementFolder(true); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -4577,21 +4563,8 @@ void resetXplorer_N64() { // Read rom and save to the SD card void backupXplorer_N64() { // create a new folder - EEPROM_readAnything(0, foldern); - sprintf(fileName, "XP64-%d", foldern); - strcat(fileName, ".z64"); - sd.mkdir("N64/ROM/XPLORER64", true); - sd.chdir("N64/ROM/XPLORER64"); - - display_Clear(); - print_Msg(F("Saving ")); - print_Msg(fileName); - println_Msg(F("...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + createFolder("N64", "ROM", "XPLORER64", "z64"); + printAndIncrementFolder(true); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/SUPRACAN.ino b/Cart_Reader/SUPRACAN.ino index c096f210..26c5fd4e 100644 --- a/Cart_Reader/SUPRACAN.ino +++ b/Cart_Reader/SUPRACAN.ino @@ -148,15 +148,10 @@ void suprAcanMenu() { static void readROM_Acan() { uint32_t crc32 = 0xffffffff; - EEPROM_readAnything(0, foldern); - snprintf(folder, FILEPATH_LENGTH, "/ACAN/ROM/%d", foldern); - + createFolder("/ACAN", "ROM", "rom", "bin"); printAndIncrementFolder(true); - sd.mkdir(folder, true); - sd.chdir(folder); - - if (!myFile.open("rom.bin", O_RDWR | O_CREAT)) + if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); draw_progressbar(0, cartSize); @@ -185,16 +180,10 @@ static void readROM_Acan() { } static void readSRAM_Acan() { - // create a new folder for storing rom file - EEPROM_readAnything(0, foldern); - snprintf(folder, FILEPATH_LENGTH, "/ACAN/SAVE/%d", foldern); - + createFolder("/ACAN", "SAVE", "save", "bin"); printAndIncrementFolder(true); - sd.mkdir(folder, true); - sd.chdir(folder); - - if (!myFile.open("save.bin", O_RDWR | O_CREAT)) + if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); dataIn_MD(); @@ -276,16 +265,10 @@ static void verifySRAM_Acan() { } static void readUM6650() { - // create a new folder for storing rom file - EEPROM_readAnything(0, foldern); - snprintf(folder, sizeof(folder), "/ACAN/UM6650/%d", foldern); - + createFolder("/ACAN", "UM6650", "UM6650", "bin"); printAndIncrementFolder(true); - sd.mkdir(folder, true); - sd.chdir(folder); - - if (!myFile.open("UM6650.bin", O_RDWR | O_CREAT)) + if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); for (uint16_t i = 0; i < 256; i++) {