Skip to content

Commit

Permalink
remove duplicate CRC printing and calculation function
Browse files Browse the repository at this point in the history
  • Loading branch information
smesgr9000 committed May 1, 2024
1 parent ccc06ef commit 254982c
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 77 deletions.
10 changes: 1 addition & 9 deletions Cart_Reader/2600.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/5200.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/7800.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/ARC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/C64.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 7 additions & 28 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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))

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;
}
#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))

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();
Expand Down
4 changes: 2 additions & 2 deletions Cart_Reader/FAIRCHILD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions Cart_Reader/MSX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions Cart_Reader/NES.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************/
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/ODY2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions Cart_Reader/VECTREX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 254982c

Please sign in to comment.