mirror of
https://github.com/sanni/cartreader.git
synced 2025-01-13 21:49:07 +01:00
remove duplicate CRC printing and calculation function
This commit is contained in:
parent
ccc06ef4e4
commit
254982cbe7
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
*****************************************/
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user