From e4246d8310cc16db84f2c4dcb457873bf28c0140 Mon Sep 17 00:00:00 2001 From: sanni Date: Wed, 17 Aug 2022 22:53:07 +0200 Subject: [PATCH] Fix N64 Controller Pak read/write --- Cart_Reader/Cart_Reader.ino | 6 ++-- Cart_Reader/N64.ino | 56 +++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 857c099..100ab0d 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -4,8 +4,8 @@ This project represents a community-driven effort to provide an easy to build and easy to modify cartridge dumper. - Date: 06.08.2022 - Version: 9.4 + Date: 17.08.2022 + Version: 9.5 SD lib: https://github.com/greiman/SdFat OLED lib: https://github.com/adafruit/Adafruit_SSD1306 @@ -60,7 +60,7 @@ **********************************************************************************/ -char ver[5] = "9.4"; +char ver[5] = "9.5"; //****************************************** // !!! CHOOSE HARDWARE VERSION !!! diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index f4c3a2f..441b19e 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2004,34 +2004,54 @@ void readMPK() { print_Error(F("Can't open file on SD"), true); } - println_Msg(F("Please wait...")); + print_Msg(F("Saving N64/MPK/")); + println_Msg(fileName); display_Update(); + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = (uint32_t)(0x7FFF); + draw_progressbar(0, totalProgressBar); + // Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF for (word i = 0x0000; i < 0x8000; i += 32) { // Read one block of the Controller Pak into array myBlock readBlock(i); + + // Delay to prevent write errors + delay(1); + // Write block to SD card for (byte j = 0; j < 32; j++) { myFile.write(myBlock[j]); } + + // Blink led + blinkLED(); + // Update progress bar + processedProgressBar += 32; + draw_progressbar(processedProgressBar, totalProgressBar); } // Close the file: myFile.close(); - print_Msg(F("Saved as N64/MPK/")); - println_Msg(fileName); - display_Update(); } void writeMPK() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Writing...")); - println_Msg(filePath); + print_Msg(F("Writing ")); + print_Msg(filePath); + println_Msg(F("...")); display_Update(); // Open file on sd card if (myFile.open(filePath, O_READ)) { + + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = (uint32_t)(0x7FFF); + draw_progressbar(0, totalProgressBar); + for (word myAddress = 0x0000; myAddress < 0x8000; myAddress += 32) { // Read 32 bytes into SD buffer myFile.read(sdBuffer, 32); @@ -2058,11 +2078,17 @@ void writeMPK() { N64_stop(); // Enable interrupts interrupts(); + + // Blink led + blinkLED(); + // Update progress bar + processedProgressBar += 32; + draw_progressbar(processedProgressBar, totalProgressBar); + // Delay to prevent write errors + delay(1); } // Close the file: myFile.close(); - println_Msg(F("Done")); - display_Update(); } else { print_Error(F("Can't create file on SD"), true); @@ -2081,17 +2107,31 @@ void verifyMPK() { print_Error(F("Can't create file on SD"), true); } + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = (uint32_t)(0x7FFF); + draw_progressbar(0, totalProgressBar); + // Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF for (word i = 0x0000; i < 0x8000; i += 32) { // Read one block of the Controller Pak into array myBlock readBlock(i); + // Delay to prevent read errors + delay(1); // Check against file on SD card for (byte j = 0; j < 32; j++) { if (myFile.read() != myBlock[j]) { writeErrors++; } } + + // Blink led + blinkLED(); + // Update progress bar + processedProgressBar += 32; + draw_progressbar(processedProgressBar, totalProgressBar); } + // Close the file: myFile.close(); if (writeErrors == 0) {