Update SNES database to 20220812

This commit is contained in:
sanni 2022-08-22 17:49:19 +02:00
parent 3b7d6bd4fc
commit 2a409bd848
3 changed files with 60 additions and 27 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: 21.08.2022 Date: 22.08.2022
Version: 9.6 Version: 9.6
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat

View File

@ -762,6 +762,20 @@ boolean checkcart_SFM() {
// set control to read // set control to read
dataIn(); dataIn();
// Read ROM header
byte snesHeader[80] = { 0 };
for (byte c = 0; c < 80; c++) {
snesHeader[c] = readBank_SFM(0, 0xFFB0 + c);
}
// Calculate CRC32 of header
uint32_t oldcrc32 = 0xFFFFFFFF;
for (int c = 0; c < 80; c++) {
oldcrc32 = updateCRC(snesHeader[c], oldcrc32);
}
char crcStr[9];
sprintf(crcStr, "%08lX", ~oldcrc32);
// Get Checksum as string // Get Checksum as string
sprintf(checksumStr, "%02X%02X", readBank_SFM(0, 65503), readBank_SFM(0, 65502)); sprintf(checksumStr, "%02X%02X", readBank_SFM(0, 65503), readBank_SFM(0, 65502));
@ -781,8 +795,10 @@ boolean checkcart_SFM() {
numBanks = (long(romSize) * 1024 * 1024 / 8) / (32768 + (long(romType) * 32768)); numBanks = (long(romSize) * 1024 * 1024 / 8) / (32768 + (long(romType) * 32768));
//Check SD card for alt config //Check SD card for alt config, pass CRC32 of snesHeader but filter out 0000 and FFFF checksums
checkAltConf(); if (!(strcmp(checksumStr, "0000") == 0) && !(strcmp(checksumStr, "FFFF") == 0)) {
checkAltConf(crcStr);
}
// Get name // Get name
byte myByte = 0; byte myByte = 0;

View File

@ -806,9 +806,9 @@ void getCartInfo_SNES() {
} }
} }
void checkAltConf() { void checkAltConf(char crcStr[9]) {
char tempStr1[2];
char tempStr2[5]; char tempStr2[5];
char tempStr3[9];
altconf = 0; altconf = 0;
if (myFile.open("snes.txt", O_READ)) { if (myFile.open("snes.txt", O_READ)) {
@ -824,24 +824,29 @@ void checkAltConf() {
// Skip over the CRC checksum // Skip over the CRC checksum
myFile.seekSet(myFile.curPosition() + 9); myFile.seekSet(myFile.curPosition() + 9);
// Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up // Get internal ROM checksum as string
sprintf(tempStr1, "%c", myFile.read()); for (byte j = 0; j < 4; j++) {
strcpy(tempStr2, tempStr1); tempStr2[j] = char(myFile.read());
sprintf(tempStr1, "%c", myFile.read()); }
strcat(tempStr2, tempStr1); tempStr2[4] = '\0';
sprintf(tempStr1, "%c", myFile.read());
strcat(tempStr2, tempStr1);
sprintf(tempStr1, "%c", myFile.read());
strcat(tempStr2, tempStr1);
// Check if string is a match // Check if checksum string is a match else go to next entry in database
if (strcmp(tempStr2, checksumStr) == 0) { if (strcmp(tempStr2, checksumStr) == 0) {
println_Msg(F("Found")); println_Msg(F("Found in database"));
display_Update(); display_Update();
// Skip the , in the file // Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1); myFile.seekSet(myFile.curPosition() + 1);
// Read the CRC32 of the SNES header out of database
for (byte k = 0; k < 8; k++) {
tempStr3[k] = char(myFile.read());
}
tempStr3[8] = '\0';
// Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1);
// Read file size // Read file size
byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48); byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48);
@ -851,22 +856,24 @@ void checkAltConf() {
// Read number of banks // Read number of banks
byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48); byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48);
if ((romSize != romSize2) || (numBanks != numBanks2)) { // Some games have the same checksum, so compare CRC32 of header area with database too
// Only correct if non-standard size found in database, else trust header info to be correct if (strcmp(tempStr3, crcStr) == 0) {
if ((romSize2 == 6) || (romSize2 == 7) || (romSize2 == 10) || (romSize2 == 12) || (romSize2 == 16) || (romSize2 == 24)) { // Game found, check if ROM sizes differ but only change ROM size if non- standard size found in database, else trust the header to be right and the database to be wrong
if (((romSize != romSize2) || (numBanks != numBanks2)) && ((romSize2 == 10) || (romSize2 == 12) || (romSize2 == 20) || (romSize2 == 24))) {
// Correct size
romSize = romSize2; romSize = romSize2;
numBanks = numBanks2; numBanks = numBanks2;
altconf = 1; altconf = 1;
println_Msg(F("Correcting size")); println_Msg(F("Correcting size"));
display_Update(); display_Update();
} }
break;
} }
break;
} }
// If no match empty string advance by 9 and try again // If no match go to next entry
else { else {
// skip rest of line // skip rest of line
myFile.seekSet(myFile.curPosition() + 9); myFile.seekSet(myFile.curPosition() + 18);
// skip third empty line // skip third empty line
skip_line(&myFile); skip_line(&myFile);
} }
@ -882,11 +889,11 @@ boolean checkcart_SNES() {
dataIn(); dataIn();
uint16_t c = 0; uint16_t c = 0;
uint16_t headerStart = 0xFFC0; uint16_t headerStart = 0xFFB0;
uint16_t currByte = headerStart; uint16_t currByte = headerStart;
byte snesHeader[64] = { 0 }; byte snesHeader[80] = { 0 };
PORTL = 0; PORTL = 0;
while (c < 64) { while (c < 80) {
PORTF = (currByte & 0xFF); PORTF = (currByte & 0xFF);
PORTK = ((currByte >> 8) & 0xFF); PORTK = ((currByte >> 8) & 0xFF);
@ -897,6 +904,14 @@ boolean checkcart_SNES() {
currByte++; currByte++;
} }
// Calculate CRC32 of header
uint32_t oldcrc32 = 0xFFFFFFFF;
for (int c = 0; c < 80; c++) {
oldcrc32 = updateCRC(snesHeader[c], oldcrc32);
}
char crcStr[9];
sprintf(crcStr, "%08lX", ~oldcrc32);
// Get Checksum as string // Get Checksum as string
sprintf(checksumStr, "%02X%02X", snesHeader[0xFFDF - headerStart], snesHeader[0xFFDE - headerStart]); sprintf(checksumStr, "%02X%02X", snesHeader[0xFFDF - headerStart], snesHeader[0xFFDE - headerStart]);
@ -959,8 +974,10 @@ boolean checkcart_SNES() {
} }
} }
//Check SD card for alt config //Check SD card for alt config, pass CRC32 of snesHeader but filter out 0000 and FFFF checksums
checkAltConf(); if (!(strcmp(checksumStr, "0000") == 0) && !(strcmp(checksumStr, "FFFF") == 0)) {
checkAltConf(crcStr);
}
// Get name // Get name
byte myByte = 0; byte myByte = 0;