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
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
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
};
// used by MD and NES modules
byte eepbit[8];
byte eeptemp;
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);
}
// 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
@ -1688,7 +1772,7 @@ unsigned char questionBox_LCD(const __FlashStringHelper * question, char answers
#ifdef global_log
println_Msg("");
print_Msg("[+] ");
print_Msg(F("[+] "));
println_Msg(answers[choice]);
#endif

View File

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

View File

@ -945,98 +945,19 @@ void compare_checksums_GB() {
if (strcmp(calcsumStr, checksumStr) == 0) {
print_Msg(F("Internal: "));
print_Msg(calcsumStr);
println_Msg(" -> OK");
println_Msg(F(" -> OK"));
}
else {
print_Msg(F("Internal: "));
println_Msg(calcsumStr);
print_Error(F("Checksum Error"), false);
}
#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
compareCRC("gb.txt");
display_Update();
//go to root
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
*****************************************/

View File

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

View File

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

View File

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

View File

@ -68,7 +68,7 @@ void _smsMenu() {
// Change working dir to root
sd.chdir("/");
readROM_SMS();
compare_checksum_sms();
compareCRC("sms.txt");
#ifdef global_log
save_log();
#endif
@ -593,88 +593,6 @@ 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

View File

@ -63,16 +63,22 @@
// #define clockgen_calibration
// Write all info to OSCR_LOG.txt in root dir
// #define global_log
#define global_log
// Use Adafruit Clock Generator
// #define clockgen_installed
//******************************************
// GB, SMS database options
// GB, SMS, MD database lookup
//******************************************
// 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

7926
sd/md.txt Normal file

File diff suppressed because it is too large Load Diff