aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorsmesgr9000 <smesgr9000>2024-05-26 22:20:47 +0200
committersmesgr9000 <smesgr9000>2024-05-26 22:20:47 +0200
commit363d18b5429c2f418250af4496a81d5522aed6d6 (patch)
tree41ce7be00b881091f5f30e27691ed8f96c62edb0
parent78bf1462d00df5cfbc9447b25577e9ec3d128b66 (diff)
downloadcartreader-363d18b5429c2f418250af4496a81d5522aed6d6.tar.gz
cartreader-363d18b5429c2f418250af4496a81d5522aed6d6.zip
add common function to open create folder, print message and open file. Remove duplicate code
-rw-r--r--Cart_Reader/2600.ino8
-rw-r--r--Cart_Reader/5200.ino9
-rw-r--r--Cart_Reader/7800.ino8
-rw-r--r--Cart_Reader/ARC.ino9
-rw-r--r--Cart_Reader/C64.ino8
-rw-r--r--Cart_Reader/COLV.ino8
-rw-r--r--Cart_Reader/Cart_Reader.ino9
-rw-r--r--Cart_Reader/FAIRCHILD.ino9
-rw-r--r--Cart_Reader/GB.ino27
-rw-r--r--Cart_Reader/GBA.ino17
-rw-r--r--Cart_Reader/GPC.ino10
-rw-r--r--Cart_Reader/INTV.ino8
-rw-r--r--Cart_Reader/LOOPY.ino8
-rw-r--r--Cart_Reader/MD.ino18
-rw-r--r--Cart_Reader/MSX.ino8
-rw-r--r--Cart_Reader/N64.ino16
-rw-r--r--Cart_Reader/NES.ino9
-rw-r--r--Cart_Reader/ODY2.ino9
-rw-r--r--Cart_Reader/POKEMINI.ino8
-rw-r--r--Cart_Reader/SMS.ino45
-rw-r--r--Cart_Reader/SNES.ino9
-rw-r--r--Cart_Reader/ST.ino9
-rw-r--r--Cart_Reader/SUPRACAN.ino18
-rw-r--r--Cart_Reader/SV.ino10
-rw-r--r--Cart_Reader/VBOY.ino8
-rw-r--r--Cart_Reader/VECTREX.ino8
-rw-r--r--Cart_Reader/WS.ino14
-rw-r--r--Cart_Reader/WSV.ino8
28 files changed, 62 insertions, 273 deletions
diff --git a/Cart_Reader/2600.ino b/Cart_Reader/2600.ino
index 1d13d16..ac1d7f4 100644
--- a/Cart_Reader/2600.ino
+++ b/Cart_Reader/2600.ino
@@ -296,13 +296,7 @@ boolean checkE7(uint16_t bank) {
}
void readROM_2600() {
- createFolder("ATARI", "ROM", romName, "a26");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("ATARI", "ROM", romName, "a26");
// ROM Start 0xF000
// Address A12-A0 = 0x1000 = 1 0000 0000 0000 = 4KB
diff --git a/Cart_Reader/5200.ino b/Cart_Reader/5200.ino
index 6e488ea..f24c3a8 100644
--- a/Cart_Reader/5200.ino
+++ b/Cart_Reader/5200.ino
@@ -216,16 +216,9 @@ void readSegment_5200(uint16_t startaddr, uint16_t endaddr) {
//******************************************
void readROM_5200() {
- createFolder("5200", "ROM", romName, "a52");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("5200", "ROM", romName, "a52");
// 5200 A13-A0 = 10 0000 0000 0000
-
switch (a5200mapper) {
case 0: // Standard 4KB/8KB/16KB/32KB
// Lower Half of 32K is at 0x4000
diff --git a/Cart_Reader/7800.ino b/Cart_Reader/7800.ino
index e446230..80ef2cf 100644
--- a/Cart_Reader/7800.ino
+++ b/Cart_Reader/7800.ino
@@ -342,13 +342,7 @@ void bankSwitch_7800(uint16_t addr) {
//******************************************
void readROM_7800() {
- createFolder("7800", "ROM", romName, "a78");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("7800", "ROM", romName, "a78");
switch (a7800mapper) {
case 0: // Standard 16K/32K/48K [7816/7832/7848]
diff --git a/Cart_Reader/ARC.ino b/Cart_Reader/ARC.ino
index a2345b8..921c884 100644
--- a/Cart_Reader/ARC.ino
+++ b/Cart_Reader/ARC.ino
@@ -150,14 +150,7 @@ void readSegment_ARC(uint16_t startaddr, uint16_t endaddr) {
}
void readROM_ARC() {
- createFolder("ARC", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("ARC", "ROM", romName, "bin");
readSegment_ARC(0x0000, 0x0800); // 2K
if (arcsize > 0) {
diff --git a/Cart_Reader/C64.ino b/Cart_Reader/C64.ino
index 6ea33cf..a6a943f 100644
--- a/Cart_Reader/C64.ino
+++ b/Cart_Reader/C64.ino
@@ -364,13 +364,7 @@ void readPorts_C64() {
// GAME HIGH/EXROM LOW: ROML = $8000
void readROM_C64() {
- createFolder("C64", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("C64", "ROM", romName, "bin");
switch (c64mapper) {
case 0: // Normal (4K/8K/16K) & Ultimax (8K/16K)
diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino
index ca866ab..2298595 100644
--- a/Cart_Reader/COLV.ino
+++ b/Cart_Reader/COLV.ino
@@ -162,13 +162,7 @@ void readSegment_COL(uint32_t startaddr, uint32_t endaddr) {
}
void readROM_COL() {
- createFolder("COL", "ROM", romName, "col");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("COL", "ROM", romName, "col");
// 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 0e9bb09..de762a6 100644
--- a/Cart_Reader/Cart_Reader.ino
+++ b/Cart_Reader/Cart_Reader.ino
@@ -692,6 +692,15 @@ void printAndIncrementFolder(bool displayClear = false) {
EEPROM_writeAnything(0, foldern);
}
+void createFolderAndOpenFile(const char* system, const char* subfolder, const char* gameName, const char* fileSuffix) {
+ createFolder(system, subfolder, gameName, fileSuffix);
+ printAndIncrementFolder(true);
+
+ if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
+ print_FatalError(sd_error_STR);
+ }
+}
+
// 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 3b02e94..4961e45 100644
--- a/Cart_Reader/FAIRCHILD.ino
+++ b/Cart_Reader/FAIRCHILD.ino
@@ -392,14 +392,7 @@ uint8_t readData_FAIRCHILD() {
}
void readROM_FAIRCHILD() {
- createFolder("FAIRCHILD", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("FAIRCHILD", "ROM", romName, "bin");
unsigned long cartsize = FAIRCHILD[fairchildsize] * 0x400;
uint8_t blocks = cartsize / 0x200;
diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino
index 1654541..eafea41 100644
--- a/Cart_Reader/GB.ino
+++ b/Cart_Reader/GB.ino
@@ -1107,14 +1107,7 @@ void getCartInfo_GB() {
// Read ROM
void readROM_GB() {
// Get name, add extension and convert to char array for sd lib
- createFolder("GB", "ROM", romName, "gb");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("GB", "ROM", romName, "gb");
word endAddress = 0x7FFF;
word romAddress = 0;
@@ -1454,14 +1447,7 @@ unsigned long verifySRAM_GB() {
// Read SRAM + FLASH save data of MBC6
void readSRAMFLASH_MBC6_GB() {
// Get name, add extension and convert to char array for sd lib
- createFolder("GB", "SAVE", romName, "sav");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("GB", "SAVE", romName, "sav");
//Initialize progress bar
uint32_t processedProgressBar = 0;
@@ -2524,14 +2510,7 @@ bool writeCFI_GB() {
// Read Pelican GBC Device - All Brainboys, MonsterBrains, Codebreakers
void readPelican_GB() {
// Get name, add extension and convert to char array for sd lib
- createFolder("GB", "ROM", "Pelican", "GB");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("GB", "ROM", "Pelican", "GB");
word finalAddress = 0x3FFF;
word startAddress = 0x2000;
diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino
index 530cc84..995d9e3 100644
--- a/Cart_Reader/GBA.ino
+++ b/Cart_Reader/GBA.ino
@@ -821,14 +821,7 @@ void getCartInfo_GBA() {
// Dump ROM
void readROM_GBA() {
// Get name, add extension and convert to char array for sd lib
- createFolder("GBA", "ROM", romName, "gba");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("GBA", "ROM", romName, "gba");
//Initialize progress bar
uint32_t processedProgressBar = 0;
@@ -1045,14 +1038,8 @@ void readFRAM_GBA(unsigned long framSize) {
PORTH &= ~((1 << 0) | (1 << 6));
// Get name, add extension and convert to char array for sd lib
- createFolder("GBA", "SAVE", romName, "srm");
+ createFolderAndOpenFile("GBA", "SAVE", romName, "srm");
- printAndIncrementFolder();
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
for (unsigned long currAddress = 0; currAddress < framSize; currAddress += 512) {
for (int c = 0; c < 512; c++) {
// Pull OE_SRAM(PH6) HIGH
diff --git a/Cart_Reader/GPC.ino b/Cart_Reader/GPC.ino
index 7240f03..f9a3ec3 100644
--- a/Cart_Reader/GPC.ino
+++ b/Cart_Reader/GPC.ino
@@ -268,15 +268,7 @@ void readRAM_GPC() {
controlIn_SNES();
// Get name, add extension and convert to char array for sd lib
- createFolder("SNES", "ROM", "GPC4M", "sfc");
-
- //clear the screen
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("SNES", "ROM", "GPC4M", "sfc");
// Read Banks
for (int currBank = 0xC0; currBank < 0xC8; currBank++) {
diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino
index f5564a6..7ecde98 100644
--- a/Cart_Reader/INTV.ino
+++ b/Cart_Reader/INTV.ino
@@ -303,13 +303,7 @@ void readSegment_INTV(uint32_t startaddr, uint32_t endaddr) {
// MODIFIED READ ROUTINE FOR ALL 10 MAPPERS
void readROM_INTV() {
- createFolder("INTV", "ROM", romName, "int");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("INTV", "ROM", romName, "int");
switch (intvmapper) {
case 0: //default mattel up to 32K (8K/12K/16K/24K/32K)
diff --git a/Cart_Reader/LOOPY.ino b/Cart_Reader/LOOPY.ino
index 3b6c45c..c4065cb 100644
--- a/Cart_Reader/LOOPY.ino
+++ b/Cart_Reader/LOOPY.ino
@@ -522,13 +522,7 @@ void getCartInfo_LOOPY() {
void readROM_LOOPY() {
dataIn_LOOPY();
- createFolder("LOOPY", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("LOOPY", "ROM", romName, "bin");
draw_progressbar(0, cartSize);
diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino
index b70b3bb..ab78674 100644
--- a/Cart_Reader/MD.ino
+++ b/Cart_Reader/MD.ino
@@ -1424,14 +1424,7 @@ void readROM_MD() {
dataIn_MD();
// Get name, add extension and convert to char array for sd lib
- createFolder("MD", "ROM", romName, "BIN");
-
- printAndIncrementFolder(true);
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("MD", "ROM", romName, "BIN");
byte buffer[1024] = { 0 };
@@ -2872,14 +2865,7 @@ void readRealtec_MD() {
dataIn_MD();
// Get name, add extension and convert to char array for sd lib
- createFolder("MD", "ROM", romName, "MD");
-
- printAndIncrementFolder(true);
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("MD", "ROM", romName, "MD");
// Realtec Registers
writeWord_MD(0x201000, 4); // Number of 128K Blocks 0x402000 (0x201000)
diff --git a/Cart_Reader/MSX.ino b/Cart_Reader/MSX.ino
index 29747d4..bc848c9 100644
--- a/Cart_Reader/MSX.ino
+++ b/Cart_Reader/MSX.ino
@@ -343,13 +343,7 @@ void readROM_MSX() {
println_Msg(F("ROM SIZE 0K"));
display_Update();
} else {
- createFolder("MSX", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("MSX", "ROM", romName, "bin");
switch (msxmapper) {
case 0: // No Mapper
diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino
index 1ff9253..a53ef8b 100644
--- a/Cart_Reader/N64.ino
+++ b/Cart_Reader/N64.ino
@@ -4194,13 +4194,7 @@ void resetGameshark_N64() {
// Read rom and save to the SD card
void backupGameshark_N64() {
- createFolder("N64", "ROM", "GameShark", "z64");
- printAndIncrementFolder(true);
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("N64", "ROM", "GameShark", "z64");
for (unsigned long currByte = romBase + 0xEC00000; currByte < (romBase + 0xEC00000 + flashSize); currByte += 512) {
// Blink led
@@ -4563,13 +4557,7 @@ void resetXplorer_N64() {
// Read rom and save to the SD card
void backupXplorer_N64() {
// create a new folder
- createFolder("N64", "ROM", "XPLORER64", "z64");
- printAndIncrementFolder(true);
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("N64", "ROM", "XPLORER64", "z64");
for (unsigned long currByte = 0x10400000; currByte <= 0x1043FFFF; currByte += 512) {
// Blink led
diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino
index 7b05bf9..6923b91 100644
--- a/Cart_Reader/NES.ino
+++ b/Cart_Reader/NES.ino
@@ -711,14 +711,7 @@ bool selectMapping(FsFile& database) {
void read_NES(const char* fileSuffix, const byte* header, const uint8_t headersize, const boolean renamerom) {
// Get name, add extension and convert to char array for sd lib
- createFolder("NES", "ROM", romName, fileSuffix);
-
- printAndIncrementFolder(true);
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("NES", "ROM", romName, fileSuffix);
//Initialize progress bar
uint32_t processedProgressBar = 0;
diff --git a/Cart_Reader/ODY2.ino b/Cart_Reader/ODY2.ino
index 94d7e3d..5559bb1 100644
--- a/Cart_Reader/ODY2.ino
+++ b/Cart_Reader/ODY2.ino
@@ -212,14 +212,7 @@ void bankSwitch_ODY2(uint16_t addr, uint8_t data) {
}
void readROM_ODY2() {
- createFolder("ODY2", "ROM", romName, "bin");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("ODY2", "ROM", romName, "bin");
if (ody2mapper == 1) { // A10 CONNECTED
// Videopac 31: Musician
diff --git a/Cart_Reader/POKEMINI.ino b/Cart_Reader/POKEMINI.ino
index 89df9f3..2de7bd4 100644
--- a/Cart_Reader/POKEMINI.ino
+++ b/Cart_Reader/POKEMINI.ino
@@ -239,13 +239,7 @@ void writeData_POKE(uint32_t addr, uint8_t data) {
//******************************************
void readROM_POKE() {
- createFolder("POKE", "ROM", romName, "min");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("POKE", "ROM", romName, "min");
// read rom
uint32_t progress = 0;
diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino
index bc30f0c..721a316 100644
--- a/Cart_Reader/SMS.ino
+++ b/Cart_Reader/SMS.ino
@@ -647,37 +647,30 @@ void readSRAM_SMS() {
} else {
system = "SMS";
}
- createFolder(system, "SAVE", romName, "sav");
+ createFolderAndOpenFile(system, "SAVE", romName, "sav");
- printAndIncrementFolder(true);
+ // Write the whole 32KB
+ // When there is only 8KB of SRAM, the contents should be duplicated
+ word bankSize = 16 * 1024UL;
+ for (byte currBank = 0x0; currBank < 2; currBank++) {
+ writeByte_SMS(0xFFFC, 0x08 | (currBank << 2));
- // Create file on sd card
- if (myFile.open(fileName, O_RDWR | O_CREAT)) {
- // Write the whole 32KB
- // When there is only 8KB of SRAM, the contents should be duplicated
- word bankSize = 16 * 1024UL;
- for (byte currBank = 0x0; currBank < 2; currBank++) {
- writeByte_SMS(0xFFFC, 0x08 | (currBank << 2));
-
- // Blink led
- blinkLED();
-
- // Read 16KB from slot 2 which starts at 0x8000
- for (word currBuffer = 0; currBuffer < bankSize; currBuffer += 512) {
- // Fill SD buffer
- for (int currByte = 0; currByte < 512; currByte++) {
- sdBuffer[currByte] = readByte_SMS(0x8000 + currBuffer + currByte);
- }
- myFile.write(sdBuffer, 512);
+ // Blink led
+ blinkLED();
+
+ // Read 16KB from slot 2 which starts at 0x8000
+ for (word currBuffer = 0; currBuffer < bankSize; currBuffer += 512) {
+ // Fill SD buffer
+ for (int currByte = 0; currByte < 512; currByte++) {
+ sdBuffer[currByte] = readByte_SMS(0x8000 + currBuffer + currByte);
}
+ myFile.write(sdBuffer, 512);
}
- // Close file
- myFile.close();
- print_STR(press_button_STR, 1);
- display_Update();
- } else {
- print_FatalError(sd_error_STR);
}
+ // Close file
+ myFile.close();
+ print_STR(press_button_STR, 1);
+ display_Update();
}
//**********************************************
diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino
index 9826a20..c6a1bcc 100644
--- a/Cart_Reader/SNES.ino
+++ b/Cart_Reader/SNES.ino
@@ -1291,14 +1291,7 @@ void readROM_SNES() {
controlIn_SNES();
// Get name, add extension and convert to char array for sd lib
- createFolder("SNES", "ROM", romName, "sfc");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("SNES", "ROM", romName, "sfc");
//Dump Derby Stallion '96 (Japan) and Sound Novel Tsukuru (Japan) - Actual Size is 24Mb
if ((romType == LO) && (numBanks == 96) && ((strcmp("CC86", checksumStr) == 0) || (strcmp("A77B", checksumStr) == 0))) {
diff --git a/Cart_Reader/ST.ino b/Cart_Reader/ST.ino
index 046c66d..0dd5df7 100644
--- a/Cart_Reader/ST.ino
+++ b/Cart_Reader/ST.ino
@@ -167,14 +167,7 @@ void readSlot(bool cartSlot) {
// Read ST rom to SD card
void readRom_ST(unsigned int bankStart, unsigned int bankEnd) {
// create a new folder to save rom file
- createFolder("ST", "ROM", "SUFAMI_TURBO", "st");
-
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("ST", "ROM", "SUFAMI_TURBO", "st");
// Read specified banks
readLoRomBanks(bankStart + 0x80, bankEnd + 0x80, &myFile);
diff --git a/Cart_Reader/SUPRACAN.ino b/Cart_Reader/SUPRACAN.ino
index 26c5fd4..25a4fb3 100644
--- a/Cart_Reader/SUPRACAN.ino
+++ b/Cart_Reader/SUPRACAN.ino
@@ -148,11 +148,7 @@ void suprAcanMenu() {
static void readROM_Acan() {
uint32_t crc32 = 0xffffffff;
- createFolder("/ACAN", "ROM", "rom", "bin");
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("/ACAN", "ROM", "rom", "bin");
draw_progressbar(0, cartSize);
@@ -180,11 +176,7 @@ static void readROM_Acan() {
}
static void readSRAM_Acan() {
- createFolder("/ACAN", "SAVE", "save", "bin");
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("/ACAN", "SAVE", "save", "bin");
dataIn_MD();
for (uint32_t i = 0; i < 0x10000; i += 1024) {
@@ -265,11 +257,7 @@ static void verifySRAM_Acan() {
}
static void readUM6650() {
- createFolder("/ACAN", "UM6650", "UM6650", "bin");
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("/ACAN", "UM6650", "UM6650", "bin");
for (uint16_t i = 0; i < 256; i++) {
dataOut_MD();
diff --git a/Cart_Reader/SV.ino b/Cart_Reader/SV.ino
index 98ef186..e91af24 100644
--- a/Cart_Reader/SV.ino
+++ b/Cart_Reader/SV.ino
@@ -413,15 +413,7 @@ void readROM_SV() {
controlIn_SNES();
// Get name, add extension and convert to char array for sd lib
- createFolder("SNES", "ROM", "MEMPACK", "bs");
-
- //clear the screen
- printAndIncrementFolder(true);
-
- //open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
+ createFolderAndOpenFile("SNES", "ROM", "MEMPACK", "bs");
// Read Banks
for (int currBank = 0x40; currBank < 0x50; currBank++) {
diff --git a/Cart_Reader/VBOY.ino b/Cart_Reader/VBOY.ino
index 25cf14e..8212e7f 100644
--- a/Cart_Reader/VBOY.ino
+++ b/Cart_Reader/VBOY.ino
@@ -410,13 +410,7 @@ void getCartInfo_VB() {
void readROM_VB() {
dataIn_VB();
- createFolder("VBOY", "ROM", romName, "vb");
-
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(sd_error_STR);
- }
+ createFolderAndOpenFile("VBOY", "ROM", romName, "vb");
word d = 0;
uint32_t progress = 0;
diff --git a/Cart_Reader/VECTREX.ino b/Cart_Reader/VECTREX.ino
index 10c7dd1..ee9bcb4 100644
--- a/Cart_Reader/VECTREX.ino
+++ b/Cart_Reader/VECTREX.ino
@@ -196,13 +196,7 @@ void readSegment_VECTREX(uint16_t startaddr, uint16_t endaddr) {
//******************************************
void readROM_VECTREX() {
- createFolder("VECTREX", "ROM", romName, "vec");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(sd_error_STR);
+ createFolderAndOpenFile("VECTREX", "ROM", romName, "vec");
PB6_DISABLE; // PB6 LOW - Switch Bank
diff --git a/Cart_Reader/WS.ino b/Cart_Reader/WS.ino
index 3ca1d63..3105458 100644
--- a/Cart_Reader/WS.ino
+++ b/Cart_Reader/WS.ino
@@ -553,12 +553,7 @@ static uint16_t readROM_WS(char *outPathBuf, size_t bufferSize) {
static void readSRAM_WS() {
// generate fullname of rom file
- createFolder("WS", "SAVE", romName, "save");
-
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("WS", "SAVE", romName, "save");
uint32_t bank_size = (sramSize << 7);
uint16_t end_bank = (bank_size >> 16); // 64KB per bank
@@ -685,12 +680,7 @@ static void writeSRAM_WS() {
static void readEEPROM_WS() {
// generate fullname of eep file
- createFolder("WS", "SAVE", romName, "eep");
-
- printAndIncrementFolder(true);
-
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("WS", "SAVE", romName, "eep");
uint32_t eepromSize = (sramSize << 7);
uint32_t bufSize = (eepromSize < 512 ? eepromSize : 512);
diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino
index 82b65f2..d326cf3 100644
--- a/Cart_Reader/WSV.ino
+++ b/Cart_Reader/WSV.ino
@@ -185,13 +185,7 @@ uint8_t readByte_WSV(uint32_t addr) {
//******************************************
void readROM_WSV() {
- createFolder("WSV", "ROM", romName, "sv");
-
- printAndIncrementFolder(true);
-
- // open file on sdcard
- if (!myFile.open(fileName, O_RDWR | O_CREAT))
- print_FatalError(create_file_STR);
+ createFolderAndOpenFile("WSV", "ROM", romName, "sv");
// start reading rom
dataIn_WSV();