diff options
author | sanni <[email protected]> | 2023-02-10 13:16:32 +0100 |
---|---|---|
committer | sanni <[email protected]> | 2023-02-10 13:16:32 +0100 |
commit | 6959c055e62be0797ab2662c92fea933da4fcc29 (patch) | |
tree | 039c733ffede36e0d50a93841edc8599498dcd0a | |
parent | e9d9617ad88d5beb8052707f1a5eaf9e232ce064 (diff) | |
download | cartreader-6959c055e62be0797ab2662c92fea933da4fcc29.tar.gz cartreader-6959c055e62be0797ab2662c92fea933da4fcc29.zip |
Improve stability when dumping N64 with fastcrc option
-rw-r--r-- | Cart_Reader/Cart_Reader.ino | 21 | ||||
-rw-r--r-- | Cart_Reader/N64.ino | 54 |
2 files changed, 52 insertions, 23 deletions
diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index da63a93..22a923d 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -5,7 +5,7 @@ an easy to build and easy to modify cartridge dumper.
Date: 10.02.2023
- Version: 12.2
+ Version: 12.3
SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/olikraus/u8g2
@@ -57,7 +57,7 @@ **********************************************************************************/
-char ver[5] = "12.2";
+char ver[5] = "12.3";
//******************************************
// !!! CHOOSE HARDWARE VERSION !!!
@@ -157,7 +157,7 @@ char ver[5] = "12.2"; #define enable_rotary
// #define rotate_counter_clockwise
#define clockgen_installed
-// #define fastcrc
+#define fastcrc
#define ws_adapter_v2
#endif
@@ -769,20 +769,20 @@ void rewind_line(FsFile& readfile, byte count = 1) { }
// Calculate CRC32 if needed and compare it to CRC read from database
-boolean compareCRC(const char* database, char* crcString, boolean renamerom, int offset) {
+boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, int offset) {
#ifdef nointro
char crcStr[9];
- if (crcString == 0) {
+ print_Msg(F("CRC32... "));
+ display_Update();
+
+ if (crc32sum == 0) {
//go to root
sd.chdir();
// Calculate CRC32
- print_Msg(F("CRC32... "));
- display_Update();
sprintf(crcStr, "%08lX", calculateCRC(fileName, folder, offset));
} else {
- // Use precalculated crc
- print_Msg(F("CRC32... "));
- strcpy(crcStr, crcString);
+ // Convert precalculated crc to string
+ sprintf(crcStr, "%08lX", ~crc32sum);
}
// Print checksum
print_Msg(crcStr);
@@ -804,6 +804,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int //if checksum search successful, rename the file and end search
if (strcmp(crc_search, crcStr) == 0) {
+
#ifdef enable_NES
if ((mode == mode_NES) && (offset != 0)) {
// Rewind to iNES Header
diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 8406bd8..c56bac1 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -239,15 +239,20 @@ void n64CartMenu() { case 0: display_Clear(); sd.chdir("/"); - readRom_N64(); #ifndef fastcrc + // Dumping ROM slow + readRom_N64(); sd.chdir("/"); - // CRC32 compareCRC("n64.txt", 0, 1, 0); +#else + // Dumping ROM fast + compareCRC("n64.txt", readRom_N64(), 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(); @@ -2780,6 +2785,8 @@ void getFramType() { Rom functions *****************************************/ // Read rom and save to the SD card +#ifndef fastcrc +// dumping rom slow void readRom_N64() { // Get name, add extension and convert to char array for sd lib strcpy(fileName, romName); @@ -2807,9 +2814,6 @@ void readRom_N64() { print_FatalError(create_file_STR); } -#ifndef fastcrc - // dumping rom slow - //Initialize progress bar uint32_t processedProgressBar = 0; uint32_t totalProgressBar = (uint32_t)(cartSize)*1024 * 1024; @@ -2835,8 +2839,36 @@ void readRom_N64() { } // Close the file: myFile.close(); +} #else - // dumping rom fast +// dumping rom fast +uint32_t readRom_N64() { + // Get name, add extension and convert to char array for sd lib + strcpy(fileName, romName); + strcat(fileName, ".Z64"); + + // create a new folder + EEPROM_readAnything(0, foldern); + sprintf(folder, "N64/ROM/%s/%d", romName, foldern); + sd.mkdir(folder, true); + sd.chdir(folder); + + // clear the screen + // display_Clear(); + print_STR(saving_to_STR, 0); + print_Msg(folder); + println_Msg(F("/...")); + display_Update(); + + // write new folder number back to eeprom + foldern = foldern + 1; + EEPROM_writeAnything(0, foldern); + + // Open file on sd card + if (!myFile.open(fileName, O_RDWR | O_CREAT)) { + print_FatalError(create_file_STR); + } + byte buffer[1024]; //Initialize progress bar @@ -2917,14 +2949,10 @@ void readRom_N64() { // Close the file: myFile.close(); - // convert checksum to string - char crcStr[9]; - sprintf(crcStr, "%08lX", ~oldcrc32); - - // Search n64.txt for crc - compareCRC("n64.txt", crcStr, 1, 0); -#endif + // Return checksum + return oldcrc32; } +#endif #ifdef savesummarytotxt // Save an info.txt with information on the dumped rom to the SD card |