Fix SRAM overflow in N64/MD, turn LED red if CRC not found

This commit is contained in:
sanni 2023-02-10 09:40:58 +01:00
parent 03935a3af0
commit 2f71d0572e
3 changed files with 36 additions and 97 deletions

View File

@ -4,7 +4,7 @@
This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper.
Date: 06.02.2023
Date: 10.02.2023
Version: 12.2
SD lib: https://github.com/greiman/SdFat
@ -863,12 +863,12 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int
}
}
if (strcmp(crc_search, crcStr) != 0) {
println_Msg(F(" -> Not found"));
print_Error(F(" -> Not found"));
return 0;
}
} else {
println_Msg(F(" -> Error"));
println_Msg(F("Database missing"));
print_Error(F("Database missing"));
return 0;
}
#else // nointro

View File

@ -306,6 +306,12 @@ void mdCartMenu() {
readRealtec_MD();
} else {
readROM_MD();
// Calculate and compare CRC32 with nointro
if (is32x)
//database, crcString, renamerom, offset
compareCRC("32x.txt", 0, 1, 0);
else
compareCRC("md.txt", 0, 1, 0);
}
} else {
print_Error(F("Cart has no ROM"));
@ -1476,13 +1482,6 @@ void readROM_MD() {
display_Update();
}
}
// Calculate and compare CRC32 with nointro
if (is32x)
//database, crcString, renamerom, offset
compareCRC("32x.txt", 0, 1, 0);
else
compareCRC("md.txt", 0, 1, 0);
}
/******************************************

View File

@ -237,8 +237,21 @@ void n64CartMenu() {
// wait for user choice to come back from the question box menu
switch (mainMenu) {
case 0:
display_Clear();
sd.chdir("/");
readRom_N64();
#ifndef fastcrc
sd.chdir("/");
// CRC32
compareCRC("n64.txt", 0, 1, 0);
#endif
#ifdef global_log
save_log();
#endif
// Prints string out of the common strings array either with or without newline
print_STR(press_button_STR, 1);
display_Update();
wait();
break;
case 1:
@ -2772,14 +2785,14 @@ void readRom_N64() {
strcpy(fileName, romName);
strcat(fileName, ".Z64");
redumpnewfolder:
// create a new folder
EEPROM_readAnything(0, foldern);
sprintf(folder, "N64/ROM/%s/%d", romName, foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
display_Clear();
// clear the screen
// display_Clear();
print_STR(saving_to_STR, 0);
print_Msg(folder);
println_Msg(F("/..."));
@ -2789,17 +2802,19 @@ redumpnewfolder:
foldern = foldern + 1;
EEPROM_writeAnything(0, foldern);
redumpsamefolder:
// Open file on sd card
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
print_FatalError(sd_error_STR);
print_FatalError(create_file_STR);
}
// get current time
unsigned long startTime = millis();
#ifndef fastcrc
// dumping rom slow
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)(cartSize)*1024 * 1024;
draw_progressbar(0, totalProgressBar);
for (unsigned long currByte = romBase; currByte < (romBase + (cartSize * 1024 * 1024)); currByte += 512) {
// Blink led
if ((currByte & 0x3FFF) == 0)
@ -2808,17 +2823,18 @@ redumpsamefolder:
// Set the address for the next 512 bytes
setAddress_N64(currByte);
for (word c = 0; c < sizeof(sdBuffer); c += 2) {
for (word c = 0; c < 512; c += 2) {
word myWord = readWord_N64();
sdBuffer[c] = myWord >> 8;
sdBuffer[c + 1] = myWord & 0xFF;
}
myFile.write(sdBuffer, sizeof(sdBuffer));
myFile.write(sdBuffer, 512);
processedProgressBar += 512;
draw_progressbar(processedProgressBar, totalProgressBar);
}
// Close the file:
myFile.close();
if (compareCRC("n64.txt", 0, 1, 0)) {
#else
// dumping rom fast
byte buffer[1024];
@ -2906,84 +2922,8 @@ redumpsamefolder:
sprintf(crcStr, "%08lX", ~oldcrc32);
// Search n64.txt for crc
if (compareCRC("n64.txt", crcStr, 1, 0)) {
compareCRC("n64.txt", crcStr, 1, 0);
#endif
unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
print_Msg(F("Done ("));
print_Msg(timeElapsed); // include elapsed time
println_Msg(F("s)"));
println_Msg(F(""));
// Prints string out of the common strings array either with or without newline
print_STR(press_button_STR, 1);
display_Update();
// This saves a tt file with rom info next to the dumped rom
#ifdef savesummarytotxt
savesummary_N64(1, crcStr, timeElapsed);
#endif
#ifdef global_log
save_log();
#endif
wait();
} else {
// Dump was bad or unknown
errorLvl = 1;
setColor_RGB(255, 0, 0);
println_Msg(F(""));
// Prints string out of the common strings array either with or without newline
print_STR(press_button_STR, 1);
display_Update();
// This saves a tt file with rom info next to the dumped rom
#ifdef savesummarytotxt
savesummary_N64(0, crcStr, timeElapsed);
#endif
wait();
// N64 CRC32 error Menu
unsigned char CRCMenu;
// Copy menuOptions out of progmem
convertPgm(menuOptionsN64CRC, 4);
CRCMenu = question_box(F("Redump cartridge?"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
switch (CRCMenu) {
case 0:
// Return to N64 menu
display_Clear();
break;
case 1:
// Dump again into new folder
display_Clear();
setColor_RGB(0, 0, 0);
goto redumpnewfolder;
break;
case 2:
// Dump again into same folder
// Change to last directory
sd.chdir(folder);
// Delete old file
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
print_FatalError(sd_error_STR);
}
if (!myFile.remove()) {
print_FatalError(F("Delete Error"));
}
// Dump again
display_Clear();
println_Msg(F("Reading Rom..."));
display_Update();
setColor_RGB(0, 0, 0);
goto redumpsamefolder;
break;
case 3:
// Reset
resetArduino();
break;
}
}
}
#ifdef savesummarytotxt