From 0a627e5bd4010e36c32877a916da02d2213a2c1b Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 05:01:59 +0000 Subject: [PATCH] All: Use f.seekCur(x) instead of f.seekSet(f.curPosition() + x) Saves 450 bytes of program space. --- Cart_Reader/COLV.ino | 18 +++++++++--------- Cart_Reader/Cart_Reader.ino | 4 ++-- Cart_Reader/GBA.ino | 20 ++++++++++---------- Cart_Reader/INTV.ino | 22 +++++++++++----------- Cart_Reader/N64.ino | 12 ++++++------ Cart_Reader/NES.ino | 36 ++++++++++++++++++------------------ Cart_Reader/SNES.ino | 10 +++++----- Cart_Reader/WSV.ino | 18 +++++++++--------- 8 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index 9f16d84..4ea817e 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -399,15 +399,15 @@ void setCart_COL() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -425,7 +425,7 @@ void setCart_COL() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -435,7 +435,7 @@ void setCart_COL() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -449,7 +449,7 @@ void setCart_COL() { } // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -490,15 +490,15 @@ void setCart_COL() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7ddf943..6415943 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -655,7 +655,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int #ifdef enable_NES if ((mode == mode_NES) && (offset != 0)) { // Rewind to iNES Header - myFile.seekSet(myFile.curPosition() - 36); + myFile.seekCur(-36); char iNES_STR[33]; // Read iNES header @@ -668,7 +668,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int iNES_HEADER[j] = iNES_BUF; } //Skip CRLF - myFile.seekSet(myFile.curPosition() + 4); + myFile.seekCur(4); } #endif // enable_NES diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index e435946..5b1054b 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -873,7 +873,7 @@ void getCartInfo_GBA() { skip_line(&myFile); // 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 sprintf(tempStr, "%c", myFile.read()); @@ -890,15 +890,15 @@ void getCartInfo_GBA() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Display database while (myFile.available()) { @@ -908,7 +908,7 @@ void getCartInfo_GBA() { get_line(gamename, &myFile, 96); // 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 sprintf(tempStr, "%c", myFile.read()); @@ -918,7 +918,7 @@ void getCartInfo_GBA() { } // 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 cartSize = myFile.read() - 48; @@ -930,7 +930,7 @@ void getCartInfo_GBA() { } // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read save type into string get_line(saveTypeStr, &myFile, 14); @@ -980,15 +980,15 @@ void getCartInfo_GBA() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 3fd7590..4acc8f9 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -812,15 +812,15 @@ void setCart_INTV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -838,7 +838,7 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -848,13 +848,13 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read mapper intvmapper = myFile.read() - 48; // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -868,13 +868,13 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read SRAM size byte sramSize __attribute__ ((unused)) = myFile.read() - 48; // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -916,15 +916,15 @@ void setCart_INTV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 2e1e51c..2456603 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2051,7 +2051,7 @@ void printCartInfo_N64() { // Check if string is a match if (strcasecmp(tempStr1, crcStr) == 0) { // 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 sprintf(tempStr, "%c", myFile.read()); @@ -2071,7 +2071,7 @@ void printCartInfo_N64() { } // If no match, empty string, advance by 12 and try again else { - myFile.seekSet(myFile.curPosition() + 12); + myFile.seekCur(12); } } // Close the file: @@ -2106,7 +2106,7 @@ void getCartInfo_N64() { skip_line(&myFile); // 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 sprintf(tempStr, "%c", myFile.read()); @@ -2118,7 +2118,7 @@ void getCartInfo_N64() { // Check if string is a match if (strcmp(tempStr, checksumStr) == 0) { // 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 cartSize = myFile.read() - 48; @@ -2130,7 +2130,7 @@ void getCartInfo_N64() { } // 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 saveType = myFile.read() - 48; @@ -2141,7 +2141,7 @@ void getCartInfo_N64() { // If no match skip to next entry else { // skip rest of line - myFile.seekSet(myFile.curPosition() + 7); + myFile.seekCur(7); // skip third empty line skip_line(&myFile); } diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index da43208..301e3b7 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -559,7 +559,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -569,7 +569,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -586,15 +586,15 @@ boolean getMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Display database @@ -612,7 +612,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -622,7 +622,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -756,15 +756,15 @@ boolean getMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } @@ -879,15 +879,15 @@ void selectMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -905,7 +905,7 @@ void selectMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -915,7 +915,7 @@ void selectMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -1040,15 +1040,15 @@ void selectMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 5a0c8d8..c4383a7 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -847,7 +847,7 @@ void checkAltConf(char crcStr[9]) { skip_line(&myFile); // Skip over the CRC checksum - myFile.seekSet(myFile.curPosition() + 9); + myFile.seekCur(9); // Get internal ROM checksum as string for (byte j = 0; j < 4; j++) { @@ -862,7 +862,7 @@ void checkAltConf(char crcStr[9]) { display_Update(); // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read the CRC32 of the SNES header out of database for (byte k = 0; k < 8; k++) { @@ -871,13 +871,13 @@ void checkAltConf(char crcStr[9]) { tempStr3[8] = '\0'; // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read file size byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48); // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read number of banks 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 else { // skip rest of line - myFile.seekSet(myFile.curPosition() + 18); + myFile.seekCur(18); // skip third empty line skip_line(&myFile); } diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index c3a70a5..da409b6 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -413,15 +413,15 @@ void setCart_WSV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -439,7 +439,7 @@ void setCart_WSV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -449,7 +449,7 @@ void setCart_WSV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -463,7 +463,7 @@ void setCart_WSV() { } // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -507,15 +507,15 @@ void setCart_WSV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; }