GB: Fix applying a patch that changes the cartridge mapper (fixes #3077)

This commit is contained in:
Vicki Pfau 2023-12-11 22:05:55 -08:00
parent 7be38eaed5
commit 68e5a0aa47
2 changed files with 10 additions and 0 deletions

View File

@ -13,6 +13,7 @@ Emulation fixes:
- GBA BIOS: Fix clobbering registers with word-sized CpuSet
- GBA SIO: Fix normal mode SI/SO semantics (fixes mgba.io/i/2925)
Other fixes:
- GB: Fix applying a patch that changes the cartridge mapper (fixes mgba.io/i/3077)
- GBA Savedata: Fix crash when resizing flash save games for RTC data
- mGUI: Fix cases where an older save state screenshot would be shown (fixes mgba.io/i/2183)
- Qt: Re-enable sync for multiplayer windows that aren't connected (fixes mgba.io/i/2974)

View File

@ -455,6 +455,9 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
if (patchedSize > GB_SIZE_CART_MAX) {
patchedSize = GB_SIZE_CART_MAX;
}
const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
uint8_t type = cart->type;
void* newRom = anonymousMemoryMap(GB_SIZE_CART_MAX);
if (!patch->applyPatch(patch, gb->memory.rom, gb->pristineRomSize, newRom, patchedSize)) {
mappedMemoryFree(newRom, GB_SIZE_CART_MAX);
@ -473,6 +476,12 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
}
gb->memory.rom = newRom;
gb->memory.romSize = patchedSize;
cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
if (cart->type != type) {
gb->memory.mbcType = GB_MBC_AUTODETECT;
GBMBCInit(gb);
}
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc);
}