mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-11 07:25:07 +01:00
V29B: Added warning when dumping GB Memory flash
Still have the bank switching error when writing, problem is located at line 2159. I can't switch the bank any time before since I need an uneven bank for the 0x5555 command and I can't switch afterwards or it will be too late and everything will be written to bank 1...
This commit is contained in:
parent
79346e3a51
commit
43ec1a423b
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Author: sanni
|
Author: sanni
|
||||||
Date: 2017-10-11
|
Date: 2017-10-11
|
||||||
Version: V29A
|
Version: V29B
|
||||||
|
|
||||||
SD lib: https://github.com/greiman/SdFat
|
SD lib: https://github.com/greiman/SdFat
|
||||||
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
||||||
@ -34,7 +34,7 @@
|
|||||||
YamaArashi - GBA flashrom bank switch command
|
YamaArashi - GBA flashrom bank switch command
|
||||||
|
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
char ver[5] = "V29A";
|
char ver[5] = "V29B";
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
Define Output
|
Define Output
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//******************************************
|
//******************************************
|
||||||
// NINTENDO POWER Cartridges for SFC and GB
|
// NINTENDO POWER Cartridges for SFC and GB
|
||||||
// (GB Memory starts at around line 1430)
|
// (GB Memory starts at around line 1460)
|
||||||
//******************************************
|
//******************************************
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
@ -1494,10 +1494,24 @@ void gbmMenu() {
|
|||||||
case 1:
|
case 1:
|
||||||
// Clear screen
|
// Clear screen
|
||||||
display_Clear();
|
display_Clear();
|
||||||
|
// Print warning
|
||||||
|
println_Msg(F("Attention"));
|
||||||
|
println_Msg(F("Always power cycle"));
|
||||||
|
println_Msg(F("cartreader directly"));
|
||||||
|
println_Msg(F("before reading"));
|
||||||
|
println_Msg("");
|
||||||
|
println_Msg(F("Press Button"));
|
||||||
|
println_Msg(F("to continue"));
|
||||||
|
display_Update();
|
||||||
|
wait();
|
||||||
|
// Clear screen
|
||||||
|
display_Clear();
|
||||||
|
|
||||||
// Reset to root directory
|
// Reset to root directory
|
||||||
sd.chdir("/");
|
sd.chdir("/");
|
||||||
|
|
||||||
// Read flash
|
// Enable access to ports 0120h
|
||||||
|
send_GBM(0x09);
|
||||||
// Map entire flashrom
|
// Map entire flashrom
|
||||||
send_GBM(0x04);
|
send_GBM(0x04);
|
||||||
// Disable ports 0x0120...
|
// Disable ports 0x0120...
|
||||||
@ -1506,7 +1520,6 @@ void gbmMenu() {
|
|||||||
readROM_GBM(64);
|
readROM_GBM(64);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// Erase Flash
|
// Erase Flash
|
||||||
case 2:
|
case 2:
|
||||||
// Clear screen
|
// Clear screen
|
||||||
@ -2070,7 +2083,7 @@ void writeFlash_GBM() {
|
|||||||
print_Error(F("File is too big."), true);
|
print_Error(F("File is too big."), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//enable access to ports 0120h
|
// Enable access to ports 0120h
|
||||||
send_GBM(0x09);
|
send_GBM(0x09);
|
||||||
// Enable write
|
// Enable write
|
||||||
send_GBM(0x0A);
|
send_GBM(0x0A);
|
||||||
@ -2082,7 +2095,7 @@ void writeFlash_GBM() {
|
|||||||
// Set bank for unprotect later on, writes to 0x5555 need odd bank number
|
// Set bank for unprotect later on, writes to 0x5555 need odd bank number
|
||||||
writeByte_GBM(0x2100, 0x1);
|
writeByte_GBM(0x2100, 0x1);
|
||||||
|
|
||||||
// disable ports 0x2100 and 0x120 or else addresses will not be writable
|
// Disable ports 0x2100 and 0x120 or else addresses will not be writable
|
||||||
send_GBM(0x10);
|
send_GBM(0x10);
|
||||||
send_GBM(0x08);
|
send_GBM(0x08);
|
||||||
|
|
||||||
@ -2097,45 +2110,68 @@ void writeFlash_GBM() {
|
|||||||
// Check if flashrom is ready for writing or busy
|
// Check if flashrom is ready for writing or busy
|
||||||
while ((readByte_GBM(0) & 0x80) != 0x80) {}
|
while ((readByte_GBM(0) & 0x80) != 0x80) {}
|
||||||
|
|
||||||
// first bank: 0x0000-0x7FFF,
|
// Blink led
|
||||||
word currAddress = 0x0;
|
PORTB ^= (1 << 4);
|
||||||
|
|
||||||
// only write the first bank for now as bank switching doesn't work yet
|
// Write first bank
|
||||||
for (word currBank = 0x1; currBank < 0x2; currBank++) {
|
for (word currAddress = 0x0; currAddress < 0x7FFF; currAddress += 128) {
|
||||||
// Blink Led
|
// Fill SD buffer
|
||||||
|
myFile.read(sdBuffer, 128);
|
||||||
|
|
||||||
|
// Write flash buffer command
|
||||||
|
writeByte_GBM(0x5555, 0xAA);
|
||||||
|
writeByte_GBM(0x2AAA, 0x55);
|
||||||
|
writeByte_GBM(0x5555, 0xA0);
|
||||||
|
|
||||||
|
// Fill flash buffer
|
||||||
|
for (word currByte = 0; currByte < 128; currByte++) {
|
||||||
|
writeByte_GBM(currAddress + currByte, sdBuffer[currByte]);
|
||||||
|
}
|
||||||
|
// Execute write
|
||||||
|
writeByte_GBM(currAddress + 127, 0xFF);
|
||||||
|
|
||||||
|
// Wait for write to complete
|
||||||
|
while ((readByte_GBM(0) & 0x80) != 0x80) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable access to ports 0120h
|
||||||
|
send_GBM(0x09);
|
||||||
|
// Enable access to ports 2100h
|
||||||
|
send_GBM(0x11);
|
||||||
|
|
||||||
|
// Write rest of the banks
|
||||||
|
for (byte currBank = 2; currBank < (fileSize / 0x4000); currBank++) {
|
||||||
|
// Blink led
|
||||||
PORTB ^= (1 << 4);
|
PORTB ^= (1 << 4);
|
||||||
|
|
||||||
// all following banks: 0x4000-0x7FFF
|
// Write single bank in 128 byte steps
|
||||||
if (currBank > 1) {
|
for (word currAddress = 0x4000; currAddress < 0x7FFF; currAddress += 128) {
|
||||||
currAddress = 0x4000;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write one bank
|
|
||||||
for (; currAddress < 0x7FFF; currAddress += 128) {
|
|
||||||
// Fill SD buffer
|
// Fill SD buffer
|
||||||
myFile.read(sdBuffer, 128);
|
myFile.read(sdBuffer, 128);
|
||||||
|
|
||||||
// Write flash buffer command
|
// Write flash buffer command
|
||||||
writeByte_GBM(0x5555, 0xAA);
|
writeByte_GBM(0x2100, 0x1);
|
||||||
writeByte_GBM(0x2AAA, 0x55);
|
send_GBM(0x0F, 0x5555, 0xAA);
|
||||||
writeByte_GBM(0x5555, 0xA0);
|
send_GBM(0x0F, 0x2AAA, 0x55);
|
||||||
|
send_GBM(0x0F, 0x5555, 0xA0);
|
||||||
|
|
||||||
|
// Setting bank here does not work and aborts the write
|
||||||
|
writeByte_GBM(0x2100, currBank);
|
||||||
|
|
||||||
// Fill flash buffer
|
// Fill flash buffer
|
||||||
for (word currByte = 0; currByte < 128; currByte++) {
|
for (word currByte = 0; currByte < 128; currByte++) {
|
||||||
writeByte_GBM(currAddress + currByte, sdBuffer[currByte]);
|
send_GBM(0x0F, currAddress + currByte, sdBuffer[currByte]);
|
||||||
}
|
}
|
||||||
// Execute write
|
// Execute write
|
||||||
writeByte_GBM(currAddress + 127, 0xFF);
|
send_GBM(0x0F, currAddress + 127, 0xFF);
|
||||||
|
|
||||||
// Wait for write to complete
|
// Wait for write to complete
|
||||||
|
writeByte_GBM(0x2100, 0x1);
|
||||||
while ((readByte_GBM(0) & 0x80) != 0x80) {}
|
while ((readByte_GBM(0) & 0x80) != 0x80) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Close the file:
|
// Close the file:
|
||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
// Reset flashrom
|
|
||||||
resetFlash_GBM();
|
|
||||||
println_Msg(F("Done"));
|
println_Msg(F("Done"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user