GB MBC: Fix initializing MBC when no ROM is loaded

This commit is contained in:
Jeffrey Pfau 2016-10-21 19:14:09 -07:00
parent d9764e8cea
commit 8561c80a1c
3 changed files with 64 additions and 60 deletions

View File

@ -16,6 +16,7 @@ Bugfixes:
- 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

View File

@ -217,9 +217,9 @@ static void _GBCoreReset(struct mCore* core) {
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);

View File

@ -47,71 +47,74 @@ void GBMBCSwitchSramBank(struct GB* gb, int bank) {
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;
break;
case 0x20:
gb->memory.mbcType = GB_MBC6;
break;
case 0x22:
gb->memory.mbcType = GB_MBC7;
break;
case 0xFE:
gb->memory.mbcType = GB_HuC3;
case 3:
gb->sramSize = 0x8000;
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: