Merge pull request #934 from smesgr9000/master

remove duplicate code of seeking database files for letters
This commit is contained in:
sanni 2024-04-26 19:24:20 +02:00 committed by GitHub
commit 15c94c110b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 77 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

@ -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()) {