GB Memory: Add SRAM bank switching to MBC5

This commit is contained in:
Jeffrey Pfau 2016-01-28 02:43:40 -08:00
parent a3d0b85d56
commit 32f0bb9f1f
2 changed files with 10 additions and 4 deletions

View File

@ -81,12 +81,13 @@ bool GBLoadROM(struct GB* gb, struct VFile* vf, struct VFile* sav, const char* f
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize); gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
gb->sramVf = sav; gb->sramVf = sav;
if (sav) { if (sav) {
if (sav->size(sav) < 0x8000) { // TODO: Do this in bank-switching code
sav->truncate(sav, 0x8000); if (sav->size(sav) < 0x20000) {
sav->truncate(sav, 0x20000);
} }
gb->memory.sram = sav->map(sav, 0x8000, MAP_WRITE); gb->memory.sram = sav->map(sav, 0x20000, MAP_WRITE);
} else { } else {
gb->memory.sram = anonymousMemoryMap(0x8000); gb->memory.sram = anonymousMemoryMap(0x20000);
} }
return true; return true;
// TODO: error check // TODO: error check

View File

@ -419,6 +419,11 @@ void _GBMBC5(struct GBMemory* memory, uint16_t address, uint8_t value) {
case 0x1: case 0x1:
_switchBank(memory, bank); _switchBank(memory, bank);
break; break;
case 0x2:
if (value < 0x10) {
_switchSramBank(memory, value);
}
break;
default: default:
// TODO // TODO
mLOG(GB_MBC, STUB, "MBC5 unknown address: %04X:%02X", address, value); mLOG(GB_MBC, STUB, "MBC5 unknown address: %04X:%02X", address, value);