all repos — mgba @ d5e434c684f36200fca0f4505bc4885b9fdd9c66

mGBA Game Boy Advance Emulator

GB: Fix CGB-to-DMG switchover
Vicki Pfau vi@endrift.com
Fri, 20 Nov 2020 02:34:07 -0800
commit

d5e434c684f36200fca0f4505bc4885b9fdd9c66

parent

54fba4c4611141b45c76471cad9981dadb03389c

3 files changed, 11 insertions(+), 6 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -489,11 +489,6 @@ struct SM83Core* cpu = gb->cpu;

const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; int nextDiv = 0; - if (gb->model >= GB_MODEL_CGB && !(cart->cgb & 0x80)) { - gb->model = GB_MODEL_DMG; - GBVideoDisableCGB(&gb->video); - } - switch (gb->model) { case GB_MODEL_AUTODETECT: // Silence warnings gb->model = GB_MODEL_DMG;

@@ -559,6 +554,12 @@ } else {

cpu->e = 0x08; cpu->l = 0x7C; gb->timer.internalDiv = 0x260; + gb->model = GB_MODEL_DMG; + gb->memory.io[GB_REG_KEY1] = 0xFF; + gb->memory.io[GB_REG_BCPS] = 0x88; // Faked writing 4 BG palette entries + gb->memory.io[GB_REG_OCPS] = 0x90; // Faked writing 8 OBJ palette entries + gb->memory.io[GB_REG_SVBK] = 0xFF; + GBVideoDisableCGB(&gb->video); } nextDiv = 0xC; break;
M src/gb/io.csrc/gb/io.c

@@ -214,7 +214,11 @@ GBIOWrite(gb, GB_REG_HDMA2, 0xFF);

GBIOWrite(gb, GB_REG_HDMA3, 0xFF); GBIOWrite(gb, GB_REG_HDMA4, 0xFF); gb->memory.io[GB_REG_HDMA5] = 0xFF; - } else if (gb->model & GB_MODEL_SGB) { + } else { + memset(&gb->memory.io[GB_REG_KEY0], 0xFF, GB_REG_PCM34 - GB_REG_KEY0); + } + + if (gb->model & GB_MODEL_SGB) { GBIOWrite(gb, GB_REG_JOYP, 0xFF); } GBIOWrite(gb, GB_REG_IE, 0x00);