GB: Fix maximum cartridge size with MBC5
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Feb 2016 11:38:36 -0800
3 files changed,
16 insertions(+),
8 deletions(-)
M
src/gb/gb.c
→
src/gb/gb.c
@@ -114,7 +114,7 @@ if (gb->memory.rom && gb->pristineRom != gb->memory.rom) {
if (gb->yankedRomSize) { gb->yankedRomSize = 0; } - mappedMemoryFree(gb->memory.rom, 0x400000); + mappedMemoryFree(gb->memory.rom, GB_SIZE_CART_MAX); } gb->memory.rom = 0;@@ -140,10 +140,10 @@ size_t patchedSize = patch->outputSize(patch, gb->memory.romSize);
if (!patchedSize) { return; } - if (patchedSize > 0x400000) { - patchedSize = 0x400000; + if (patchedSize > GB_SIZE_CART_MAX) { + patchedSize = GB_SIZE_CART_MAX; } - gb->memory.rom = anonymousMemoryMap(0x400000); + gb->memory.rom = anonymousMemoryMap(GB_SIZE_CART_MAX); if (!patch->applyPatch(patch, gb->pristineRom, gb->pristineRomSize, gb->memory.rom, patchedSize)) { mappedMemoryFree(gb->memory.rom, patchedSize); gb->memory.rom = gb->pristineRom;
M
src/gb/memory.c
→
src/gb/memory.c
@@ -514,9 +514,10 @@ }
} void _GBMBC5(struct GBMemory* memory, uint16_t address, uint8_t value) { - int bank = value; - switch (address >> 13) { + int bank; + switch (address >> 12) { case 0x0: + case 0x1: switch (value) { case 0: memory->sramAccess = false;@@ -531,10 +532,16 @@ mLOG(GB_MBC, STUB, "MBC5 unknown value %02X", value);
break; } break; - case 0x1: + case 0x2: + bank = (memory->currentBank & 0x100) | value; _switchBank(memory, bank); break; - case 0x2: + case 0x3: + bank = (memory->currentBank & 0xFF) | ((value & 1) << 8); + _switchBank(memory, bank); + break; + case 0x4: + case 0x5: if (memory->mbcType == GB_MBC5_RUMBLE) { memory->rumble->setRumble(memory->rumble, (value >> 3) & 1); value &= ~8;
M
src/gb/memory.h
→
src/gb/memory.h
@@ -44,6 +44,7 @@ };
enum { GB_SIZE_CART_BANK0 = 0x4000, + GB_SIZE_CART_MAX = 0x800000, GB_SIZE_VRAM = 0x4000, GB_SIZE_VRAM_BANK0 = 0x2000, GB_SIZE_EXTERNAL_RAM = 0x2000,