aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorsanni <[email protected]>2024-06-30 11:50:11 +0200
committersanni <[email protected]>2024-06-30 11:50:11 +0200
commitd1b1c88af0b3cf2995b7a8ccde052d58ec7793c9 (patch)
tree38c7229d0fe094200cad9516946216cc36ae3543
parentfd2c332ea9a2249795786766d216199b5b4f235e (diff)
downloadcartreader-d1b1c88af0b3cf2995b7a8ccde052d58ec7793c9.tar.gz
cartreader-d1b1c88af0b3cf2995b7a8ccde052d58ec7793c9.zip
Fix reading Bahamut Lagoon English Translation SRAM (thx to Cowboyjunkie)
https://github.com/sanni/cartreader/issues/917
-rw-r--r--Cart_Reader/SNES.ino110
1 files changed, 86 insertions, 24 deletions
diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino
index 9782039..58ffbe3 100644
--- a/Cart_Reader/SNES.ino
+++ b/Cart_Reader/SNES.ino
@@ -384,8 +384,8 @@ void snesMenu() {
// Change working dir to root
sd.chdir("/");
readSRAM();
- eraseSRAM(0x00);
- eraseSRAM(0xFF);
+ eraseSRAM(0x0F);
+ eraseSRAM(0xF0);
writeSRAM(0);
unsigned long wrErrors = verifySRAM();
if (wrErrors == 0) {
@@ -1655,9 +1655,20 @@ void writeSRAM(boolean browseFile) {
// Writing SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3);
// Sram size
- long lastByte = (long(sramSize) * 128) + 0x6000;
- for (long currByte = 0x6000; currByte < lastByte; currByte++) {
- writeBank_SNES(0xB0, currByte, myFile.read());
+ long lastByte = (long(sramSize) * 128);
+ if (lastByte > 0x2000) { // Large EX SRAM Fix
+ sramBanks = lastByte / 0x2000;
+ for (int currBank = 0xB0; currBank < sramBanks + 0xB0; currBank++) {
+ for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
+ writeBank_SNES(currBank, currByte, myFile.read());
+ }
+ }
+ } else {
+ lastByte += 0x6000;
+ // Write to sram bank
+ for (long currByte = 0x6000; currByte < lastByte; currByte++) {
+ writeBank_SNES(0xB0, currByte, myFile.read());
+ }
}
}
// SA1
@@ -1809,9 +1820,19 @@ void readSRAM() {
// Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3);
// Sram size
- long lastByte = (long(sramSize) * 128) + 0x6000;
- for (long currByte = 0x6000; currByte < lastByte; currByte++) {
- myFile.write(readBank_SNES(0xB0, currByte));
+ long lastByte = (long(sramSize) * 128);
+ if (lastByte > 0x2000) { // Large EX SRAM Fix
+ sramBanks = lastByte / 0x2000;
+ for (int currBank = 0xB0; currBank < sramBanks + 0xB0; currBank++) {
+ for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
+ myFile.write(readBank_SNES(currBank, currByte));
+ }
+ }
+ } else {
+ lastByte += 0x6000;
+ for (long currByte = 0x6000; currByte < lastByte; currByte++) {
+ myFile.write(readBank_SNES(0xB0, currByte));
+ }
}
} else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
@@ -1964,13 +1985,29 @@ unsigned long verifySRAM() {
// Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3);
// Sram size
- long lastByte = (long(sramSize) * 128) + 0x6000;
- for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
- //fill sdBuffer
- myFile.read(sdBuffer, 512);
- for (int c = 0; c < 512; c++) {
- if ((readBank_SNES(0xB0, currByte + c)) != sdBuffer[c]) {
- writeErrors++;
+ long lastByte = (long(sramSize) * 128);
+ if (lastByte > 0x2000) { // Large EX SRAM Fix
+ sramBanks = lastByte / 0x2000;
+ for (int currBank = 0xB0; currBank < sramBanks + 0xB0; currBank++) {
+ for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
+ //fill sdBuffer
+ myFile.read(sdBuffer, 512);
+ for (int c = 0; c < 512; c++) {
+ if ((readBank_SNES(currBank, currByte + c)) != sdBuffer[c]) {
+ writeErrors++;
+ }
+ }
+ }
+ }
+ } else {
+ lastByte += 0x6000;
+ for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
+ //fill sdBuffer
+ myFile.read(sdBuffer, 512);
+ for (int c = 0; c < 512; c++) {
+ if ((readBank_SNES(0xB0, currByte + c)) != sdBuffer[c]) {
+ writeErrors++;
+ }
}
}
}
@@ -2121,10 +2158,21 @@ boolean eraseSRAM(byte b) {
else if (romType == EX) {
// Writing SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3);
- // Sram size
- long lastByte = (long(sramSize) * 128) + 0x6000;
- for (long currByte = 0x6000; currByte < lastByte; currByte++) {
- writeBank_SNES(0xB0, currByte, b);
+ /// Sram size
+ long lastByte = (long(sramSize) * 128);
+ if (lastByte > 0x2000) { // Large EX SRAM Fix
+ sramBanks = lastByte / 0x2000;
+ for (int currBank = 0xB0; currBank < sramBanks + 0xB0; currBank++) {
+ for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
+ writeBank_SNES(currBank, currByte, b);
+ }
+ }
+ } else {
+ lastByte += 0x6000;
+ // Write to sram bank
+ for (long currByte = 0x6000; currByte < lastByte; currByte++) {
+ writeBank_SNES(0xB0, currByte, b);
+ }
}
}
// SA1
@@ -2281,11 +2329,25 @@ boolean eraseSRAM(byte b) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3);
// Sram size
- long lastByte = (long(sramSize) * 128) + 0x6000;
- for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
- for (int c = 0; c < 512; c++) {
- if ((readBank_SNES(0xB0, currByte + c)) != b) {
- writeErrors++;
+ long lastByte = (long(sramSize) * 128);
+ if (lastByte > 0x2000) { // Large EX SRAM Fix
+ sramBanks = lastByte / 0x2000;
+ for (int currBank = 0xB0; currBank < sramBanks + 0xB0; currBank++) {
+ for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
+ for (int c = 0; c < 512; c++) {
+ if ((readBank_SNES(currBank, currByte + c)) != b) {
+ writeErrors++;
+ }
+ }
+ }
+ }
+ } else {
+ lastByte += 0x6000;
+ for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
+ for (int c = 0; c < 512; c++) {
+ if ((readBank_SNES(0xB0, currByte + c)) != b) {
+ writeErrors++;
+ }
}
}
}