Skip to content

Commit

Permalink
remove duplicate code to create folder
Browse files Browse the repository at this point in the history
  • Loading branch information
smesgr9000 committed May 12, 2024
1 parent 38b2b24 commit 9f0aa09
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 450 deletions.
9 changes: 1 addition & 8 deletions Cart_Reader/2600.ino
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,7 @@ boolean checkE7(uint16_t bank) {
}

void readROM_2600() {
strcpy(fileName, romName);
strcat(fileName, ".a26");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "ATARI/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("ATARI", "ROM", romName, "a26");

display_Clear();
print_Msg(F("Saving to "));
Expand Down
9 changes: 1 addition & 8 deletions Cart_Reader/5200.ino
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,7 @@ void readSegment_5200(uint16_t startaddr, uint16_t endaddr) {
//******************************************

void readROM_5200() {
strcpy(fileName, romName);
strcat(fileName, ".a52");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "5200/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("5200", "ROM", romName, "a52");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down
9 changes: 1 addition & 8 deletions Cart_Reader/7800.ino
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,7 @@ void bankSwitch_7800(uint16_t addr) {
//******************************************

void readROM_7800() {
strcpy(fileName, romName);
strcat(fileName, ".a78");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "7800/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("7800", "ROM", romName, "a78");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down
9 changes: 1 addition & 8 deletions Cart_Reader/ARC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,7 @@ void readSegment_ARC(uint16_t startaddr, uint16_t endaddr) {
}

void readROM_ARC() {
strcpy(fileName, romName);
strcat(fileName, ".bin");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "ARC/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("ARC", "ROM", romName, "bin");

display_Clear();
print_Msg(F("Saving to "));
Expand Down
9 changes: 1 addition & 8 deletions Cart_Reader/C64.ino
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,7 @@ void readPorts_C64() {
// GAME HIGH/EXROM LOW: ROML = $8000

void readROM_C64() {
strcpy(fileName, romName);
strcat(fileName, ".bin");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "C64/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("C64", "ROM", romName, "bin");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down
10 changes: 1 addition & 9 deletions Cart_Reader/COLV.ino
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,7 @@ void readSegment_COL(uint32_t startaddr, uint32_t endaddr) {
}

void readROM_COL() {
strcpy(fileName, romName);
strcat(fileName, ".col");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
// sprintf(folder, "COL/ROM/%s/%d", romName, foldern);
sprintf(folder, "COL/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("COL", "ROM", romName, "col");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down
10 changes: 10 additions & 0 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ int int_pow(int base, int exp) { // Power for int
}
#endif

void createFolder(const char* system, const char* subfolder, const char* gameName, const char* fileSuffix) {
snprintf(fileName, FILENAME_LENGTH, "%s.%s", gameName, fileSuffix);

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "%s/%s/%s/%d", system, subfolder, gameName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
}

// 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];
Expand Down
21 changes: 3 additions & 18 deletions Cart_Reader/FAIRCHILD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,7 @@ uint8_t readData_FAIRCHILD() {
}

void readROM_FAIRCHILD() {
strcpy(fileName, romName);
strcat(fileName, ".bin");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "FAIRCHILD/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("FAIRCHILD", "ROM", romName, "bin");

display_Clear();
print_Msg(F("Saving to "));
Expand Down Expand Up @@ -479,16 +472,8 @@ void readROM_FAIRCHILD() {
wait();
}

void read16K_FAIRCHILD() // Read 16K Bytes
{
strcpy(fileName, romName);
strcat(fileName, ".bin");

// create a new folder for storing rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "FAIRCHILD/ROM/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
void read16K_FAIRCHILD() { // Read 16K Bytes
createFolder("FAIRCHILD", "ROM", romName, "bin");

display_Clear();
print_Msg(F("Saving to "));
Expand Down
71 changes: 11 additions & 60 deletions Cart_Reader/GB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ void getCartInfo_GB() {

// ROM banks
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x08) {
if (romSize >= 0x01 && romSize <= 0x08) {
romBanks = int_pow(2, romSize + 1);
}

Expand Down Expand Up @@ -1107,14 +1107,7 @@ void getCartInfo_GB() {
// Read ROM
void readROM_GB() {
// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".GB");

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/ROM/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "ROM", romName, "gb");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -1322,14 +1315,7 @@ void readSRAM_GB() {
if (lastByte > 0) {

// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".sav");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "SAVE", romName, "sav");

// write new folder number back to eeprom
foldern = foldern + 1;
Expand Down Expand Up @@ -1476,14 +1462,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
strcpy(fileName, romName);
strcat(fileName, ".sav");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "SAVE", romName, "sav");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -1711,14 +1690,7 @@ void writeSRAMFLASH_MBC6_GB() {
void readEEPROM_MBC7_GB() {

// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".sav");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "SAVE", romName, "sav");

// write new folder number back to eeprom
foldern = foldern + 1;
Expand Down Expand Up @@ -1932,7 +1904,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {

// ROM banks
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x07) {
if (romSize >= 0x01 && romSize <= 0x07) {
romBanks = int_pow(2, romSize + 1);
}

Expand Down Expand Up @@ -2354,7 +2326,7 @@ bool writeCFI_GB() {

// ROM banks
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x07) {
if (romSize >= 0x01 && romSize <= 0x07) {
romBanks = int_pow(2, romSize + 1);
}

Expand Down Expand Up @@ -2568,14 +2540,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
strcpy(fileName, "Pelican");
strcat(fileName, ".GB");

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/ROM/Pelican/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "ROM", "Pelican", "GB");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -3027,14 +2992,7 @@ bool isToggle(byte byte1, byte byte2) {
// Read Mega Memory Card Rom and Save Backup Data
void readMegaMem_GB() {
// Dump the Rom
strcpy(fileName, "Rom");
strcat(fileName, ".GB");

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/ROM/MegaMem/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GB", "ROM", "MegaMem", "GB");

display_Clear();
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -3349,10 +3307,6 @@ void writeMegaMem_GB() {
***************************************************/
// Read Datel GBC Gameshark Device
void readGameshark_GB() {
// Get name, add extension and convert to char array for sd lib
strcpy(fileName, "Gameshark");
strcat(fileName, ".GB");

word finalAddress = 0x5FFF;
word startAddress = 0x4000;
word bankAddress = 0x7FE1;
Expand Down Expand Up @@ -3401,11 +3355,8 @@ void readGameshark_GB() {
mainMenu();
}

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GB/ROM/Gameshark/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
// 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);
Expand Down
47 changes: 5 additions & 42 deletions Cart_Reader/GBA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,7 @@ void getCartInfo_GBA() {
// Dump ROM
void readROM_GBA() {
// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".gba");

// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GBA/ROM/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GBA", "ROM", romName, "gba");

//clear the screen
display_Clear();
Expand Down Expand Up @@ -935,14 +928,7 @@ boolean compare_checksum_GBA() {
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
strcpy(fileName, romName);
strcat(fileName, ".srm");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GBA/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GBA", "SAVE", romName, "srm");

// Save location
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -1076,14 +1062,7 @@ void readFRAM_GBA(unsigned long framSize) {
PORTH &= ~((1 << 0) | (1 << 6));

// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".srm");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "GBA/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GBA", "SAVE", romName, "srm");

// Save location
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -1480,15 +1459,7 @@ void readFLASH_GBA(boolean browseFile, uint32_t flashSize, uint32_t pos) {

if (browseFile) {
// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".fla");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);

sprintf(folder, "GBA/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GBA", "SAVE", romName, "fla");

// Save location
print_STR(saving_to_STR, 0);
Expand Down Expand Up @@ -1724,15 +1695,7 @@ void writeEeprom_GBA(word eepSize) {
// Read eeprom to file
void readEeprom_GBA(word eepSize) {
// Get name, add extension and convert to char array for sd lib
strcpy(fileName, romName);
strcat(fileName, ".eep");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);

sprintf(folder, "GBA/SAVE/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("GBA", "SAVE", romName, "eep");

// Save location
print_STR(saving_to_STR, 0);
Expand Down
8 changes: 1 addition & 7 deletions Cart_Reader/GPC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,7 @@ void readRAM_GPC() {
controlIn_SNES();

// Get name, add extension and convert to char array for sd lib
strcpy(fileName, "GPC4M.sfc");

// create a new folder for the save file
EEPROM_readAnything(0, foldern);
sprintf(folder, "SNES/ROM/%s/%d", "GPC4M", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
createFolder("SNES", "ROM", "GPC4M", "sfc");

//clear the screen
display_Clear();
Expand Down
Loading

0 comments on commit 9f0aa09

Please sign in to comment.