Fix reading Bahamut Lagoon English Translation SRAM (thx to Cowboyjunkie)

https://github.com/sanni/cartreader/issues/917
This commit is contained in:
sanni 2024-06-30 11:50:11 +02:00
parent fd2c332ea9
commit d1b1c88af0

View File

@ -384,8 +384,8 @@ void snesMenu() {
// Change working dir to root // Change working dir to root
sd.chdir("/"); sd.chdir("/");
readSRAM(); readSRAM();
eraseSRAM(0x00); eraseSRAM(0x0F);
eraseSRAM(0xFF); eraseSRAM(0xF0);
writeSRAM(0); writeSRAM(0);
unsigned long wrErrors = verifySRAM(); unsigned long wrErrors = verifySRAM();
if (wrErrors == 0) { if (wrErrors == 0) {
@ -1655,11 +1655,22 @@ void writeSRAM(boolean browseFile) {
// Writing SRAM on HiRom needs CS(PH3) to be high // Writing SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
// Sram size // Sram size
long lastByte = (long(sramSize) * 128) + 0x6000; 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++) { for (long currByte = 0x6000; currByte < lastByte; currByte++) {
writeBank_SNES(0xB0, currByte, myFile.read()); writeBank_SNES(0xB0, currByte, myFile.read());
} }
} }
}
// SA1 // SA1
else if (romType == SA) { else if (romType == SA) {
long lastByte = (long(sramSize) * 128); long lastByte = (long(sramSize) * 128);
@ -1809,10 +1820,20 @@ void readSRAM() {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
// Sram size // Sram size
long lastByte = (long(sramSize) * 128) + 0x6000; 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++) { for (long currByte = 0x6000; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0xB0, currByte)); myFile.write(readBank_SNES(0xB0, currByte));
} }
}
} else if (romType == SA) { } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
@ -1964,7 +1985,22 @@ unsigned long verifySRAM() {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
// Sram size // Sram size
long lastByte = (long(sramSize) * 128) + 0x6000; 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) { for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
//fill sdBuffer //fill sdBuffer
myFile.read(sdBuffer, 512); myFile.read(sdBuffer, 512);
@ -1974,6 +2010,7 @@ unsigned long verifySRAM() {
} }
} }
} }
}
} else if (romType == SA) { } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
@ -2121,12 +2158,23 @@ boolean eraseSRAM(byte b) {
else if (romType == EX) { else if (romType == EX) {
// Writing SRAM on HiRom needs CS(PH3) to be high // Writing SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
// Sram size /// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000; 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++) { for (long currByte = 0x6000; currByte < lastByte; currByte++) {
writeBank_SNES(0xB0, currByte, b); writeBank_SNES(0xB0, currByte, b);
} }
} }
}
// SA1 // SA1
else if (romType == SA) { else if (romType == SA) {
long lastByte = (long(sramSize) * 128); long lastByte = (long(sramSize) * 128);
@ -2281,7 +2329,20 @@ boolean eraseSRAM(byte b) {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);
// Sram size // Sram size
long lastByte = (long(sramSize) * 128) + 0x6000; 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 (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
for (int c = 0; c < 512; c++) { for (int c = 0; c < 512; c++) {
if ((readBank_SNES(0xB0, currByte + c)) != b) { if ((readBank_SNES(0xB0, currByte + c)) != b) {
@ -2289,6 +2350,7 @@ boolean eraseSRAM(byte b) {
} }
} }
} }
}
} else if (romType == SA) { } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high // Dumping SRAM on HiRom needs CS(PH3) to be high
PORTH |= (1 << 3); PORTH |= (1 << 3);