From 4f94849728227e028564cbd72ef4605edbb56707 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 10 Feb 2022 18:26:08 -0800 Subject: [PATCH] GBA: Automatically skip BIOS if ROM has invalid logo --- CHANGES | 1 + src/gba/core.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index dc8ad9aa0..7a7285bd5 100644 --- a/CHANGES +++ b/CHANGES @@ -41,6 +41,7 @@ Other fixes: Misc: - Core: Suspend runloop when a core crashes - GB Video: Add default SGB border + - GBA: Automatically skip BIOS if ROM has invalid logo - mGUI: Add margin to right-aligned menu text (fixes mgba.io/i/871) - Qt: Rearrange menus some - Qt: Clean up cheats dialog diff --git a/src/gba/core.c b/src/gba/core.c index 8515fa9c1..633572249 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef USE_ELF #include #endif @@ -129,6 +130,7 @@ static const struct mCoreMemoryBlock _GBAMemoryBlocksEEPROM[] = { struct mVideoLogContext; #define CPU_COMPONENT_AUDIO_MIXER CPU_COMPONENT_MISC_1 +#define LOGO_CRC32 0xD0BEB55E struct GBACore { struct mCore d; @@ -658,7 +660,16 @@ static void _GBACoreReset(struct mCore* core) { #endif ARMReset(core->cpu); - if ((core->opts.skipBios && (gba->romVf || gba->memory.rom)) || (gba->romVf && GBAIsMB(gba->romVf))) { + bool forceSkip = gba->romVf && GBAIsMB(gba->romVf); + if (!(forceSkip || core->opts.skipBios) && (gba->romVf || gba->memory.rom) && gba->pristineRomSize >= 0xA0 && gba->biosVf) { + uint32_t crc = doCrc32(&gba->memory.rom[1], 0x9C); + if (crc != LOGO_CRC32) { + mLOG(STATUS, WARN, "Invalid logo, skipping BIOS"); + forceSkip = true; + } + } + + if (forceSkip || (core->opts.skipBios && (gba->romVf || gba->memory.rom))) { GBASkipBIOS(core->board); } }