GB Memory: Add SRAM bank switching to MBC5
Jeffrey Pfau jeffrey@endrift.com
Thu, 28 Jan 2016 02:43:40 -0800
2 files changed,
10 insertions(+),
4 deletions(-)
M
src/gb/gb.c
→
src/gb/gb.c
@@ -81,12 +81,13 @@ gb->memory.romSize = gb->pristineRomSize;
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize); gb->sramVf = sav; if (sav) { - if (sav->size(sav) < 0x8000) { - sav->truncate(sav, 0x8000); + // TODO: Do this in bank-switching code + 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 { - gb->memory.sram = anonymousMemoryMap(0x8000); + gb->memory.sram = anonymousMemoryMap(0x20000); } return true; // TODO: error check
M
src/gb/memory.c
→
src/gb/memory.c
@@ -419,6 +419,11 @@ break;
case 0x1: _switchBank(memory, bank); break; + case 0x2: + if (value < 0x10) { + _switchSramBank(memory, value); + } + break; default: // TODO mLOG(GB_MBC, STUB, "MBC5 unknown address: %04X:%02X", address, value);