From 9150a79efd85450df02ba70908dbfcc3f27924b2 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 9 Jul 2017 09:59:05 -0700 Subject: [PATCH] GBA: Extend oddly-sized ROMs to full address space (fixes #722) --- CHANGES | 1 + src/gba/gba.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES b/CHANGES index d10243b3a..e8e5a9c46 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Bugfixes: - GB Audio: Make audio unsigned with bias (fixes mgba.io/i/749) Misc: - GBA Timer: Use global cycles for timers + - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) 0.6.0: (Future) Features: diff --git a/src/gba/gba.c b/src/gba/gba.c index a6d9467ae..d5f5e2113 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -342,6 +342,16 @@ bool GBALoadROM(struct GBA* gba, struct VFile* vf) { gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize); GBAHardwareInit(&gba->memory.hw, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]); GBAVFameDetect(&gba->memory.vfame, gba->memory.rom, gba->memory.romSize); + if (popcount32(gba->memory.romSize) != 1) { + // This ROM is either a bad dump or homebrew. Emulate flash cart behavior. +#ifndef _3DS + void* newRom = anonymousMemoryMap(SIZE_CART0); + memcpy(newRom, gba->memory.rom, gba->pristineRomSize); + gba->memory.rom = newRom; +#endif + gba->memory.romSize = SIZE_CART0; + gba->isPristine = false; + } // TODO: error check return true; }