gb_rt/boot.rs
1//! Hardware identification captured by the startup code at boot.
2//!
3//! The boot ROM leaves identification values in registers `A` and `B` when it
4//! hands control to the cartridge at `0x100`, valid only at that first
5//! instruction. `rrt0` captures them into `__boot_a` and `__boot_b`; this module
6//! reads them back. Interpreting the values is left to callers:
7//!
8//! | Register | Value | Console |
9//! |----------|-------|---------|
10//! | `A` | `0x01` | DMG, and Super Game Boy |
11//! | `A` | `0xFF` | MGB (Pocket, Light) |
12//! | `A` | `0x11` | CGB, also reported by the Game Boy Advance |
13//! | `B` | bit 0 set | Game Boy Advance running in CGB mode |
14
15unsafe extern "C" {
16 #[link_name = "_boot_a"]
17 static BOOT_A: u8;
18 #[link_name = "_boot_b"]
19 static BOOT_B: u8;
20}
21
22/// Value left in register `A` by the boot ROM.
23#[inline]
24pub fn a() -> u8 {
25 unsafe { core::ptr::read_volatile(core::ptr::addr_of!(BOOT_A)) }
26}
27
28/// Value left in register `B` by the boot ROM.
29#[inline]
30pub fn b() -> u8 {
31 unsafe { core::ptr::read_volatile(core::ptr::addr_of!(BOOT_B)) }
32}