Skip to content

Instantly share code, notes, and snippets.

@drhelius
Last active March 9, 2024 19:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhelius/3398793 to your computer and use it in GitHub Desktop.
Save drhelius/3398793 to your computer and use it in GitHub Desktop.
Game Boy - Hardware detection
To detect Super Game Boy, the values of SGB Flag and Old Licensee Code must be set in the cartridge header. In detail, that would mean that the value of $0146 is $03 and the value of $014B is $33.
To detect Game Boy Color, use the value of the CGB Flag in the cartridge header. If the value of $0143 is $80, then the game should be compatible with both normal and color Game Boy models. If it is $C0, then it should only work with Game Boy Color.
Additionally, some games check the value of the Accumulator directly after startup. If the value is $01, then the hardware is either Super Game Boy or normal Game Boy. If it is $FF, then the hardware is either Super Game Boy 2 or Game Boy Pocket. If it is $11, then it is either Game Boy Color or Game Boy Advance.
Lastly, you can detect if the game is on a Game Boy Advance by checking bit 0 of the B register directly after startup. If it is cleared, it is a Game Boy Color. If it is set, it is a Game Boy Advance.
__________
Note: The Super Game Boy 2 was little more than a Super Game Boy with a link cable port in it. Some games do detect this, however, like Tetris DX, which will display a different border for Super Game Boy and Super Game Boy 2.
EDIT:
Here is a list of examples for games which detect seperate combinations of hardware configurations:
Normal only: Tetris
Normal or Super: Pokémon
Normal, Super or Color: Game & Watch Gallery 2, Game & Watch Gallery 3
Normal, Super, Color or Super2: Tetris DX
Color only: Super Mario Bros. DX
Advance: The Legend of Zelda: Oracle of Ages, The Legend of Zelda: Oracle of Seasons
Ah, yes. I forgot how to post hardware detection of Super Game Boy. My appologies.
Super Game Boy programs write to the Joypad register at $FF00 in order to communicate with the Super Game Boy. For a non-Super Game Boy system, anything written to this register should be ignored.
Sending command $11 through this register (which requires a special SGB protocol which I will not document here) will pass a MLT_REQ command to the Super Game Boy, which is used for multiple joypads plugged into the SNES, which can be 1, 2 or 4. If this command is successful, then data can be read from each of those joypads. If it is not successful, then the hardware is not a Super Game Boy.
So simply ignore any data that is written to register $FF00 and it is therefore impossible for a ROM to detect that it is being used in a Super Game Boy.
__________
Simply checking the Accumulator will resolve Color/Advance Game Boy presence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment