mirror of
https://github.com/sanni/cartreader.git
synced 2024-12-24 03:51:54 +01:00
Add CRC32 database for SMS
This commit is contained in:
parent
fac6f8eab2
commit
0b70db4241
@ -68,6 +68,7 @@ void _smsMenu() {
|
||||
// Change working dir to root
|
||||
sd.chdir("/");
|
||||
readROM_SMS();
|
||||
compare_checksum_sms();
|
||||
#ifdef global_log
|
||||
save_log();
|
||||
#endif
|
||||
@ -592,6 +593,88 @@ void readROM_SMS() {
|
||||
myFile.close();
|
||||
}
|
||||
|
||||
inline uint32_t updateCRC_SMS(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);
|
||||
}
|
||||
|
||||
// Calculate rom's CRC32 from SD
|
||||
uint32_t crcSMS(char* fileName, char* folder) {
|
||||
if (myFile.open(fileName, O_READ)) {
|
||||
uint32_t oldcrc32 = 0xFFFFFFFF;
|
||||
|
||||
for (unsigned long currByte = 0; currByte < (myFile.fileSize() / 512); currByte++) {
|
||||
myFile.read(sdBuffer, 512);
|
||||
for (int c = 0; c < 512; c++) {
|
||||
oldcrc32 = updateCRC_SMS(sdBuffer[c], oldcrc32);
|
||||
}
|
||||
}
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
return ~oldcrc32;
|
||||
}
|
||||
else {
|
||||
print_Error(F("File not found"), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void compare_checksum_sms() {
|
||||
#ifdef no-intro
|
||||
//CRC32
|
||||
char crcStr[9];
|
||||
sprintf(crcStr, "%08lX", crcSMS(fileName, folder));
|
||||
// Print checksum
|
||||
print_Msg("CRC32: ");
|
||||
print_Msg(crcStr);
|
||||
|
||||
//Search for CRC32 in file
|
||||
char gamename[100];
|
||||
char crc_search[9];
|
||||
|
||||
//go to root
|
||||
sd.chdir();
|
||||
if (myFile.open("sms.txt", O_READ)) {
|
||||
//Search for same CRC in list
|
||||
while (myFile.available()) {
|
||||
//Read 2 lines (game name and CRC)
|
||||
get_line(gamename, &myFile, 96);
|
||||
get_line(crc_search, &myFile, 9);
|
||||
skip_line(&myFile); //Skip every 3rd line
|
||||
|
||||
//if checksum search successful, rename the file and end search
|
||||
if (strcmp(crc_search, crcStr) == 0)
|
||||
{
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
|
||||
print_Msg(" -> ");
|
||||
println_Msg(gamename);
|
||||
|
||||
// Rename file to no-intro
|
||||
sd.chdir(folder);
|
||||
if (myFile.open(fileName, O_READ)) {
|
||||
myFile.rename(gamename);
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (strcmp(crc_search, crcStr) != 0)
|
||||
{
|
||||
println_Msg(" -> Not found");
|
||||
}
|
||||
}
|
||||
else {
|
||||
println_Msg(" -> sms.txt not found");
|
||||
}
|
||||
#else
|
||||
println_Msg("");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Read SRAM and save to the SD card
|
||||
void readSRAM_SMS() {
|
||||
// Get name, add extension and convert to char array for sd lib
|
||||
|
@ -69,7 +69,7 @@
|
||||
// #define clockgen_installed
|
||||
|
||||
//******************************************
|
||||
// GB OPTIONS
|
||||
// GB, SMS database options
|
||||
//******************************************
|
||||
// Renames ROM if found in database (slow)
|
||||
// #define no-intro
|
||||
|
Loading…
Reference in New Issue
Block a user