Added function to check for newer emulators/hardware.

This commit is contained in:
Ariel Antonitis 2021-05-23 21:04:37 -04:00
parent e9d01b4808
commit c267dd6ee6
2 changed files with 11 additions and 0 deletions

View file

@ -497,6 +497,7 @@ struct SaveBlock2
extern struct SaveBlock2 *gSaveBlock2Ptr;
extern u8 UpdateSpritePaletteWithTime(u8);
extern bool8 IsAccurateGBA(void);
struct SecretBaseParty
{

View file

@ -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;
}