all repos — mgba @ 8561c80a1c43392523ca3be614f2ae8d72b3a469

mGBA Game Boy Advance Emulator

GB MBC: Fix initializing MBC when no ROM is loaded
Jeffrey Pfau jeffrey@endrift.com
Fri, 21 Oct 2016 19:14:09 -0700
commit

8561c80a1c43392523ca3be614f2ae8d72b3a469

parent

d9764e8cea482fead7e1a3376d1007c884ee252b

3 files changed, 64 insertions(+), 60 deletions(-)

jump to
M CHANGESCHANGES

@@ -16,6 +16,7 @@ - Qt: Fix changing resolution of software renderer

- Qt: Fix setting overrides - 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 Misc: - SDL: Remove scancode key input - GBA Video: Clean up unused timers
M src/gb/core.csrc/gb/core.c

@@ -217,9 +217,9 @@ if (gbcore->renderer.outputBuffer) {

GBVideoAssociateRenderer(&gb->video, &gbcore->renderer.d); } - struct GBCartridgeOverride override; - const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; - if (cart) { + if (gb->memory.rom) { + struct GBCartridgeOverride override; + const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; override.headerCrc32 = doCrc32(cart, sizeof(*cart)); if (GBOverrideFind(gbcore->overrides, &override)) { GBOverrideApply(gb, &override);
M src/gb/mbc.csrc/gb/mbc.c

@@ -47,71 +47,74 @@ }

void GBMBCInit(struct GB* gb) { const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; - switch (cart->ramSize) { - case 0: - gb->sramSize = 0; - break; - case 1: - gb->sramSize = 0x800; - break; - default: - case 2: - gb->sramSize = 0x2000; - break; - case 3: - gb->sramSize = 0x8000; - break; - } - - if (gb->memory.mbcType == GB_MBC_AUTODETECT) { - const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; - switch (cart->type) { + if (gb->memory.rom) { + switch (cart->ramSize) { case 0: - case 8: - case 9: - gb->memory.mbcType = GB_MBC_NONE; + gb->sramSize = 0; break; case 1: - case 2: - case 3: - gb->memory.mbcType = GB_MBC1; - break; - case 5: - case 6: - gb->memory.mbcType = GB_MBC2; - break; - case 0x0F: - case 0x10: - gb->memory.mbcType = GB_MBC3_RTC; - break; - case 0x11: - case 0x12: - case 0x13: - gb->memory.mbcType = GB_MBC3; + gb->sramSize = 0x800; break; default: - mLOG(GB_MBC, WARN, "Unknown MBC type: %02X", cart->type); - // Fall through - case 0x19: - case 0x1A: - case 0x1B: - gb->memory.mbcType = GB_MBC5; + case 2: + gb->sramSize = 0x2000; break; - case 0x1C: - case 0x1D: - case 0x1E: - gb->memory.mbcType = GB_MBC5_RUMBLE; + case 3: + gb->sramSize = 0x8000; break; - case 0x20: - gb->memory.mbcType = GB_MBC6; - break; - case 0x22: - gb->memory.mbcType = GB_MBC7; - break; - case 0xFE: - gb->memory.mbcType = GB_HuC3; - break; + } + + if (gb->memory.mbcType == GB_MBC_AUTODETECT) { + switch (cart->type) { + case 0: + case 8: + case 9: + gb->memory.mbcType = GB_MBC_NONE; + break; + case 1: + case 2: + case 3: + gb->memory.mbcType = GB_MBC1; + break; + case 5: + case 6: + gb->memory.mbcType = GB_MBC2; + break; + case 0x0F: + case 0x10: + gb->memory.mbcType = GB_MBC3_RTC; + break; + case 0x11: + case 0x12: + case 0x13: + gb->memory.mbcType = GB_MBC3; + break; + default: + mLOG(GB_MBC, WARN, "Unknown MBC type: %02X", cart->type); + // Fall through + case 0x19: + case 0x1A: + case 0x1B: + gb->memory.mbcType = GB_MBC5; + break; + case 0x1C: + case 0x1D: + case 0x1E: + gb->memory.mbcType = GB_MBC5_RUMBLE; + break; + case 0x20: + gb->memory.mbcType = GB_MBC6; + break; + case 0x22: + gb->memory.mbcType = GB_MBC7; + break; + case 0xFE: + gb->memory.mbcType = GB_HuC3; + break; + } } + } else { + gb->memory.mbcType = GB_MBC_NONE; } switch (gb->memory.mbcType) { case GB_MBC_NONE: