remove duplicate code of seeking database files for letter

This commit is contained in:
smesgr9000 2024-04-24 19:55:43 +02:00
parent 50a147bad7
commit 3441cedfd4
6 changed files with 60 additions and 101 deletions

View File

@ -377,24 +377,7 @@ void setCart_COL() {
// Open database // Open database
if (myFile.open("colv.txt", O_READ)) { if (myFile.open("colv.txt", O_READ)) {
// Skip ahead to selected starting letter seek_first_letter_in_database(myFile, myLetter);
if ((myLetter > 0) && (myLetter <= 26)) {
while (myFile.available()) {
// Read current name
get_line(gamename, &myFile, 96);
// Compare selected letter with first letter of current name until match
while (gamename[0] != 64 + myLetter) {
skip_line(&myFile);
skip_line(&myFile);
get_line(gamename, &myFile, 96);
}
break;
}
// Rewind one line
rewind_line(myFile);
}
// Display database // Display database
while (myFile.available()) { while (myFile.available()) {

View File

@ -660,7 +660,7 @@ boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, i
myFile.close(); myFile.close();
} }
} else { } else {
println_Msg("OK"); println_Msg(FS(FSTRING_OK));
} }
return 1; return 1;
break; break;
@ -678,6 +678,35 @@ boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, i
return 0; return 0;
} }
// 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];
#ifdef ENABLE_GLOBAL_LOG
// Disable log to prevent unnecessary logging
println_Log(F("Select Mapping from List"));
dont_log = true;
#endif
database.rewind();
// Skip ahead to selected starting letter
if ((myLetter > 0) && (myLetter <= 26)) {
myLetter += 'A' - 1;
do {
// Read current name
get_line(gamename_str, &database, 2);
// Skip data line
skip_line(&database);
// Skip empty line
skip_line(&database);
} while (database.available() && gamename_str[0] != myLetter);
rewind_line(database, 3);
}
#ifdef ENABLE_GLOBAL_LOG
// Enable log again
dont_log = false;
#endif
}
void starting_letter__subDraw(byte selection, byte line) { void starting_letter__subDraw(byte selection, byte line) {
display.setDrawColor(0); display.setDrawColor(0);
for (uint8_t i = 0; i < 4; i++) display.drawLine(0, 10 + i * 16, 128, 10 + i * 16); for (uint8_t i = 0; i < 4; i++) display.drawLine(0, 10 + i * 16, 128, 10 + i * 16);

View File

@ -29,7 +29,7 @@
Choose your hardware version: Choose your hardware version:
*/ */
//#define HW5 #define HW5
//#define HW4 //#define HW4
//#define HW3 //#define HW3
//#define HW2 //#define HW2
@ -71,56 +71,56 @@
/* [ Atari 2600 --------------------------------------------------- ] /* [ Atari 2600 --------------------------------------------------- ]
*/ */
//#define ENABLE_2600 #define ENABLE_2600
/****/ /****/
/* [ Atari 5200 --------------------------------------------------- ] /* [ Atari 5200 --------------------------------------------------- ]
*/ */
//#define ENABLE_5200 // #define ENABLE_5200
/****/ /****/
/* [ Atari 7800 --------------------------------------------------- ] /* [ Atari 7800 --------------------------------------------------- ]
*/ */
//#define ENABLE_7800 #define ENABLE_7800
/****/ /****/
/* [ Benesse Pocket Challenge W ----------------------------------- ] /* [ Benesse Pocket Challenge W ----------------------------------- ]
*/ */
//#define ENABLE_PCW // #define ENABLE_PCW
/****/ /****/
/* [ C64 --------------------------------------------------- ] /* [ C64 --------------------------------------------------- ]
*/ */
//#define ENABLE_C64 #define ENABLE_C64
/****/ /****/
/* [ ColecoVision ------------------------------------------------- ] /* [ ColecoVision ------------------------------------------------- ]
*/ */
//#define ENABLE_COLV #define ENABLE_COLV
/****/ /****/
/* [ Emerson Arcadia 2001 ----------------------------------------- ] /* [ Emerson Arcadia 2001 ----------------------------------------- ]
*/ */
//#define ENABLE_ARC // #define ENABLE_ARC
/****/ /****/
/* [ Fairchild Channel F ------------------------------------------ ] /* [ Fairchild Channel F ------------------------------------------ ]
*/ */
//#define ENABLE_FAIRCHILD // #define ENABLE_FAIRCHILD
/****/ /****/
@ -142,21 +142,21 @@
/* [ Intellivision ------------------------------------------------ ] /* [ Intellivision ------------------------------------------------ ]
*/ */
//#define ENABLE_INTV // #define ENABLE_INTV
/****/ /****/
/* [ Neo Geo Pocket ----------------------------------------------- ] /* [ Neo Geo Pocket ----------------------------------------------- ]
*/ */
//#define ENABLE_NGP // #define ENABLE_NGP
/****/ /****/
/* [ Nintendo 64 -------------------------------------------------- ] /* [ Nintendo 64 -------------------------------------------------- ]
*/ */
#define ENABLE_N64 // #define ENABLE_N64
/****/ /****/
@ -170,28 +170,28 @@
/* [ Magnavox Odyssey 2 ------------------------------------------- ] /* [ Magnavox Odyssey 2 ------------------------------------------- ]
*/ */
//#define ENABLE_ODY2 #define ENABLE_ODY2
/****/ /****/
/* [ MSX ------------------------------------------- ] /* [ MSX ------------------------------------------- ]
*/ */
//#define ENABLE_MSX #define ENABLE_MSX
/****/ /****/
/* [ PC Engine/TurboGrafx 16 -------------------------------------- ] /* [ PC Engine/TurboGrafx 16 -------------------------------------- ]
*/ */
//#define ENABLE_PCE #define ENABLE_PCE
/****/ /****/
/* [ Pokemon Mini -------------------------------------- ] /* [ Pokemon Mini -------------------------------------- ]
*/ */
//#define ENABLE_POKE #define ENABLE_POKE
/****/ /****/
@ -212,14 +212,14 @@
/* [ Super Famicom SF Memory Cassette ----------------------------- ] /* [ Super Famicom SF Memory Cassette ----------------------------- ]
*/ */
//#define ENABLE_SFM // #define ENABLE_SFM
/****/ /****/
/* [ Super Famicom Satellaview ------------------------------------ ] /* [ Super Famicom Satellaview ------------------------------------ ]
*/ */
//#define ENABLE_SV // #define ENABLE_SV
/****/ /****/
@ -233,7 +233,7 @@
/* [ Super Famicom Game Processor RAM Cassette -------------------- ] /* [ Super Famicom Game Processor RAM Cassette -------------------- ]
*/ */
//#define ENABLE_GPC // #define ENABLE_GPC
/****/ /****/
@ -247,42 +247,42 @@
/* [ Vectrex --------------------------------------------------- ] /* [ Vectrex --------------------------------------------------- ]
*/ */
//#define ENABLE_VECTREX #define ENABLE_VECTREX
/****/ /****/
/* [ Virtual Boy -------------------------------------------------- ] /* [ Virtual Boy -------------------------------------------------- ]
*/ */
//#define ENABLE_VBOY #define ENABLE_VBOY
/****/ /****/
/* [ Watara Supervision ------------------------------------------- ] /* [ Watara Supervision ------------------------------------------- ]
*/ */
//#define ENABLE_WSV #define ENABLE_WSV
/****/ /****/
/* [ WonderSwan and Benesse Pocket Challenge v2 ------------------- ] /* [ WonderSwan and Benesse Pocket Challenge v2 ------------------- ]
*/ */
//#define ENABLE_WS #define ENABLE_WS
/****/ /****/
/* [ Super A'can -------------------------------------------------- ] /* [ Super A'can -------------------------------------------------- ]
*/ */
//#define ENABLE_SUPRACAN #define ENABLE_SUPRACAN
/****/ /****/
/* [ Casio Loopy -------------------------------------------------- ] /* [ Casio Loopy -------------------------------------------------- ]
*/ */
//#define ENABLE_LOOPY #define ENABLE_LOOPY
/****/ /****/

View File

@ -770,24 +770,7 @@ void setCart_INTV() {
// Open database // Open database
if (myFile.open("intv.txt", O_READ)) { if (myFile.open("intv.txt", O_READ)) {
// Skip ahead to selected starting letter seek_first_letter_in_database(myFile, myLetter);
if ((myLetter > 0) && (myLetter <= 26)) {
while (myFile.available()) {
// Read current name
get_line(gamename, &myFile, 96);
// Compare selected letter with first letter of current name until match
while (gamename[0] != 64 + myLetter) {
skip_line(&myFile);
skip_line(&myFile);
get_line(gamename, &myFile, 96);
}
break;
}
// Rewind one line
rewind_line(myFile);
}
// Display database // Display database
while (myFile.available()) { while (myFile.available()) {

View File

@ -755,7 +755,7 @@ static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
bool selectMapping(FsFile& database) { bool selectMapping(FsFile& database) {
// Select starting letter // Select starting letter
uint8_t myLetter = starting_letter(); byte myLetter = starting_letter();
if (myLetter == 27) { if (myLetter == 27) {
// Change Mapper // Change Mapper
@ -766,26 +766,7 @@ bool selectMapping(FsFile& database) {
setRAMSize(); setRAMSize();
return 0; return 0;
} else { } else {
#ifdef ENABLE_GLOBAL_LOG seek_first_letter_in_database(database, myLetter);
// Disable log to prevent unnecessary logging
println_Log(F("Select Mapping from List"));
dont_log = true;
#endif
database.rewind();
// Skip ahead to selected starting letter
if ((myLetter > 0) && (myLetter <= 26)) {
myLetter += 'A' - 1;
struct database_entry entry;
// Read current name
do {
readDatabaseEntry(database, &entry);
} while (database.available() && entry.filename[0] != myLetter);
rewind_line(database, 3);
}
#ifdef ENABLE_GLOBAL_LOG
// Enable log again
dont_log = false;
#endif
} }
return 1; return 1;
} }

View File

@ -391,24 +391,7 @@ void setCart_WSV() {
// Open database // Open database
if (myFile.open("wsv.txt", O_READ)) { if (myFile.open("wsv.txt", O_READ)) {
// Skip ahead to selected starting letter seek_first_letter_in_database(myFile, myLetter);
if ((myLetter > 0) && (myLetter <= 26)) {
while (myFile.available()) {
// Read current name
get_line(gamename, &myFile, 96);
// Compare selected letter with first letter of current name until match
while (gamename[0] != 64 + myLetter) {
skip_line(&myFile);
skip_line(&myFile);
get_line(gamename, &myFile, 96);
}
break;
}
// Rewind one line
rewind_line(myFile);
}
// Display database // Display database
while (myFile.available()) { while (myFile.available()) {