all repos — mgba @ 6b90a75ae92170a876237ba81e90302ca952da3e

mGBA Game Boy Advance Emulator

GB: Fix using boot ROM with MMM01 games
Vicki Pfau vi@endrift.com
Wed, 02 Oct 2019 18:08:15 -0700
commit

6b90a75ae92170a876237ba81e90302ca952da3e

parent

ed6d55bc4626ef9c3e1543fa873b1af7ff83aef9

2 files changed, 27 insertions(+), 21 deletions(-)

jump to
M CHANGESCHANGES

@@ -35,6 +35,7 @@ - GB Memory: Better emulate 0xFEA0 region on DMG, MGB and AGB

- GB Video: Fix mode 0 window edge case (fixes mgba.io/i/1519) - GB Audio: Fix channel 4 volume (fixes mgba.io/i/1529) - GB Video: Fix color scaling in AGB mode + - GB: Fix using boot ROM with MMM01 games Other fixes: - Qt: Fix some Qt display driver race conditions - Core: Improved lockstep driver reliability (Le Hoang Quyen)
M src/gb/gb.csrc/gb/gb.c

@@ -415,23 +415,6 @@ struct GB* gb = (struct GB*) cpu->master;

gb->memory.romBase = gb->memory.rom; GBDetectModel(gb); - if (gb->biosVf) { - if (!GBIsBIOS(gb->biosVf)) { - gb->biosVf->close(gb->biosVf); - gb->biosVf = NULL; - } else { - GBMapBIOS(gb); - cpu->a = 0; - cpu->f.packed = 0; - cpu->c = 0; - cpu->e = 0; - cpu->h = 0; - cpu->l = 0; - cpu->sp = 0; - cpu->pc = 0; - } - } - cpu->b = 0; cpu->d = 0;

@@ -457,6 +440,24 @@

mTimingClear(&gb->timing); GBMemoryReset(gb); + + if (gb->biosVf) { + if (!GBIsBIOS(gb->biosVf)) { + gb->biosVf->close(gb->biosVf); + gb->biosVf = NULL; + } else { + GBMapBIOS(gb); + cpu->a = 0; + cpu->f.packed = 0; + cpu->c = 0; + cpu->e = 0; + cpu->h = 0; + cpu->l = 0; + cpu->sp = 0; + cpu->pc = 0; + } + } + GBVideoReset(&gb->video); GBTimerReset(&gb->timer); if (!gb->biosVf) {

@@ -561,19 +562,23 @@ }

void GBMapBIOS(struct GB* gb) { gb->biosVf->seek(gb->biosVf, 0, SEEK_SET); + uint8_t* oldRomBase = gb->memory.romBase; gb->memory.romBase = malloc(GB_SIZE_CART_BANK0); ssize_t size = gb->biosVf->read(gb->biosVf, gb->memory.romBase, GB_SIZE_CART_BANK0); - memcpy(&gb->memory.romBase[size], &gb->memory.rom[size], GB_SIZE_CART_BANK0 - size); + memcpy(&gb->memory.romBase[size], &oldRomBase[size], GB_SIZE_CART_BANK0 - size); if (size > 0x100) { - memcpy(&gb->memory.romBase[0x100], &gb->memory.rom[0x100], sizeof(struct GBCartridge)); + memcpy(&gb->memory.romBase[0x100], &oldRomBase[0x100], sizeof(struct GBCartridge)); } } void GBUnmapBIOS(struct GB* gb) { if (gb->memory.romBase < gb->memory.rom || gb->memory.romBase > &gb->memory.rom[gb->memory.romSize - 1]) { free(gb->memory.romBase); - gb->memory.romBase = gb->memory.rom; - gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc); + if (gb->memory.mbcType == GB_MMM01) { + GBMBCSwitchBank0(gb, gb->memory.romSize / GB_SIZE_CART_BANK0 - 2); + } else { + GBMBCSwitchBank0(gb, 0); + } } // XXX: Force AGB registers for AGB-mode if (gb->model == GB_MODEL_AGB && gb->cpu->pc == 0x100) {