Add MD database

This commit is contained in:
sanni 2022-06-16 17:17:16 +02:00
parent 0b70db4241
commit 8b96d250bd
13 changed files with 9312 additions and 1484 deletions

View File

@ -308,8 +308,12 @@ void(*resetArduino) (void) = 0;
// Progressbar // Progressbar
void draw_progressbar(uint32_t processedsize, uint32_t totalsize); void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
// used by MD and NES modules
byte eepbit[8];
byte eeptemp;
//****************************************** //******************************************
// Data used by multiple modules // CRC32
//****************************************** //******************************************
// CRC32 lookup table // 256 entries // CRC32 lookup table // 256 entries
static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */ static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */
@ -358,9 +362,89 @@ static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
}; };
// used by MD and NES modules inline uint32_t updateCRC(uint8_t ch, uint32_t crc) {
byte eepbit[8]; uint32_t idx = ((crc) ^ (ch)) & 0xff;
byte eeptemp; uint32_t tab_value = pgm_read_dword(crc_32_tab + idx);
return tab_value ^ ((crc) >> 8);
}
// Calculate rom's CRC32 from SD
uint32_t calculateCRC(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(sdBuffer[c], oldcrc32);
}
}
// Close the file:
myFile.close();
return ~oldcrc32;
}
else {
print_Error(F("File not found"), true);
}
}
//******************************************
// no-intro database
//******************************************
void compareCRC(char* database) {
#ifdef no-intro
// Calculate CRC32
char crcStr[9];
sprintf(crcStr, "%08lX", calculateCRC(fileName, folder));
// Print checksum
print_Msg(F("CRC32: "));
print_Msg(crcStr);
//Search for CRC32 in file
char gamename[100];
char crc_search[9];
//go to root
sd.chdir();
if (myFile.open(database, 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(F(" -> "));
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(F(" -> Not found"));
}
}
else {
println_Msg(F(" -> database file not found"));
}
#else
println_Msg("");
#endif
}
/****************************************** /******************************************
Main menu optimized for rotary encoder Main menu optimized for rotary encoder
@ -1688,7 +1772,7 @@ unsigned char questionBox_LCD(const __FlashStringHelper * question, char answers
#ifdef global_log #ifdef global_log
println_Msg(""); println_Msg("");
print_Msg("[+] "); print_Msg(F("[+] "));
println_Msg(answers[choice]); println_Msg(answers[choice]);
#endif #endif

View File

@ -323,7 +323,7 @@ void flashromMenu16() {
if (time != 0) { if (time != 0) {
print_Msg(F("Operation took: ")); print_Msg(F("Operation took: "));
print_Msg((millis() - time) / 1000, DEC); print_Msg((millis() - time) / 1000, DEC);
println_Msg("s"); println_Msg(F("s"));
display_Update(); display_Update();
} }
wait(); wait();
@ -390,7 +390,7 @@ void epromMenu() {
if (time != 0) { if (time != 0) {
print_Msg(F("Operation took: ")); print_Msg(F("Operation took: "));
print_Msg((millis() - time) / 1000, DEC); print_Msg((millis() - time) / 1000, DEC);
println_Msg("s"); println_Msg(F("s"));
display_Update(); display_Update();
} }
wait(); wait();
@ -408,8 +408,8 @@ idtheflash:
display_Clear(); display_Clear();
display_Update(); display_Update();
println_Msg(F("Flashrom Writer 8bit")); println_Msg(F("Flashrom Writer 8bit"));
println_Msg(" "); println_Msg("");
println_Msg(" "); println_Msg("");
print_Msg(F("Flash ID: ")); print_Msg(F("Flash ID: "));
println_Msg(flashid); println_Msg(flashid);
@ -578,14 +578,14 @@ idtheflash:
// ID not found // ID not found
display_Clear(); display_Clear();
println_Msg(F("Flashrom Writer 8bit")); println_Msg(F("Flashrom Writer 8bit"));
println_Msg(" "); println_Msg("");
print_Msg(F("ID Type 1: ")); print_Msg(F("ID Type 1: "));
println_Msg(vendorID); println_Msg(vendorID);
print_Msg(F("ID Type 2: ")); print_Msg(F("ID Type 2: "));
println_Msg(flashid); println_Msg(flashid);
println_Msg(" "); println_Msg("");
println_Msg(F("UNKNOWN FLASHROM")); println_Msg(F("UNKNOWN FLASHROM"));
println_Msg(" "); println_Msg("");
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
wait(); wait();
@ -600,7 +600,7 @@ idtheflash:
resetFlash8(); resetFlash8();
print_Error(F("Press Button to reset"), true); print_Error(F("Press Button to reset"), true);
} }
println_Msg(" "); println_Msg("");
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
@ -613,12 +613,12 @@ void id_Flash16() {
resetFlash16(); resetFlash16();
println_Msg(F("Flashrom Writer 16bit")); println_Msg(F("Flashrom Writer 16bit"));
println_Msg(" "); println_Msg("");
print_Msg(F("Flash ID: ")); print_Msg(F("Flash ID: "));
println_Msg(flashid); println_Msg(flashid);
if (strcmp(flashid, "C2F1") == 0) { if (strcmp(flashid, "C2F1") == 0) {
println_Msg(F("MX29F1610 detected")); println_Msg(F("MX29F1610 detected"));
println_Msg(" "); println_Msg("");
flashSize = 2097152; flashSize = 2097152;
flashromType = 2; flashromType = 2;
} }
@ -659,9 +659,9 @@ void id_Flash16() {
} }
else { else {
print_Error(F("Unknown flashrom"), true); print_Error(F("Unknown flashrom"), true);
println_Msg(" "); println_Msg("");
} }
println_Msg(" "); println_Msg("");
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
} }
@ -1785,7 +1785,7 @@ void printFlash(int numBytes) {
for (int c = 0; c < 10; c++) { for (int c = 0; c < 10; c++) {
itoa (readByte_Flash(currByte + c), myBuffer, 16); itoa (readByte_Flash(currByte + c), myBuffer, 16);
for (int i = 0; i < 2 - strlen(myBuffer); i++) { for (int i = 0; i < 2 - strlen(myBuffer); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(myBuffer); print_Msg(myBuffer);
@ -2130,14 +2130,14 @@ void printFlash16(int numBytes) {
sprintf (buf, "%x", left_byte); sprintf (buf, "%x", left_byte);
for (int i = 0; i < 2 - strlen(buf); i++) { for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(buf); print_Msg(buf);
sprintf (buf, "%x", right_byte); sprintf (buf, "%x", right_byte);
for (int i = 0; i < 2 - strlen(buf); i++) { for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(buf); print_Msg(buf);
@ -2521,14 +2521,14 @@ void print_Eprom(int numBytes) {
sprintf (buf, "%x", left_byte); sprintf (buf, "%x", left_byte);
for (int i = 0; i < 2 - strlen(buf); i++) { for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(buf); print_Msg(buf);
sprintf (buf, "%x", right_byte); sprintf (buf, "%x", right_byte);
for (int i = 0; i < 2 - strlen(buf); i++) { for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(buf); print_Msg(buf);

View File

@ -945,98 +945,19 @@ void compare_checksums_GB() {
if (strcmp(calcsumStr, checksumStr) == 0) { if (strcmp(calcsumStr, checksumStr) == 0) {
print_Msg(F("Internal: ")); print_Msg(F("Internal: "));
print_Msg(calcsumStr); print_Msg(calcsumStr);
println_Msg(" -> OK"); println_Msg(F(" -> OK"));
} }
else { else {
print_Msg(F("Internal: ")); print_Msg(F("Internal: "));
println_Msg(calcsumStr); println_Msg(calcsumStr);
print_Error(F("Checksum Error"), false); print_Error(F("Checksum Error"), false);
} }
compareCRC("gb.txt");
#ifdef no-intro
//CRC32
char crcStr[9];
sprintf(crcStr, "%08lX", crcGB(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("gb.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(" -> gb.txt not found");
}
#else
println_Msg("");
#endif
display_Update(); display_Update();
//go to root //go to root
sd.chdir(); sd.chdir();
} }
inline uint32_t updateCRC_GB(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 crcGB(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_GB(sdBuffer[c], oldcrc32);
}
}
// Close the file:
myFile.close();
return ~oldcrc32;
}
else {
print_Error(F("File not found"), true);
}
}
/****************************************** /******************************************
SRAM functions SRAM functions
*****************************************/ *****************************************/

