Skip to content

Commit

Permalink
V7.7: Improve GB Camera dumping (thx to avapug)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni committed Feb 23, 2022
1 parent 2ff3e84 commit c0abeac
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 38 deletions.
30 changes: 17 additions & 13 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,7 +45,7 @@
**********************************************************************************/

char ver[5] = "7.6";
char ver[5] = "7.7";

/******************************************
Libraries
Expand Down Expand Up @@ -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();
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1307,7 +1307,9 @@ void wait_btn() {
if (b == 3) {
if (errorLvl) {
// Debug
//ignoreError = 1;
#ifdef debug_mode
ignoreError = 1;
#endif
errorLvl = 0;
}
break;
Expand Down Expand Up @@ -1649,7 +1651,9 @@ void wait_btn() {
if (b == 3) {
if (errorLvl) {
// Debug
//ignoreError = 1;
#ifdef debug_mode
ignoreError = 1;
#endif
errorLvl = 0;
}
break;
Expand Down
106 changes: 81 additions & 25 deletions Cart_Reader/GB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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();
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -797,7 +805,7 @@ void readSRAM_GB() {
dataIn_GB();

// MBC2 Fix
readByte_GB(0x0134);
readByteCLK_GB(0x0134);

dataOut();
if (romType <= 4) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -854,7 +862,7 @@ void writeSRAM_GB() {
dataIn_GB();

// MBC2 Fix
readByte_GB(0x0134);
readByteCLK_GB(0x0134);

dataOut();

Expand All @@ -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
Expand Down Expand Up @@ -909,7 +917,7 @@ unsigned long verifySRAM_GB() {
dataIn_GB();

// MBC2 Fix
readByte_GB(0x0134);
readByteCLK_GB(0x0134);

// Check SRAM size
if (lastByte > 0) {
Expand All @@ -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++;
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Cart_Reader/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0abeac

Please sign in to comment.