All: Use f.seekCur(x) instead of f.seekSet(f.curPosition() + x)

Saves 450 bytes of program space.
This commit is contained in:
Vincent Pelletier 2022-10-23 05:01:59 +00:00
parent a555f2117f
commit 0a627e5bd4
8 changed files with 70 additions and 70 deletions

View File

@ -399,15 +399,15 @@ void setCart_COL() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
} }
// Display database // Display database
@ -425,7 +425,7 @@ void setCart_COL() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -435,7 +435,7 @@ void setCart_COL() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read rom size // Read rom size
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
@ -449,7 +449,7 @@ void setCart_COL() {
} }
// Skip rest of line // Skip rest of line
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
// Skip every 3rd line // Skip every 3rd line
skip_line(&myFile); skip_line(&myFile);
@ -490,15 +490,15 @@ void setCart_COL() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }

View File

@ -655,7 +655,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int
#ifdef enable_NES #ifdef enable_NES
if ((mode == mode_NES) && (offset != 0)) { if ((mode == mode_NES) && (offset != 0)) {
// Rewind to iNES Header // Rewind to iNES Header
myFile.seekSet(myFile.curPosition() - 36); myFile.seekCur(-36);
char iNES_STR[33]; char iNES_STR[33];
// Read iNES header // Read iNES header
@ -668,7 +668,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int
iNES_HEADER[j] = iNES_BUF; iNES_HEADER[j] = iNES_BUF;
} }
//Skip CRLF //Skip CRLF
myFile.seekSet(myFile.curPosition() + 4); myFile.seekCur(4);
} }
#endif // enable_NES #endif // enable_NES

View File

@ -873,7 +873,7 @@ void getCartInfo_GBA() {
skip_line(&myFile); skip_line(&myFile);
// Skip over the CRC checksum // Skip over the CRC checksum
myFile.seekSet(myFile.curPosition() + 9); myFile.seekCur(9);
// Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up
sprintf(tempStr, "%c", myFile.read()); sprintf(tempStr, "%c", myFile.read());
@ -890,15 +890,15 @@ void getCartInfo_GBA() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
// Display database // Display database
while (myFile.available()) { while (myFile.available()) {
@ -908,7 +908,7 @@ void getCartInfo_GBA() {
get_line(gamename, &myFile, 96); get_line(gamename, &myFile, 96);
// Skip over the CRC checksum // Skip over the CRC checksum
myFile.seekSet(myFile.curPosition() + 9); myFile.seekCur(9);
// Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up
sprintf(tempStr, "%c", myFile.read()); sprintf(tempStr, "%c", myFile.read());
@ -918,7 +918,7 @@ void getCartInfo_GBA() {
} }
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
cartSize = myFile.read() - 48; cartSize = myFile.read() - 48;
@ -930,7 +930,7 @@ void getCartInfo_GBA() {
} }
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read save type into string // Read save type into string
get_line(saveTypeStr, &myFile, 14); get_line(saveTypeStr, &myFile, 14);
@ -980,15 +980,15 @@ void getCartInfo_GBA() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }

View File

@ -812,15 +812,15 @@ void setCart_INTV() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
} }
// Display database // Display database
@ -838,7 +838,7 @@ void setCart_INTV() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -848,13 +848,13 @@ void setCart_INTV() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read mapper // Read mapper
intvmapper = myFile.read() - 48; intvmapper = myFile.read() - 48;
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read rom size // Read rom size
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
@ -868,13 +868,13 @@ void setCart_INTV() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read SRAM size // Read SRAM size
byte sramSize __attribute__ ((unused)) = myFile.read() - 48; byte sramSize __attribute__ ((unused)) = myFile.read() - 48;
// Skip rest of line // Skip rest of line
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
// Skip every 3rd line // Skip every 3rd line
skip_line(&myFile); skip_line(&myFile);
@ -916,15 +916,15 @@ void setCart_INTV() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }

View File

