mirror of https://github.com/mgba-emu/mgba.git
GBA: Detect when a BIOS file is not actually a BIOS file
This commit is contained in:
parent
98a6510b92
commit
4fdb4991f4
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue