Skip to content

Commit

Permalink
GBA: Refine multiboot detection (fixes #2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Feb 21, 2022
1 parent 5b26099 commit 91911fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -47,6 +47,7 @@ Misc:
- Debugger: Save and restore CLI history
- GB Video: Add default SGB border
- GBA: Automatically skip BIOS if ROM has invalid logo
- GBA: Refine multiboot detection (fixes mgba.io/i/2192)
- GBA DMA: Enhanced logging (closes mgba.io/i/2454)
- GBA Video: Implement layer placement for OpenGL renderer (fixes mgba.io/i/1962)
- mGUI: Add margin to right-aligned menu text (fixes mgba.io/i/871)
Expand Down
21 changes: 20 additions & 1 deletion src/gba/gba.c
Expand Up @@ -672,13 +672,23 @@ bool GBAIsMB(struct VFile* vf) {
}

uint32_t pc = GBA_MB_MAGIC_OFFSET;
int wramAddrs = 0;
int wramLoads = 0;
int romAddrs = 0;
int romLoads = 0;
int i;
for (i = 0; i < 80; ++i) {
if (vf->read(vf, &signature, sizeof(signature)) != sizeof(signature)) {
break;
}
pc += 4;
LOAD_32(opcode, 0, &signature);
if ((opcode & ~0x7FF) == BASE_WORKING_RAM) {
++wramAddrs;
}
if ((opcode & ~0x7FF) == BASE_CART0) {
++romAddrs;
}
ARMDecodeARM(opcode, &info);
if (info.mnemonic != ARM_MN_LDR) {
continue;
Expand All @@ -700,10 +710,19 @@ bool GBAIsMB(struct VFile* vf) {
break;
}
if ((immediate & ~0x7FF) == BASE_WORKING_RAM) {
return true;
++wramLoads;
}
if ((immediate & ~0x7FF) == BASE_CART0) {
++romLoads;
}
}
}
if (romLoads + romAddrs > 2) {
return false;
}
if (wramLoads + wramAddrs) {
return true;
}
// Found a libgba-linked cart...these are a bit harder to detect.
return false;
}
Expand Down

0 comments on commit 91911fe

Please sign in to comment.