From c0abeac385a891e41b39af65b021eb5cd8072499 Mon Sep 17 00:00:00 2001 From: sanni Date: Wed, 23 Feb 2022 15:08:25 +0100 Subject: [PATCH] V7.7: Improve GB Camera dumping (thx to avapug) --- Cart_Reader/Cart_Reader.ino | 30 +++++----- Cart_Reader/GB.ino | 106 +++++++++++++++++++++++++++--------- Cart_Reader/options.h | 3 + 3 files changed, 101 insertions(+), 38 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index db3ef2e..f3e552d 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: 15.02.2022 - Version: 7.6 + Date: 23.02.2022 + Version: 7.7 SD lib: https://github.com/greiman/SdFat OLED lib: https://github.com/adafruit/Adafruit_SSD1306 @@ -45,7 +45,7 @@ **********************************************************************************/ -char ver[5] = "7.6"; +char ver[5] = "7.7"; /****************************************** Libraries @@ -813,7 +813,6 @@ void print_Error(const __FlashStringHelper *errorMessage, boolean forceReset) { display_Update(); if (forceReset) { -#if (defined(enable_OLED) || defined(enable_LCD)) println_Msg(F("")); println_Msg(F("Press Button...")); display_Update(); @@ -825,17 +824,11 @@ void print_Error(const __FlashStringHelper *errorMessage, boolean forceReset) { ignoreError = 0; display_Clear(); println_Msg(F("")); + println_Msg(F("Error Overwrite")); println_Msg(F("")); - println_Msg(F("")); - println_Msg(F(" Error Overwrite")); display_Update(); delay(2000); } -#endif -#ifdef enable_serial - println_Msg(F("Fatal Error, please reset")); - while (1); -#endif } } @@ -1049,6 +1042,13 @@ unsigned char question_box(const __FlashStringHelper* question, char answers[7][ *****************************************/ #ifdef enable_serial void wait_serial() { + if (errorLvl) { + // Debug +#ifdef debug_mode + ignoreError = 1; +#endif + errorLvl = 0; + } while (Serial.available() == 0) { } incomingByte = Serial.read() - 48; @@ -1307,7 +1307,9 @@ void wait_btn() { if (b == 3) { if (errorLvl) { // Debug - //ignoreError = 1; +#ifdef debug_mode + ignoreError = 1; +#endif errorLvl = 0; } break; @@ -1649,7 +1651,9 @@ void wait_btn() { if (b == 3) { if (errorLvl) { // Debug - //ignoreError = 1; +#ifdef debug_mode + ignoreError = 1; +#endif errorLvl = 0; } break; diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index f239533..f03c029 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -494,7 +494,7 @@ void writeByte_GB(int myAddress, byte myData) { __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); } -byte readByteSRAM_GB(word myAddress) { +byte readByteCLK_GB(word myAddress) { PORTF = myAddress & 0xFF; PORTK = (myAddress >> 8) & 0xFF; @@ -510,17 +510,17 @@ byte readByteSRAM_GB(word myAddress) { // Read byte tempByte = PINC; - // Pull CS(PH3) CLK(PH1)(for FRAM MOD) HIGH - PORTH |= (1 << 3) | (1 << 1); // Pull RD(PH6) HIGH PORTH |= (1 << 6); + // Pull CS(PH3) CLK(PH1)(for FRAM MOD) HIGH + PORTH |= (1 << 3) | (1 << 1); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); return tempByte; } -void writeByteSRAM_GB(int myAddress, byte myData) { +void writeByteCLK_GB(int myAddress, byte myData) { PORTF = myAddress & 0xFF; PORTK = (myAddress >> 8) & 0xFF; PORTC = myData; @@ -549,12 +549,12 @@ void writeByteSRAM_GB(int myAddress, byte myData) { *****************************************/ // Read Cartridge Header void getCartInfo_GB() { - romType = readByte_GB(0x0147); - romSize = readByte_GB(0x0148); - sramSize = readByte_GB(0x0149); + romType = readByteCLK_GB(0x0147); + romSize = readByteCLK_GB(0x0148); + sramSize = readByteCLK_GB(0x0149); // ROM banks - switch (romSize){ + switch (romSize) { case 0x00: romBanks = 2; break; @@ -617,14 +617,14 @@ void getCartInfo_GB() { } // Get Checksum as string - sprintf(checksumStr, "%02X%02X", readByte_GB(0x014E), readByte_GB(0x014F)); + sprintf(checksumStr, "%02X%02X", readByteCLK_GB(0x014E), readByteCLK_GB(0x014F)); // Get name byte myByte = 0; byte myLength = 0; for (int addr = 0x0134; addr <= 0x13C; addr++) { - myByte = readByte_GB(addr); + myByte = readByteCLK_GB(addr); if (((char(myByte) >= 48 && char(myByte) <= 57) || (char(myByte) >= 65 && char(myByte) <= 122)) && myLength < 15) { romName[myLength] = char(myByte); myLength++; @@ -664,6 +664,11 @@ void readROM_GB() { word romAddress = 0; + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = (uint32_t)(romBanks - 1); + draw_progressbar(0, totalProgressBar); + for (word currBank = 1; currBank < romBanks; currBank++) { // Switch data pins to output dataOut(); @@ -690,11 +695,14 @@ void readROM_GB() { // Read banks and save to SD while (romAddress <= 0x7FFF) { for (int i = 0; i < 512; i++) { - sdBuffer[i] = readByte_GB(romAddress + i); + sdBuffer[i] = readByteCLK_GB(romAddress + i); } myFile.write(sdBuffer, 512); romAddress += 512; } + + processedProgressBar += 1; + draw_progressbar(processedProgressBar, totalProgressBar); } // Close the file: @@ -723,8 +731,8 @@ unsigned int calc_checksum_GB (char* fileName, char* folder) { myFile.close(); sd.chdir(); // Subtract checksum bytes - calcChecksum -= readByte_GB(0x014E); - calcChecksum -= readByte_GB(0x014F); + calcChecksum -= readByteCLK_GB(0x014E); + calcChecksum -= readByteCLK_GB(0x014F); // Return result return (calcChecksum); @@ -797,7 +805,7 @@ void readSRAM_GB() { dataIn_GB(); // MBC2 Fix - readByte_GB(0x0134); + readByteCLK_GB(0x0134); dataOut(); if (romType <= 4) { @@ -816,7 +824,7 @@ void readSRAM_GB() { dataIn_GB(); for (word sramAddress = 0xA000; sramAddress <= lastByte; sramAddress += 64) { for (byte i = 0; i < 64; i++) { - sdBuffer[i] = readByteSRAM_GB(sramAddress + i); + sdBuffer[i] = readByteCLK_GB(sramAddress + i); } myFile.write(sdBuffer, 64); } @@ -854,7 +862,7 @@ void writeSRAM_GB() { dataIn_GB(); // MBC2 Fix - readByte_GB(0x0134); + readByteCLK_GB(0x0134); dataOut(); @@ -872,7 +880,7 @@ void writeSRAM_GB() { // Write RAM for (word sramAddress = 0xA000; sramAddress <= lastByte; sramAddress++) { - writeByteSRAM_GB(sramAddress, myFile.read()); + writeByteCLK_GB(sramAddress, myFile.read()); } } // Disable SRAM @@ -909,7 +917,7 @@ unsigned long verifySRAM_GB() { dataIn_GB(); // MBC2 Fix - readByte_GB(0x0134); + readByteCLK_GB(0x0134); // Check SRAM size if (lastByte > 0) { @@ -932,7 +940,7 @@ unsigned long verifySRAM_GB() { //fill sdBuffer myFile.read(sdBuffer, 64); for (int c = 0; c < 64; c++) { - if (readByteSRAM_GB(sramAddress + c) != sdBuffer[c]) { + if (readByteCLK_GB(sramAddress + c) != sdBuffer[c]) { writeErrors++; } } @@ -978,9 +986,33 @@ void writeFlash29F_GB(byte MBC) { myFile.seekSet(0); // ROM banks - romBanks = 2; // Default 32K - if (romSize >= 1) { // Calculate rom size - romBanks = 2 << romSize; + switch (romSize) { + case 0x00: + romBanks = 2; + break; + case 0x01: + romBanks = 4; + break; + case 0x02: + romBanks = 8; + break; + case 0x03: + romBanks = 16; + break; + case 0x04: + romBanks = 32; + break; + case 0x05: + romBanks = 64; + break; + case 0x06: + romBanks = 128; + break; + case 0x07: + romBanks = 256; + break; + default: + romBanks = 2; } // Set data pins to output @@ -1409,9 +1441,33 @@ bool writeCFI_GB() { myFile.seekSet(0); // ROM banks - romBanks = 2; // Default 32K - if (romSize >= 1) { // Calculate rom size - romBanks = 2 << romSize; + switch (romSize) { + case 0x00: + romBanks = 2; + break; + case 0x01: + romBanks = 4; + break; + case 0x02: + romBanks = 8; + break; + case 0x03: + romBanks = 16; + break; + case 0x04: + romBanks = 32; + break; + case 0x05: + romBanks = 64; + break; + case 0x06: + romBanks = 128; + break; + case 0x07: + romBanks = 256; + break; + default: + romBanks = 2; } if (romBanks <= flashBanks) { diff --git a/Cart_Reader/options.h b/Cart_Reader/options.h index 6f68f43..decb646 100644 --- a/Cart_Reader/options.h +++ b/Cart_Reader/options.h @@ -46,6 +46,9 @@ // flashMenu, nesMenu or smsMenu for single slot Cart Readers #define startMenu mainMenu +//Ignores errors that normally force a reset if button 2 is pressed +//#define debug_mode + // Setup RTC if installed. // remove // if you have an RTC installed // #define RTC_installed