diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 11ab2eb97..6171b4e00 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -146,7 +146,7 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { if (threadContext->rom) { GBALoadROM(&gba, threadContext->rom, threadContext->save, threadContext->fname); - if (threadContext->bios) { + if (threadContext->bios && GBAIsBIOS(threadContext->bios)) { GBALoadBIOS(&gba, threadContext->bios); } diff --git a/src/gba/gba.c b/src/gba/gba.c index 60c5a0527..14eb83f2f 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -680,6 +680,23 @@ bool GBAIsROM(struct VFile* vf) { return memcmp(signature, GBA_ROM_MAGIC, sizeof(signature)) == 0; } +bool GBAIsBIOS(struct VFile* vf) { + if (vf->seek(vf, 0, SEEK_SET) < 0) { + return false; + } + uint32_t interruptTable[7]; + if (vf->read(vf, &interruptTable, sizeof(interruptTable)) != sizeof(interruptTable)) { + return false; + } + int i; + for (i = 0; i < 7; ++i) { + if ((interruptTable[i] & 0xFFFF0000) != 0xEA000000) { + return false; + } + } + return true; +} + void GBAGetGameCode(struct GBA* gba, char* out) { memcpy(out, &((struct GBACartridge*) gba->memory.rom)->id, 4); } diff --git a/src/gba/gba.h b/src/gba/gba.h index 522d3e3db..e653021f9 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -170,6 +170,7 @@ void GBALoadBIOS(struct GBA* gba, struct VFile* vf); void GBAApplyPatch(struct GBA* gba, struct Patch* patch); bool GBAIsROM(struct VFile* vf); +bool GBAIsBIOS(struct VFile* vf); void GBAGetGameCode(struct GBA* gba, char* out); void GBAGetGameTitle(struct GBA* gba, char* out);