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...
1 Answers
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.)
- 23,072
- 4
- 91
- 150
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 – puppydrum64 Oct 22 '21 at 15:13r1or something? Aside from abbreviations for stack pointer etc. registers, I've only ever known the registers on GBA to be numbered. – Karl Knechtel Sep 07 '22 at 01:04