@ -2051,7 +2051,7 @@ void printCartInfo_N64() {
// Check if string is a match // Check if string is a match
if (strcasecmp(tempStr1, crcStr) == 0) { if (strcasecmp(tempStr1, crcStr) == 0) {
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up
sprintf(tempStr, "%c", myFile.read()); sprintf(tempStr, "%c", myFile.read());
@ -2071,7 +2071,7 @@ void printCartInfo_N64() {
} }
// If no match, empty string, advance by 12 and try again // If no match, empty string, advance by 12 and try again
else { else {
myFile.seekSet(myFile.curPosition() + 12); myFile.seekCur(12);
} }
} }
// Close the file: // Close the file:
@ -2106,7 +2106,7 @@ void getCartInfo_N64() {
skip_line(&myFile); skip_line(&myFile);
// Skip over the CRC32 checksum // Skip over the CRC32 checksum
myFile.seekSet(myFile.curPosition() + 9); myFile.seekCur(9);
// Read 8 bytes into String, do it one at a time so byte order doesn't get mixed up // Read 8 bytes into String, do it one at a time so byte order doesn't get mixed up
sprintf(tempStr, "%c", myFile.read()); sprintf(tempStr, "%c", myFile.read());
@ -2118,7 +2118,7 @@ void getCartInfo_N64() {
// Check if string is a match // Check if string is a match
if (strcmp(tempStr, checksumStr) == 0) { if (strcmp(tempStr, checksumStr) == 0) {
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
cartSize = myFile.read() - 48; cartSize = myFile.read() - 48;
@ -2130,7 +2130,7 @@ void getCartInfo_N64() {
} }
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
saveType = myFile.read() - 48; saveType = myFile.read() - 48;
@ -2141,7 +2141,7 @@ void getCartInfo_N64() {
// If no match skip to next entry // If no match skip to next entry
else { else {
// skip rest of line // skip rest of line
myFile.seekSet(myFile.curPosition() + 7); myFile.seekCur(7);
// skip third empty line // skip third empty line
skip_line(&myFile); skip_line(&myFile);
} }

View File

@ -559,7 +559,7 @@ boolean getMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -569,7 +569,7 @@ boolean getMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read iNES header // Read iNES header
get_line(iNES_STR, &myFile, 33); get_line(iNES_STR, &myFile, 33);
@ -586,15 +586,15 @@ boolean getMapping() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
// Display database // Display database
@ -612,7 +612,7 @@ boolean getMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -622,7 +622,7 @@ boolean getMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read iNES header // Read iNES header
get_line(iNES_STR, &myFile, 33); get_line(iNES_STR, &myFile, 33);
@ -756,15 +756,15 @@ boolean getMapping() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }
@ -879,15 +879,15 @@ void selectMapping() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
} }
// Display database // Display database
@ -905,7 +905,7 @@ void selectMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -915,7 +915,7 @@ void selectMapping() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read iNES header // Read iNES header
get_line(iNES_STR, &myFile, 33); get_line(iNES_STR, &myFile, 33);
@ -1040,15 +1040,15 @@ void selectMapping() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }

View File

@ -847,7 +847,7 @@ void checkAltConf(char crcStr[9]) {
skip_line(&myFile); skip_line(&myFile);
// Skip over the CRC checksum // Skip over the CRC checksum
myFile.seekSet(myFile.curPosition() + 9); myFile.seekCur(9);
// Get internal ROM checksum as string // Get internal ROM checksum as string
for (byte j = 0; j < 4; j++) { for (byte j = 0; j < 4; j++) {
@ -862,7 +862,7 @@ void checkAltConf(char crcStr[9]) {
display_Update(); display_Update();
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read the CRC32 of the SNES header out of database // Read the CRC32 of the SNES header out of database
for (byte k = 0; k < 8; k++) { for (byte k = 0; k < 8; k++) {
@ -871,13 +871,13 @@ void checkAltConf(char crcStr[9]) {
tempStr3[8] = '\0'; tempStr3[8] = '\0';
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read file size // Read file size
byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48); byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48);
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read number of banks // Read number of banks
byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48); byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48);
@ -911,7 +911,7 @@ void checkAltConf(char crcStr[9]) {
// If no match go to next entry // If no match go to next entry
else { else {
// skip rest of line // skip rest of line
myFile.seekSet(myFile.curPosition() + 18); myFile.seekCur(18);
// skip third empty line // skip third empty line
skip_line(&myFile); skip_line(&myFile);
} }

View File

@ -413,15 +413,15 @@ void setCart_WSV() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
} }
// Display database // Display database
@ -439,7 +439,7 @@ void setCart_WSV() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read CRC32 of first 512 bytes // Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read()); sprintf(crc_search, "%c", myFile.read());
@ -449,7 +449,7 @@ void setCart_WSV() {
} }
// Skip over semicolon // Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1); myFile.seekCur(1);
// Read rom size // Read rom size
// Read the next ascii character and subtract 48 to convert to decimal // Read the next ascii character and subtract 48 to convert to decimal
@ -463,7 +463,7 @@ void setCart_WSV() {
} }
// Skip rest of line // Skip rest of line
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
// Skip every 3rd line // Skip every 3rd line
skip_line(&myFile); skip_line(&myFile);
@ -507,15 +507,15 @@ void setCart_WSV() {
if (myFile.curPosition() == 0) { if (myFile.curPosition() == 0) {
break; break;
} else if (myFile.peek() == '\n') { } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
break; break;
} else { } else {
myFile.seekSet(myFile.curPosition() - 1); myFile.seekCur(-1);
} }
} }
} }
if (myFile.curPosition() != 0) if (myFile.curPosition() != 0)
myFile.seekSet(myFile.curPosition() + 2); myFile.seekCur(2);
break; break;
} }