GB Memory: Fix patching bank 0
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Oct 2016 11:49:06 -0700
3 files changed,
9 insertions(+),
5 deletions(-)
M
CHANGES
→
CHANGES
@@ -18,6 +18,7 @@ - GBA Cheats: Fix GameShark ROM patches
- Qt: Fix cut off tiles and alignment issues in tile viewer - GB MBC: Fix initializing MBC when no ROM is loaded - VFS: Fix resizing memory chunks when not needed + - GB Memory: Fix patching ROM bank 0 Misc: - SDL: Remove scancode key input - GBA Video: Clean up unused timers
M
src/gb/gb.c
→
src/gb/gb.c
@@ -243,15 +243,15 @@ }
void GBUnloadROM(struct GB* gb) { // TODO: Share with GBAUnloadROM + if (gb->memory.rom && gb->memory.romBase != gb->memory.rom && gb->memory.romBase != gb->pristineRom) { + free(gb->memory.romBase); + } if (gb->memory.rom && gb->pristineRom != gb->memory.rom) { if (gb->yankedRomSize) { gb->yankedRomSize = 0; } mappedMemoryFree(gb->memory.rom, GB_SIZE_CART_MAX); gb->memory.rom = gb->pristineRom; - } - if (gb->memory.rom && gb->memory.romBase != gb->memory.rom) { - free(gb->memory.romBase); } gb->memory.rom = 0;
M
src/gb/memory.c
→
src/gb/memory.c
@@ -508,8 +508,8 @@ case GB_REGION_CART_BANK0 + 1:
case GB_REGION_CART_BANK0 + 2: case GB_REGION_CART_BANK0 + 3: _pristineCow(gb); - oldValue = memory->rom[address & (GB_SIZE_CART_BANK0 - 1)]; - memory->rom[address & (GB_SIZE_CART_BANK0 - 1)] = value; + oldValue = memory->romBase[address & (GB_SIZE_CART_BANK0 - 1)]; + memory->romBase[address & (GB_SIZE_CART_BANK0 - 1)] = value; break; case GB_REGION_CART_BANK1: case GB_REGION_CART_BANK1 + 1:@@ -654,5 +654,8 @@ }
gb->memory.rom = anonymousMemoryMap(GB_SIZE_CART_MAX); memcpy(gb->memory.rom, gb->pristineRom, gb->memory.romSize); memset(((uint8_t*) gb->memory.rom) + gb->memory.romSize, 0xFF, GB_SIZE_CART_MAX - gb->memory.romSize); + if (gb->pristineRom == gb->memory.romBase) { + gb->memory.romBase = gb->memory.rom; + } GBMBCSwitchBank(&gb->memory, gb->memory.currentBank); }