16

I remember finding out there was a secret area in both games that you could only get to if you were playing on a Game Boy Advance. Even the 3DS releases don't allow access to them. My question is, how did the games know they were running on a Game Boy Advance? I thought that the ARM CPU in the Game Boy Advance was disabled in Game Boy Color mode...

0
19

Probably the easiest way to discover whether a cartridge was started on a GameBoy Advance is to look at the initial register state. According to nitro2k01 at gbdev.gg8.se:

cgb_agb_boot.bin - Gameboy Color boot ROM used in GBA's GBC mode

This revision of the GBC boot ROM was used in GBA's GBC compatibility mode and has the following changes from the most common GBC boot ROM revision:

  • […]
  • CGB-AGB contains an additional "inc B" instruction right before control is handed over to the cartridge, which allows the game to detect that it's running on GBA and for example fix its color palette to improve visibility on the darker GBA LCD screen. This also leads to a minor reorganization of the code in this area.

In other words, on a GameBoy Advance the B register should be 1 after the boot ROM runs, where it would otherwise be zero. This behaviour is emulated in mGBA. The Pan Docs reference describes the initial register state similarly, though it also mentions some other possibilities.

A disassembly of Oracle of Ages/Seasons I found online confirms this is the method they used:

;;
; The game's entrypoint.
begin:
    nop
    di
    cp $11
    ld a,$00
    jr nz,+

    ; Check GBA Mode
    inc a
    bit 0,b
    jr z,+
    ld a,$ff
+
    ldh (<hGameboyType),a

(The earlier test checks for a Game Boy Color, also agreeing with the Pan Docs.)

3
  • Does the Game Boy boot rom also set all registers to zero before the inc B? I was under the impression that a register's contents could never be assumed to contain any specific value upon booting up. But that may just be for systems with no BIOS like the NES Oct 22 at 15:13
  • 1
    It’s not a bad stance to adopt in general, but I think the B register value has been deliberately set up that way (though only official documentation can confirm for sure). And at this point we should consider the Game Boy ABI effectively frozen anyway. I don’t expect any more versions of the boot ROM, they all behave more-or-less deterministically (emulators also faithfully follow their behaviour), so one might as well take any useful behaviour exhibited as promised. Oct 22 at 16:24
  • I got it to work. I had mistakenly cleared the work ram after the test, which is why my in-software hexdump was showing a zero value. Oct 24 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.