all repos — mgba @ 2b5b8a0d6a29c233ac1f3ce664f57ddc3dfb19b4

mGBA Game Boy Advance Emulator

GBA: Improve multiboot detection
Jeffrey Pfau jeffrey@endrift.com
Thu, 05 Nov 2015 20:58:52 -0800
commit

2b5b8a0d6a29c233ac1f3ce664f57ddc3dfb19b4

parent

0faa6dd8acef62296cd9f352f404bf0555f7ae73

1 files changed, 19 insertions(+), 6 deletions(-)

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

@@ -5,6 +5,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gba.h" +#include "arm/decoder.h" +#include "arm/isa-inlines.h" + #include "gba/bios.h" #include "gba/cheats.h" #include "gba/io.h"

@@ -12,8 +15,6 @@ #include "gba/rr/rr.h"

#include "gba/supervisor/thread.h" #include "gba/serialize.h" #include "gba/sio.h" - -#include "isa-inlines.h" #include "util/crc32.h" #include "util/memory.h"

@@ -27,8 +28,7 @@

static const size_t GBA_ROM_MAGIC_OFFSET = 3; static const uint8_t GBA_ROM_MAGIC[] = { 0xEA }; -static const size_t GBA_MB_MAGIC_OFFSET = 0xC1; -static const uint8_t GBA_MB_MAGIC[] = { 0x00, 0x00, 0xEA }; +static const size_t GBA_MB_MAGIC_OFFSET = 0xC0; static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component); static void GBAInterruptHandlerInit(struct ARMInterruptHandler* irqh);

@@ -727,11 +727,24 @@ }

if (vf->seek(vf, GBA_MB_MAGIC_OFFSET, SEEK_SET) < 0) { return false; } - uint8_t signature[sizeof(GBA_MB_MAGIC)]; + uint8_t signature[sizeof(uint32_t)]; if (vf->read(vf, &signature, sizeof(signature)) != sizeof(signature)) { return false; } - return memcmp(signature, GBA_MB_MAGIC, sizeof(signature)) == 0; + uint32_t opcode; + LOAD_32(opcode, 0, signature); + struct ARMInstructionInfo info; + ARMDecodeARM(opcode, &info); + if (info.branchType != ARM_BRANCH) { + return false; + } + if (info.op1.immediate <= 0) { + return false; + } else if (info.op1.immediate != 24) { + return true; + } + // Found a libgba-linked cart...these are a bit harder to detect. + return false; } bool GBAIsBIOS(struct VFile* vf) {