From 254982cbe7343415c4635f6d6d034d47196c9c74 Mon Sep 17 00:00:00 2001 From: smesgr9000 Date: Wed, 1 May 2024 10:48:58 +0200 Subject: [PATCH] remove duplicate CRC printing and calculation function --- Cart_Reader/2600.ino | 10 +--------- Cart_Reader/5200.ino | 3 +-- Cart_Reader/7800.ino | 3 +-- Cart_Reader/ARC.ino | 3 +-- Cart_Reader/C64.ino | 3 +-- Cart_Reader/Cart_Reader.ino | 35 +++++++---------------------------- Cart_Reader/FAIRCHILD.ino | 4 ++-- Cart_Reader/MSX.ino | 6 ++---- Cart_Reader/NES.ino | 22 ---------------------- Cart_Reader/ODY2.ino | 3 +-- Cart_Reader/VECTREX.ino | 3 +-- 11 files changed, 18 insertions(+), 77 deletions(-) diff --git a/Cart_Reader/2600.ino b/Cart_Reader/2600.ino index 8fd55d0..c27683c 100644 --- a/Cart_Reader/2600.ino +++ b/Cart_Reader/2600.ino @@ -554,15 +554,7 @@ void readROM_2600() { } myFile.close(); - unsigned long crcsize = a2600[a2600size] * 0x400; - // Correct E7 Size for 8K/12K ROMs - if (a2600mapper == 0xE7) { - if (e7size == 0) - crcsize = a2600[a2600size] * 0x200; - else if (e7size == 1) - crcsize = a2600[a2600size] * 0x300; - } - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); diff --git a/Cart_Reader/5200.ino b/Cart_Reader/5200.ino index 893bf7c..1269134 100644 --- a/Cart_Reader/5200.ino +++ b/Cart_Reader/5200.ino @@ -327,8 +327,7 @@ void readROM_5200() { } myFile.close(); - unsigned long crcsize = a5200[a5200size] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline diff --git a/Cart_Reader/7800.ino b/Cart_Reader/7800.ino index aa42dae..80d7b6c 100644 --- a/Cart_Reader/7800.ino +++ b/Cart_Reader/7800.ino @@ -424,8 +424,7 @@ void readROM_7800() { } myFile.close(); - unsigned long crcsize = a7800[a7800size] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline diff --git a/Cart_Reader/ARC.ino b/Cart_Reader/ARC.ino index e05d3d7..f94003c 100644 --- a/Cart_Reader/ARC.ino +++ b/Cart_Reader/ARC.ino @@ -186,8 +186,7 @@ void readROM_ARC() { } myFile.close(); - unsigned long crcsize = ARC[arcsize] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); diff --git a/Cart_Reader/C64.ino b/Cart_Reader/C64.ino index a2affd8..89d45cb 100644 --- a/Cart_Reader/C64.ino +++ b/Cart_Reader/C64.ino @@ -640,8 +640,7 @@ void readROM_C64() { } myFile.close(); - unsigned long crcsize = C64[c64size] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index bcb659e..bb51740 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -455,43 +455,22 @@ uint32_t calculateCRC(char* fileName, char* folder, int offset) { /****************************************** CRC Functions for Atari, Fairchild, Ody2, Arc, etc. modules *****************************************/ -#if (defined(ENABLE_ODY2) || defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_MSX) || defined(ENABLE_POKE) || defined(ENABLE_2600) || defined(ENABLE_5200) || defined(ENABLE_7800) || defined(ENABLE_C64) || defined(ENABLE_VECTREX)) +#if (defined(ENABLE_ODY2) || defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_MSX) || defined(ENABLE_POKE) || defined(ENABLE_2600) || defined(ENABLE_5200) || defined(ENABLE_7800) || defined(ENABLE_C64) || defined(ENABLE_VECTREX) || defined(ENABLE_NES)) -inline uint32_t updateCRC(uint8_t ch, uint32_t crc) { - uint32_t idx = ((crc) ^ (ch)) & 0xff; - uint32_t tab_value = pgm_read_dword(crc_32_tab + idx); - return tab_value ^ ((crc) >> 8); -} - -FsFile crcFile; -char tempCRC[9]; - -uint32_t crc32(FsFile& file, uint32_t& charcnt) { - uint32_t oldcrc32 = 0xFFFFFFFF; - charcnt = 0; - while (file.available()) { - crcFile.read(sdBuffer, 512); - for (int x = 0; x < 512; x++) { - uint8_t c = sdBuffer[x]; - charcnt++; - oldcrc32 = updateCRC(c, oldcrc32); - } - } - return ~oldcrc32; -} - -void calcCRC(char* checkFile, unsigned long filesize, uint32_t* crcCopy, unsigned long offset) { +void printCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) { uint32_t crc; - crcFile = sd.open(checkFile); + char tempCRC[9]; + FsFile crcFile = sd.open(checkFile); + crcFile.seek(offset); - crc = crc32(crcFile, filesize); + crc = calculateCRC(crcFile); crcFile.close(); - sprintf(tempCRC, "%08lX", crc); if (crcCopy != NULL) { *crcCopy = crc; } + sprintf(tempCRC, "%08lX", crc); print_Msg(F("CRC: ")); println_Msg(tempCRC); display_Update(); diff --git a/Cart_Reader/FAIRCHILD.ino b/Cart_Reader/FAIRCHILD.ino index 937279c..c51c19d 100644 --- a/Cart_Reader/FAIRCHILD.ino +++ b/Cart_Reader/FAIRCHILD.ino @@ -471,7 +471,7 @@ void readROM_FAIRCHILD() { } myFile.close(); - calcCRC(fileName, cartsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); @@ -526,7 +526,7 @@ void read16K_FAIRCHILD() // Read 16K Bytes } myFile.close(); - calcCRC(fileName, 0x4000, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); diff --git a/Cart_Reader/MSX.ino b/Cart_Reader/MSX.ino index 8ddd128..5fd2b88 100644 --- a/Cart_Reader/MSX.ino +++ b/Cart_Reader/MSX.ino @@ -555,8 +555,7 @@ void readROM_MSX() { } myFile.close(); - unsigned long crcsize = MSX[msxsize] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline @@ -715,8 +714,7 @@ void readRAM_MSX() { } myFile.close(); - unsigned long crcsize = MSX[msxramsize] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 4bbf6e2..dce86ce 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -1002,28 +1002,6 @@ int int_pow(int base, int exp) { // Power for int return result; } -/****************************************** - CRC Functions - *****************************************/ - -void printCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) { - uint32_t crc; - char tempCRC[9]; - FsFile crcFile = sd.open(checkFile); - - crcFile.seek(offset); - crc = calculateCRC(crcFile); - crcFile.close(); - - if (crcCopy != NULL) { - *crcCopy = crc; - } - sprintf(tempCRC, "%08lX", crc); - print_Msg(F("CRC: ")); - println_Msg(tempCRC); - display_Update(); -} - /****************************************** File Functions *****************************************/ diff --git a/Cart_Reader/ODY2.ino b/Cart_Reader/ODY2.ino index cfdd7dc..b50792d 100644 --- a/Cart_Reader/ODY2.ino +++ b/Cart_Reader/ODY2.ino @@ -264,8 +264,7 @@ void readROM_ODY2() { } myFile.close(); - unsigned long crcsize = ODY2[ody2size] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); diff --git a/Cart_Reader/VECTREX.ino b/Cart_Reader/VECTREX.ino index 718d67f..a3a3c21 100644 --- a/Cart_Reader/VECTREX.ino +++ b/Cart_Reader/VECTREX.ino @@ -243,8 +243,7 @@ void readROM_VECTREX() { } myFile.close(); - unsigned long crcsize = VECTREX[vectrexsize] * 0x400; - calcCRC(fileName, crcsize, NULL, 0); + printCRC(fileName, NULL, 0); println_Msg(FS(FSTRING_EMPTY)); // Prints string out of the common strings array either with or without newline