From 6abe29fcd9b30e45c539876a57634aa840f77a58 Mon Sep 17 00:00:00 2001 From: smesgr9000 Date: Sat, 25 May 2024 14:07:08 +0200 Subject: [PATCH] remove duplicate code to print saving and increment of folder id --- Cart_Reader/2600.ino | 9 +------ Cart_Reader/5200.ino | 9 +------ Cart_Reader/7800.ino | 9 +------ Cart_Reader/ARC.ino | 8 +------ Cart_Reader/C64.ino | 9 +------ Cart_Reader/COLV.ino | 9 +------ Cart_Reader/Cart_Reader.ino | 11 +++++++++ Cart_Reader/FAIRCHILD.ino | 9 +------ Cart_Reader/GB.ino | 36 ++++------------------------ Cart_Reader/GBA.ino | 48 ++++--------------------------------- Cart_Reader/GPC.ino | 9 +------ Cart_Reader/INTV.ino | 9 +------ Cart_Reader/LOOPY.ino | 8 +------ Cart_Reader/MD.ino | 18 ++------------ Cart_Reader/MSX.ino | 9 +------ Cart_Reader/N64.ino | 18 ++------------ Cart_Reader/NES.ino | 14 +++-------- Cart_Reader/NGP.ino | 9 +------ Cart_Reader/ODY2.ino | 9 +------ Cart_Reader/PCW.ino | 16 ++----------- Cart_Reader/POKEMINI.ino | 9 +------ Cart_Reader/SMS.ino | 18 ++------------ Cart_Reader/SNES.ino | 9 +------ Cart_Reader/ST.ino | 9 +------ Cart_Reader/SUPRACAN.ino | 24 +++---------------- Cart_Reader/SV.ino | 9 +------ Cart_Reader/VBOY.ino | 8 +------ Cart_Reader/VECTREX.ino | 9 +------ Cart_Reader/WS.ino | 25 +++---------------- Cart_Reader/WSV.ino | 9 +------ 30 files changed, 57 insertions(+), 348 deletions(-) diff --git a/Cart_Reader/2600.ino b/Cart_Reader/2600.ino index da538d4..883051d 100644 --- a/Cart_Reader/2600.ino +++ b/Cart_Reader/2600.ino @@ -299,19 +299,12 @@ void readROM_2600() { createFolder("ATARI", "ROM", romName, "a26"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // ROM Start 0xF000 // Address A12-A0 = 0x1000 = 1 0000 0000 0000 = 4KB // Read Start 0x1000 diff --git a/Cart_Reader/5200.ino b/Cart_Reader/5200.ino index 2eee63d..a3f6f9d 100644 --- a/Cart_Reader/5200.ino +++ b/Cart_Reader/5200.ino @@ -219,19 +219,12 @@ void readROM_5200() { createFolder("5200", "ROM", romName, "a52"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // 5200 A13-A0 = 10 0000 0000 0000 switch (a5200mapper) { diff --git a/Cart_Reader/7800.ino b/Cart_Reader/7800.ino index fafcbf5..b09b231 100644 --- a/Cart_Reader/7800.ino +++ b/Cart_Reader/7800.ino @@ -345,19 +345,12 @@ void readROM_7800() { createFolder("7800", "ROM", romName, "a78"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - switch (a7800mapper) { case 0: // Standard 16K/32K/48K [7816/7832/7848] readStandard_7800(); diff --git a/Cart_Reader/ARC.ino b/Cart_Reader/ARC.ino index d5207d6..943741c 100644 --- a/Cart_Reader/ARC.ino +++ b/Cart_Reader/ARC.ino @@ -153,18 +153,12 @@ void readROM_ARC() { createFolder("ARC", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(create_file_STR); } - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); readSegment_ARC(0x0000, 0x0800); // 2K if (arcsize > 0) { diff --git a/Cart_Reader/C64.ino b/Cart_Reader/C64.ino index b55f0da..dc88923 100644 --- a/Cart_Reader/C64.ino +++ b/Cart_Reader/C64.ino @@ -367,19 +367,12 @@ void readROM_C64() { createFolder("C64", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - switch (c64mapper) { case 0: // Normal (4K/8K/16K) & Ultimax (8K/16K) readPorts_C64(); diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index 2673f99..fd5ad45 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -165,19 +165,12 @@ void readROM_COL() { createFolder("COL", "ROM", romName, "col"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // RESET ALL CS PINS HIGH (DISABLE) PORTH |= (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6); diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index ffb0312..611f6a3 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -678,6 +678,17 @@ void createFolder(const char* system, const char* subfolder, const char* gameNam sd.chdir(folder); } +void printAndIncrementFolder() { + // Save location + print_STR(saving_to_STR, 0); + print_Msg(folder); + println_Msg(F("/...")); + display_Update(); + // write new folder number back to eeprom + foldern = foldern + 1; + EEPROM_writeAnything(0, foldern); +} + // move file pointer to first game line with matching letter. If no match is found the last database entry is selected void seek_first_letter_in_database(FsFile& database, byte myLetter) { char gamename_str[3]; diff --git a/Cart_Reader/FAIRCHILD.ino b/Cart_Reader/FAIRCHILD.ino index 67c10d5..d2120ac 100644 --- a/Cart_Reader/FAIRCHILD.ino +++ b/Cart_Reader/FAIRCHILD.ino @@ -395,20 +395,13 @@ void readROM_FAIRCHILD() { createFolder("FAIRCHILD", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(create_file_STR); } - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - unsigned long cartsize = FAIRCHILD[fairchildsize] * 0x400; uint8_t blocks = cartsize / 0x200; setROMC_FAIRCHILD(0x8); // Clear PC0 diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index 3922147..e77e694 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -1110,14 +1110,7 @@ void readROM_GB() { createFolder("GB", "ROM", romName, "gb"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -1465,14 +1458,7 @@ void readSRAMFLASH_MBC6_GB() { createFolder("GB", "SAVE", romName, "sav"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -2543,14 +2529,7 @@ void readPelican_GB() { createFolder("GB", "ROM", "Pelican", "GB"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -3358,14 +3337,7 @@ void readGameshark_GB() { // Get name, add extension and convert to char array for sd lib createFolder("GB", "ROM", "Gameshark", "GB"); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index cca63a7..6e2b55d 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -825,14 +825,7 @@ void readROM_GBA() { //clear the screen display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -929,15 +922,7 @@ void readSRAM_GBA(boolean browseFile, uint32_t sramSize, uint32_t pos) { if (browseFile) { // Get name, add extension and convert to char array for sd lib createFolder("GBA", "SAVE", romName, "srm"); - - // Save location - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); } //open file on sd card @@ -1064,14 +1049,7 @@ void readFRAM_GBA(unsigned long framSize) { // Get name, add extension and convert to char array for sd lib createFolder("GBA", "SAVE", romName, "srm"); - // Save location - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -1461,15 +1439,7 @@ void readFLASH_GBA(boolean browseFile, uint32_t flashSize, uint32_t pos) { // Get name, add extension and convert to char array for sd lib createFolder("GBA", "SAVE", romName, "fla"); - // Save location - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); } //open file on sd card @@ -1697,15 +1667,7 @@ void readEeprom_GBA(word eepSize) { // Get name, add extension and convert to char array for sd lib createFolder("GBA", "SAVE", romName, "eep"); - // Save location - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/GPC.ino b/Cart_Reader/GPC.ino index 612ee34..629609a 100644 --- a/Cart_Reader/GPC.ino +++ b/Cart_Reader/GPC.ino @@ -272,14 +272,7 @@ void readRAM_GPC() { //clear the screen display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 047ae3b..e593ce1 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -306,19 +306,12 @@ void readROM_INTV() { createFolder("INTV", "ROM", romName, "int"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - switch (intvmapper) { case 0: //default mattel up to 32K (8K/12K/16K/24K/32K) readSegment_INTV(0x5000, 0x6000); // 8K diff --git a/Cart_Reader/LOOPY.ino b/Cart_Reader/LOOPY.ino index a33d323..21574e1 100644 --- a/Cart_Reader/LOOPY.ino +++ b/Cart_Reader/LOOPY.ino @@ -525,13 +525,7 @@ void readROM_LOOPY() { createFolder("LOOPY", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(sd_error_STR); diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index 2ee271b..b216fdd 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -1427,14 +1427,7 @@ void readROM_MD() { createFolder("MD", "ROM", romName, "BIN"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -2883,14 +2876,7 @@ void readRealtec_MD() { createFolder("MD", "ROM", romName, "MD"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/MSX.ino b/Cart_Reader/MSX.ino index 0b65464..7be291a 100644 --- a/Cart_Reader/MSX.ino +++ b/Cart_Reader/MSX.ino @@ -346,19 +346,12 @@ void readROM_MSX() { createFolder("MSX", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - switch (msxmapper) { case 0: // No Mapper disableCS(); diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 280f788..51ca935 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2820,14 +2820,7 @@ void readRom_N64() { // clear the screen // display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -2868,14 +2861,7 @@ uint32_t readRom_N64() { // clear the screen // display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 6807daa..6ef2f14 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -614,10 +614,9 @@ void getMapping() { sprintf(crcStr, "%08lX", oldcrc32); print_Msg(crcStr); if (oldcrc32 != oldcrc32MMC3) { - char crcStrMMC3[9]; print_Msg(F(" or ")); - sprintf(crcStrMMC3, "%08lX", oldcrc32MMC3); - print_Msg(crcStrMMC3); + sprintf(crcStr, "%08lX", oldcrc32MMC3); + print_Msg(crcStr); } println_Msg(F("...")); display_Update(); @@ -715,14 +714,7 @@ void read_NES(const char* fileSuffix, const byte* header, const uint8_t headersi createFolder("NES", "ROM", romName, fileSuffix); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/NGP.ino b/Cart_Reader/NGP.ino index ecbbbb6..b0e9b46 100644 --- a/Cart_Reader/NGP.ino +++ b/Cart_Reader/NGP.ino @@ -215,19 +215,12 @@ void readROM_NGP(char* outPathBuf, size_t bufferSize) { snprintf(outPathBuf, bufferSize, "%s/%s", folder, fileName); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // back to read mode dataOut(); writeByte_NGP(0x0, 0xf0); diff --git a/Cart_Reader/ODY2.ino b/Cart_Reader/ODY2.ino index 81a6317..47edf40 100644 --- a/Cart_Reader/ODY2.ino +++ b/Cart_Reader/ODY2.ino @@ -215,20 +215,13 @@ void readROM_ODY2() { createFolder("ODY2", "ROM", romName, "bin"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(create_file_STR); } - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - if (ody2mapper == 1) { // A10 CONNECTED // Videopac 31: Musician // Videopac 40: 4 in 1 Row/4 en 1 Ligne diff --git a/Cart_Reader/PCW.ino b/Cart_Reader/PCW.ino index 0d330fe..ddcc370 100644 --- a/Cart_Reader/PCW.ino +++ b/Cart_Reader/PCW.ino @@ -427,13 +427,7 @@ void readSingleROM_PCW() { // Create file createFolder("PCW", "ROM", romName, "pcw"); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(sd_error_STR); @@ -561,13 +555,7 @@ void readMultiROM_PCW() { // Create file createFolder("PCW", "ROM", romName, "pcw"); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(sd_error_STR); diff --git a/Cart_Reader/POKEMINI.ino b/Cart_Reader/POKEMINI.ino index bf301c5..bbbe5fa 100644 --- a/Cart_Reader/POKEMINI.ino +++ b/Cart_Reader/POKEMINI.ino @@ -242,19 +242,12 @@ void readROM_POKE() { createFolder("POKE", "ROM", romName, "min"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // read rom uint32_t progress = 0; draw_progressbar(0, 0x80000); diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino index f326e7e..977ccaa 100644 --- a/Cart_Reader/SMS.ino +++ b/Cart_Reader/SMS.ino @@ -559,14 +559,7 @@ void readROM_SMS() { } display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // Write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { @@ -658,14 +651,7 @@ void readSRAM_SMS() { createFolder(system, "SAVE", romName, "sav"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); // Create file on sd card if (myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index b15dfb9..e961c3d 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -1295,14 +1295,7 @@ void readROM_SNES() { //clear the screen display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/ST.ino b/Cart_Reader/ST.ino index 9285b8d..dd96b5d 100644 --- a/Cart_Reader/ST.ino +++ b/Cart_Reader/ST.ino @@ -170,14 +170,7 @@ void readRom_ST(unsigned int bankStart, unsigned int bankEnd) { createFolder("ST", "ROM", "SUFAMI_TURBO", "st"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern++; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //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 571c301..6d737f7 100644 --- a/Cart_Reader/SUPRACAN.ino +++ b/Cart_Reader/SUPRACAN.ino @@ -152,10 +152,7 @@ static void readROM_Acan() { snprintf(folder, FILEPATH_LENGTH, "/ACAN/ROM/%d", foldern); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); sd.mkdir(folder, true); sd.chdir(folder); @@ -163,9 +160,6 @@ static void readROM_Acan() { if (!myFile.open("rom.bin", O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - foldern++; - EEPROM_writeAnything(0, foldern); - draw_progressbar(0, cartSize); dataIn_MD(); @@ -197,10 +191,7 @@ static void readSRAM_Acan() { snprintf(folder, FILEPATH_LENGTH, "/ACAN/SAVE/%d", foldern); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); sd.mkdir(folder, true); sd.chdir(folder); @@ -208,9 +199,6 @@ static void readSRAM_Acan() { if (!myFile.open("save.bin", O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - foldern++; - EEPROM_writeAnything(0, foldern); - dataIn_MD(); for (uint32_t i = 0; i < 0x10000; i += 1024) { for (uint32_t j = 0; j < 1024; j += 2) @@ -295,10 +283,7 @@ static void readUM6650() { snprintf(folder, sizeof(folder), "/ACAN/UM6650/%d", foldern); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); sd.mkdir(folder, true); sd.chdir(folder); @@ -306,9 +291,6 @@ static void readUM6650() { if (!myFile.open("UM6650.bin", O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - foldern++; - EEPROM_writeAnything(0, foldern); - for (uint16_t i = 0; i < 256; i++) { dataOut_MD(); writeWord_Acan(0xeb0d03, i); diff --git a/Cart_Reader/SV.ino b/Cart_Reader/SV.ino index c140aaa..9e36b03 100644 --- a/Cart_Reader/SV.ino +++ b/Cart_Reader/SV.ino @@ -417,14 +417,7 @@ void readROM_SV() { //clear the screen display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - // write new folder number back to eeprom - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { diff --git a/Cart_Reader/VBOY.ino b/Cart_Reader/VBOY.ino index 294e216..bd68bd2 100644 --- a/Cart_Reader/VBOY.ino +++ b/Cart_Reader/VBOY.ino @@ -413,13 +413,7 @@ void readROM_VB() { createFolder("VBOY", "ROM", romName, "vb"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern = foldern + 1; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_FatalError(sd_error_STR); diff --git a/Cart_Reader/VECTREX.ino b/Cart_Reader/VECTREX.ino index 049592d..a541d71 100644 --- a/Cart_Reader/VECTREX.ino +++ b/Cart_Reader/VECTREX.ino @@ -199,19 +199,12 @@ void readROM_VECTREX() { createFolder("VECTREX", "ROM", romName, "vec"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(sd_error_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - PB6_DISABLE; // PB6 LOW - Switch Bank // Standard Carts 4K/8K diff --git a/Cart_Reader/WS.ino b/Cart_Reader/WS.ino index 921c340..f4617be 100644 --- a/Cart_Reader/WS.ino +++ b/Cart_Reader/WS.ino @@ -490,19 +490,12 @@ static uint16_t readROM_WS(char *outPathBuf, size_t bufferSize) { snprintf(outPathBuf, bufferSize, "%s/%s", folder, fileName); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // get correct starting rom bank uint16_t bank = (256 - (cartSize >> 16)); uint32_t progress = 0; @@ -564,13 +557,7 @@ static void readSRAM_WS() { createFolder("WS", "SAVE", romName, "save"); display_Clear(); - print_Msg(F("Saving ")); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern++; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); @@ -703,13 +690,7 @@ static void readEEPROM_WS() { createFolder("WS", "SAVE", romName, "eep"); display_Clear(); - print_Msg(F("Saving ")); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); - - foldern++; - EEPROM_writeAnything(0, foldern); + printAndIncrementFolder(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index ebe3c7b..8b047f6 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -188,19 +188,12 @@ void readROM_WSV() { createFolder("WSV", "ROM", romName, "sv"); display_Clear(); - print_STR(saving_to_STR, 0); - print_Msg(folder); - println_Msg(F("/...")); - display_Update(); + printAndIncrementFolder(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) print_FatalError(create_file_STR); - // write new folder number back to EEPROM - foldern++; - EEPROM_writeAnything(0, foldern); - // start reading rom dataIn_WSV(); controlIn_WSV();