Add CRC32 and filenames to SNES database

This commit is contained in:
sanni 2022-06-21 13:29:19 +02:00
parent 311822f3c7
commit 44d853e1bb
6 changed files with 46 additions and 31 deletions

View File

@ -4,7 +4,7 @@
This project represents a community-driven effort to provide This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper. an easy to build and easy to modify cartridge dumper.
Date: 20.06.2022 Date: 21.06.2022
Version: 8.5 BETA Version: 8.5 BETA
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat
@ -370,6 +370,9 @@ inline uint32_t updateCRC(uint8_t ch, uint32_t crc) {
// Calculate rom's CRC32 from SD // Calculate rom's CRC32 from SD
uint32_t calculateCRC(char* fileName, char* folder) { uint32_t calculateCRC(char* fileName, char* folder) {
// Open folder
sd.chdir(folder);
// Open file
if (myFile.open(fileName, O_READ)) { if (myFile.open(fileName, O_READ)) {
uint32_t oldcrc32 = 0xFFFFFFFF; uint32_t oldcrc32 = 0xFFFFFFFF;
@ -384,7 +387,12 @@ uint32_t calculateCRC(char* fileName, char* folder) {
return ~oldcrc32; return ~oldcrc32;
} }
else { else {
print_Error(F("File not found"), true); display_Clear();
print_Msg(F("File "));
//print_Msg(folder);
//print_Msg(F("/"));
//print_Msg(fileName);
print_Error(F(" not found"), true);
} }
} }
@ -444,7 +452,11 @@ boolean compareCRC(char* database, char* crcString) {
#ifdef no-intro #ifdef no-intro
char crcStr[9]; char crcStr[9];
if (crcString == 0) { if (crcString == 0) {
//go to root
sd.chdir();
// Calculate CRC32 // Calculate CRC32
print_Msg(F("CRC32... "));
display_Update();
sprintf(crcStr, "%08lX", calculateCRC(fileName, folder)); sprintf(crcStr, "%08lX", calculateCRC(fileName, folder));
} }
else { else {
@ -452,7 +464,6 @@ boolean compareCRC(char* database, char* crcString) {
strcpy(crcStr, crcString); strcpy(crcStr, crcString);
} }
// Print checksum // Print checksum
print_Msg(F("CRC32: "));
print_Msg(crcStr); print_Msg(crcStr);
display_Update(); display_Update();

View File

@ -925,9 +925,6 @@ unsigned int calc_checksum_GB (char* fileName, char* folder) {
// Compare checksum // Compare checksum
void compare_checksums_GB() { void compare_checksums_GB() {
println_Msg(F("Calculating Checksum..."));
display_Update();
strcpy(fileName, romName); strcpy(fileName, romName);
strcat(fileName, ".GB"); strcat(fileName, ".GB");

View File

@ -130,8 +130,6 @@ void gbaMenu() {
// Internal Checksum // Internal Checksum
compare_checksum_GBA(); compare_checksum_GBA();
// CRC32 // CRC32
println_Msg(F("Calculating CRC checksum..."));
display_Update();
compareCRC("gba.txt", 0); compareCRC("gba.txt", 0);
#ifdef global_log #ifdef global_log
save_log(); save_log();
@ -501,7 +499,7 @@ void setup_GBA() {
// Get cart info // Get cart info
display_Clear(); display_Clear();
println_Msg(F("Seaching database...")); println_Msg(F("Searching database..."));
display_Update(); display_Update();
getCartInfo_GBA(); getCartInfo_GBA();
display_Clear(); display_Clear();

View File

@ -1293,9 +1293,6 @@ void readROM_MD() {
//println_Msg(F("s")); //println_Msg(F("s"));
//display_Update(); //display_Update();
println_Msg(F("Calculating checksum..."));
display_Update();
// Calculate and compare CRC32 with no-intro // Calculate and compare CRC32 with no-intro
compareCRC("md.txt", 0); compareCRC("md.txt", 0);

View File

@ -3434,9 +3434,6 @@ redumpsamefolder:
// Close the file: // Close the file:
myFile.close(); myFile.close();
// Calculate Checksum and convert to string
println_Msg(F("Calculating CRC.."));
display_Update();
if (compareCRC("n64.txt", 0)) { if (compareCRC("n64.txt", 0)) {
#else #else
// dumping rom fast // dumping rom fast

View File

@ -215,12 +215,10 @@ void snesMenu() {
unsigned long startTime = millis(); unsigned long startTime = millis();
// start reading from cart // start reading from cart
readROM_SNES(); readROM_SNES();
// Internal Checksum
compare_checksum(); compare_checksum();
// CRC32
// print elapsed time compareCRC("snes.txt", 0);
print_Msg(F("Time elapsed: "));
print_Msg((millis() - startTime) / 1000);
println_Msg(F("s"));
#ifdef global_log #ifdef global_log
save_log(); save_log();
#endif #endif
@ -337,7 +335,7 @@ void snesMenu() {
resetArduino(); resetArduino();
break; break;
} }
println_Msg(F("")); //println_Msg(F(""));
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
wait(); wait();
@ -818,7 +816,18 @@ void checkAltConf() {
altconf = 0; altconf = 0;
if (myFile.open("snes.txt", O_READ)) { if (myFile.open("snes.txt", O_READ)) {
// Get cart info
display_Clear();
println_Msg(F("Searching database..."));
display_Update();
while (myFile.available()) { while (myFile.available()) {
// Skip first line with name
skip_line(&myFile);
// Skip over the CRC checksum
myFile.seekSet(myFile.curPosition() + 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(tempStr1, "%c", myFile.read()); sprintf(tempStr1, "%c", myFile.read());
strcpy(tempStr2, tempStr1); strcpy(tempStr2, tempStr1);
@ -836,24 +845,31 @@ void checkAltConf() {
myFile.seekSet(myFile.curPosition() + 1); myFile.seekSet(myFile.curPosition() + 1);
// Read file size // Read file size
romSize = (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.seekSet(myFile.curPosition() + 1);
// Read number of banks // Read number of banks
numBanks = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48); byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48);
altconf = 1; if ((romSize != romSize2) || (numBanks != numBanks2)) {
romSize = romSize2;
numBanks = numBanks2;
altconf = 1;
}
} }
// If no match empty string advance by 9 and try again // If no match empty string advance by 9 and try again
else { else {
myFile.seekSet(myFile.curPosition() + 9); // skip rest of line
myFile.seekSet(myFile.curPosition() + 7);
// skip third empty line
skip_line(&myFile);
} }
} }
// Close the file:
myFile.close();
} }
// Close the file:
myFile.close();
} }
// Read header // Read header
@ -1163,8 +1179,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
} }
boolean compare_checksum() { boolean compare_checksum() {
print_Msg(F("Internal Checksum..."));
println_Msg(F("Calculating Checksum"));
display_Update(); display_Update();
strcpy(fileName, romName); strcpy(fileName, romName);
@ -1178,8 +1193,8 @@ boolean compare_checksum() {
sprintf(calcsumStr, "%04X", calc_checksum(fileName, folder)); sprintf(calcsumStr, "%04X", calc_checksum(fileName, folder));
if (strcmp(calcsumStr, checksumStr) == 0) { if (strcmp(calcsumStr, checksumStr) == 0) {
print_Msg(F("Checksum OK: ")); println_Msg(F("OK"));
println_Msg(calcsumStr); //println_Msg(calcsumStr);
display_Update(); display_Update();
return 1; return 1;
} }