From a6e2613379f5c996612a90f8514ad19af5092af7 Mon Sep 17 00:00:00 2001 From: sanni Date: Fri, 18 Jan 2019 14:37:22 +0100 Subject: [PATCH] V2.6 Auto backup current Gameshark ROM --- Cart_Reader/Cart_Reader.ino | 6 ++--- Cart_Reader/N64.ino | 54 ++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 2be07e5..57fba10 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -2,8 +2,8 @@ Cartridge Reader for Arduino Mega2560 Author: sanni - Date: 16-01-2018 - Version: 2.5 + Date: 18-01-2019 + Version: 2.6 SD lib: https://github.com/greiman/SdFat LCD lib: https://github.com/adafruit/Adafruit_SSD1306 @@ -37,7 +37,7 @@ vogelfreiheit - N64 flashram fix **********************************************************************************/ -char ver[5] = "2.5"; +char ver[5] = "2.6"; /****************************************** Define Starting Point diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 603d84e..98d0f2c 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -46,8 +46,8 @@ boolean MN63F81MPN = false; Menu *****************************************/ // N64 start menu -static const char n64MenuItem1[] PROGMEM = "Cart Slot"; -static const char n64MenuItem2[] PROGMEM = "Controller"; +static const char n64MenuItem1[] PROGMEM = "Game Cartridge"; +static const char n64MenuItem2[] PROGMEM = "Controller Pak"; static const char n64MenuItem3[] PROGMEM = "Flash Repro"; static const char n64MenuItem4[] PROGMEM = "Flash Gameshark"; static const char* const menuOptionsN64[] PROGMEM = {n64MenuItem1, n64MenuItem2, n64MenuItem3, n64MenuItem4}; @@ -3042,7 +3042,7 @@ void flashGameshark_N64() { // Check for SST 29LE010 if (strcmp(flashid, "0808") == 0) { - + backupGameshark_N64(); println_Msg(""); println_Msg(F("This will erase your")); println_Msg(F("Gameshark cartridge")); @@ -3153,6 +3153,54 @@ void resetGameshark_N64() { delay(100); } +// Read rom and save to the SD card +void backupGameshark_N64() { + // create a new folder + EEPROM_readAnything(10, foldern); + sprintf(fileName, "GS%d", foldern); + strcat(fileName, ".z64"); + sd.mkdir("N64/ROM/Gameshark", true); + sd.chdir("N64/ROM/Gameshark"); + + display_Clear(); + print_Msg(F("Saving ")); + print_Msg(fileName); + println_Msg(F("...")); + display_Update(); + + // write new folder number back to eeprom + foldern = foldern + 1; + EEPROM_writeAnything(10, foldern); + + // Open file on sd card + if (!myFile.open(fileName, O_RDWR | O_CREAT)) { + print_Error(F("SD Error"), true); + } + + for (unsigned long currByte = romBase + 0xC00000; currByte < (romBase + 0xC00000 + 262144); currByte += 512) { + // Blink led + if (currByte % 16384 == 0) + PORTB ^= (1 << 4); + + // Set the address for the next 512 bytes + setAddress_N64(currByte); + + for (int c = 0; c < 512; c += 2) { + // split word + word myWord = readWord_N64(); + byte loByte = myWord & 0xFF; + byte hiByte = myWord >> 8; + + // write to buffer + sdBuffer[c] = hiByte; + sdBuffer[c + 1] = loByte; + } + myFile.write(sdBuffer, 512); + } + // Close the file: + myFile.close(); +} + // Send chip erase to the two SST29LE010 inside the Gameshark void eraseGameshark_N64() { println_Msg(F("Erasing..."));