GBA: Detect when a BIOS file is not actually a BIOS file
Jeffrey Pfau jeffrey@endrift.com
Sun, 04 Jan 2015 19:02:53 -0800
3 files changed,
19 insertions(+),
1 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -146,7 +146,7 @@ }
if (threadContext->rom) { GBALoadROM(&gba, threadContext->rom, threadContext->save, threadContext->fname); - if (threadContext->bios) { + if (threadContext->bios && GBAIsBIOS(threadContext->bios)) { GBALoadBIOS(&gba, threadContext->bios); }
M
src/gba/gba.c
→
src/gba/gba.c
@@ -680,6 +680,23 @@ }
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); }
M
src/gba/gba.h
→
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);