View File

@ -112,8 +112,9 @@ static char labelLockon[17];
/****************************************** /******************************************
Configuration Configuration
*****************************************/ *****************************************/
#ifdef use_md_conf
void mdLoadConf() { void mdLoadConf() {
if (myFile.open("md.txt", O_READ)) { if (myFile.open("mdconf.txt", O_READ)) {
char line[64]; char line[64];
int n; int n;
int i; int i;
@ -183,6 +184,7 @@ void mdLoadConf() {
myFile.close(); myFile.close();
} }
} }
#endif
/****************************************** /******************************************
Menu Menu
@ -306,18 +308,19 @@ void mdCartMenu() {
if (cartSize != 0 && cartSize <= 16777216) { if (cartSize != 0 && cartSize <= 16777216) {
// Change working dir to root // Change working dir to root
sd.chdir("/"); sd.chdir("/");
if (realtec) if (realtec) {
readRealtec_MD(); readRealtec_MD();
else }
else {
readROM_MD(); readROM_MD();
//compare_checksum_MD(); }
#ifdef global_log
save_log();
#endif
} }
else { else {
print_Error(F("Cart has no ROM"), false); print_Error(F("Cart has no ROM"), false);
} }
#ifdef global_log
save_log();
#endif
break; break;
case 1: case 1:
@ -460,7 +463,9 @@ void segaCDMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_MD() { void setup_MD() {
#ifdef use_md_conf
mdLoadConf(); mdLoadConf();
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7
@ -1284,18 +1289,21 @@ void readROM_MD() {
} }
// print elapsed time // print elapsed time
print_Msg(F("Time elapsed: ")); //print_Msg(F("Time elapsed: "));
print_Msg((millis() - startTime) / 1000); //print_Msg((millis() - startTime) / 1000);
println_Msg(F("s")); //println_Msg(F("s"));
display_Update(); //display_Update();
// Calculate and compare CRC32 with no-intro
compareCRC("md.txt");
// print Checksum // print Checksum
if (chksum == calcCKS) { if (chksum == calcCKS) {
println_Msg(F("Checksum OK")); println_Msg(F("Internal checksum OK"));
display_Update(); display_Update();
} }
else { else {
print_Msg(F("Checksum Error: ")); print_Msg(F("Internal checksum Error: "));
char calcsumStr[5]; char calcsumStr[5];
sprintf(calcsumStr, "%04X", calcCKS); sprintf(calcsumStr, "%04X", calcCKS);
println_Msg(calcsumStr); println_Msg(calcsumStr);

View File

@ -2223,35 +2223,6 @@ int strcicmp(char const * a, char const * b)
} }
} }
#ifndef fastcrc
// Calculate dumped rom's CRC32
inline uint32_t updateCRC64(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 crc64() {
if (myFile.open(fileName, O_READ)) {
uint32_t oldcrc32 = 0xFFFFFFFF;
for (unsigned long currByte = 0; currByte < cartSize * 2048; currByte++) {
myFile.read(sdBuffer, 512);
for (int c = 0; c < 512; c++) {
oldcrc32 = updateCRC64(sdBuffer[c], oldcrc32);
}
}
// Close the file:
myFile.close();
return ~oldcrc32;
}
else {
print_Error(F("File not found"), true);
}
}
#endif
// look-up the calculated crc in the file n64.txt on sd card // look-up the calculated crc in the file n64.txt on sd card
boolean searchCRC(char crcStr[9]) { boolean searchCRC(char crcStr[9]) {
boolean result = 0; boolean result = 0;
@ -3117,7 +3088,7 @@ void writeFram(byte flashramType) {
display_Update(); display_Update();
} }
else { else {
println_Msg("FAIL"); println_Msg(F("FAIL"));
display_Update(); display_Update();
} }
@ -3457,7 +3428,7 @@ redumpsamefolder:
println_Msg(F("Calculating CRC..")); println_Msg(F("Calculating CRC.."));
display_Update(); display_Update();
char crcStr[9]; char crcStr[9];
sprintf(crcStr, "%08lx", crc64()); sprintf(crcStr, "%08lx", calculateCRC(fileName, folder));
// Print checksum // Print checksum
println_Msg(crcStr); println_Msg(crcStr);
display_Update(); display_Update();

View File

@ -640,12 +640,6 @@ int int_pow(int base, int exp) { // Power for int
FsFile crcFile; FsFile crcFile;
char tempCRC[9]; char tempCRC[9];
inline uint32_t updateCRC32(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);
}
uint32_t crc32(FsFile & file, uint32_t &charcnt) { uint32_t crc32(FsFile & file, uint32_t &charcnt) {
uint32_t oldcrc32 = 0xFFFFFFFF; uint32_t oldcrc32 = 0xFFFFFFFF;
charcnt = 0; charcnt = 0;
@ -654,7 +648,7 @@ uint32_t crc32(FsFile & file, uint32_t &charcnt) {
for (int x = 0; x < 512; x++) { for (int x = 0; x < 512; x++) {
uint8_t c = sdBuffer[x]; uint8_t c = sdBuffer[x];
charcnt++; charcnt++;
oldcrc32 = updateCRC32(c, oldcrc32); oldcrc32 = updateCRC(c, oldcrc32);
} }
} }
return ~oldcrc32; return ~oldcrc32;
@ -668,7 +662,7 @@ uint32_t crc32EEP(FsFile & file, uint32_t &charcnt) {
for (int x = 0; x < 128; x++) { for (int x = 0; x < 128; x++) {
uint8_t c = sdBuffer[x]; uint8_t c = sdBuffer[x];
charcnt++; charcnt++;
oldcrc32 = updateCRC32(c, oldcrc32); oldcrc32 = updateCRC(c, oldcrc32);
} }
} }
return ~oldcrc32; return ~oldcrc32;
@ -902,7 +896,7 @@ unsigned char* getNESHeaderForFileInfo(uint32_t prg_size, uint32_t chr_size, uin
unsigned char* nes20_header; unsigned char* nes20_header;
int i; int i;
if (!sdFile.open("/nes20db.txt", FILE_READ)) { if (!sdFile.open("/nes.txt", FILE_READ)) {
return NULL; return NULL;
} else { } else {
display_Clear(); display_Clear();
@ -1190,7 +1184,7 @@ chooseMapper:
for (byte digit = 0; digit < 3; digit++) { for (byte digit = 0; digit < 3; digit++) {
while (1) { while (1) {
display_Clear(); display_Clear();
println_Msg("Select Mapper:"); println_Msg(F("Select Mapper:"));
display.setCursor(23, 20); display.setCursor(23, 20);
println_Msg(hundreds); println_Msg(hundreds);
display.setCursor(43, 20); display.setCursor(43, 20);

View File

@ -1309,7 +1309,7 @@ void printMapping() {
for (int c = 0; c < 10; c++) { for (int c = 0; c < 10; c++) {
itoa (readBank_SFM(0xC0, currByte + c), buffer, 16); itoa (readBank_SFM(0xC0, currByte + c), buffer, 16);
for (int i = 0; i < 2 - strlen(buffer); i++) { for (int i = 0; i < 2 - strlen(buffer); i++) {
print_Msg("0"); print_Msg(F("0"));
} }
// Now print the significant bits // Now print the significant bits
print_Msg(buffer); print_Msg(buffer);

View File

@ -496,7 +496,7 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
//Open list file. If no list file found, just skip //Open list file. If no list file found, just skip
sd.chdir("/"); //Set read directry to root sd.chdir("/"); //Set read directry to root
if (script.open("PCE_CRC_LIST.txt", O_READ)) if (script.open("pce.txt", O_READ))
{ {
//Calculate CRC of ROM file //Calculate CRC of ROM file
sd.chdir(folder_p); sd.chdir(folder_p);

View File

@ -68,7 +68,7 @@ void _smsMenu() {
// Change working dir to root // Change working dir to root
sd.chdir("/"); sd.chdir("/");
readROM_SMS(); readROM_SMS();
compare_checksum_sms(); compareCRC("sms.txt");
#ifdef global_log #ifdef global_log
save_log(); save_log();
#endif #endif
@ -593,88 +593,6 @@ void readROM_SMS() {
myFile.close(); 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 // Read SRAM and save to the SD card
void readSRAM_SMS() { void readSRAM_SMS() {
// Get name, add extension and convert to char array for sd lib // Get name, add extension and convert to char array for sd lib

View File

@ -63,16 +63,22 @@
// #define clockgen_calibration // #define clockgen_calibration
// Write all info to OSCR_LOG.txt in root dir // Write all info to OSCR_LOG.txt in root dir
// #define global_log #define global_log
// Use Adafruit Clock Generator // Use Adafruit Clock Generator
// #define clockgen_installed // #define clockgen_installed
//****************************************** //******************************************
// GB, SMS database options // GB, SMS, MD database lookup
//****************************************** //******************************************
// Renames ROM if found in database (slow) // Renames ROM if found in database (slow)
// #define no-intro #define no-intro
//******************************************
// MD OPTIONS
//******************************************
// I don't know
//#define use_md_conf
//****************************************** //******************************************
// N64 OPTIONS // N64 OPTIONS

7926
sd/md.txt Normal file

File diff suppressed because it is too large Load Diff