all repos — mgba @ 474f1c6e9c8b5008d40a0faf1508e685b72cede3

mGBA Game Boy Advance Emulator

GB Memory: Fix patching bank 0
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Oct 2016 11:49:06 -0700
commit

474f1c6e9c8b5008d40a0faf1508e685b72cede3

parent

c1c27b46feba04724d6ce5c11dd4b32315ca8a98

3 files changed, 9 insertions(+), 5 deletions(-)

jump to
M CHANGESCHANGES

@@ -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.csrc/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.csrc/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); }