diff --git a/include/global.h b/include/global.h index 5de8b410b5..b57cc26049 100644 --- a/include/global.h +++ b/include/global.h @@ -497,6 +497,7 @@ struct SaveBlock2 extern struct SaveBlock2 *gSaveBlock2Ptr; extern u8 UpdateSpritePaletteWithTime(u8); +extern bool8 IsAccurateGBA(void); struct SecretBaseParty { diff --git a/src/main.c b/src/main.c index 3125716e25..985b9185b7 100644 --- a/src/main.c +++ b/src/main.c @@ -432,3 +432,13 @@ void ClearPokemonCrySongs(void) { CpuFill16(0, gPokemonCrySongs, MAX_POKEMON_CRIES * sizeof(struct PokemonCrySong)); } + +// TODO: Needs to be updated if compiling for a different processor than the GBA's +bool8 IsAccurateGBA(void) { // tests to see whether running on either an accurate emulator in >=2020, or real hardware + u32 code[5] = {0xFF1EE12F, 0xE1DF00B0, 0xE12FFF1E, 0xAAAABBBB, 0xCCCCDDDD}; // ARM: _;ldrh r0, [pc];bx lr + u32 func = (u32) &code[0]; + if (func & 3) // not word aligned; safer to just return false here + return FALSE; + func = (func & ~3) | 0x2; // misalign PC to test PC-relative loading + return ((u32 (*)(void)) func)() == code[3] >> 16; +}