Skip to main content

gb/
lib.rs

1//! `gb`: Game Boy hardware abstractions.
2//!
3//! # Feature flags
4#![doc = document_features::document_features!()]
5#![no_std]
6#![feature(asm_experimental_arch)]
7#![feature(linkage)]
8#![feature(negative_impls)]
9#![feature(abi_z80_interrupt)]
10#![cfg_attr(docsrs, feature(doc_cfg))]
11
12pub mod mmio;
13pub mod apu;
14pub mod interrupt;
15#[cfg(feature = "cgb")]
16#[cfg_attr(docsrs, doc(cfg(feature = "cgb")))]
17pub mod ir;
18pub mod joypad;
19pub mod ppu;
20pub mod serial;
21pub mod timer;
22
23// Also at the root, so the attribute reads as `#[gb::bank]` rather than
24// `#[gb::bank::bank]`. A macro and a module may share a name.
25#[cfg(feature = "bank")]
26#[cfg_attr(docsrs, doc(cfg(feature = "bank")))]
27pub use gb_bank_macros::bank;
28#[cfg(feature = "pak")]
29#[cfg_attr(docsrs, doc(cfg(feature = "pak")))]
30pub use gb_pak_macros::sram;
31pub use gb_hram::hram;
32pub use gb_ram_fn::ram_fn;
33
34#[cfg(feature = "bank")]
35#[cfg_attr(docsrs, doc(cfg(feature = "bank")))]
36#[doc(inline)]
37pub use gb_bank as bank;
38#[cfg(feature = "pak")]
39#[cfg_attr(docsrs, doc(cfg(feature = "pak")))]
40#[doc(inline)]
41pub use gb_pak as pak;
42#[doc(inline)]
43pub use gb_hram as hram;
44#[doc(inline)]
45pub use gb_ram_fn as ram_fn;
46#[doc(inline)]
47pub use gb_rt as rt;
48
49// Where the `gb-bank` and `gb-ram-fn` macros look when the invoking crate depends
50// on this crate instead of on them.
51#[cfg(feature = "bank")]
52#[doc(hidden)]
53pub use gb_bank as __bank;
54#[cfg(feature = "pak")]
55#[doc(hidden)]
56pub use gb_pak as __pak;
57#[doc(hidden)]
58pub use gb_ram_fn as __ram_fn;
59
60/// Whether the machine has the Game Boy Color's hardware.
61///
62/// From the value the boot ROM leaves in `A`, so it costs one load. A Game Boy
63/// Advance reports yes as well: it runs the same hardware.
64///
65/// A cartridge built for both machines needs this wherever a Color feature has
66/// nothing to fall back on.
67#[inline]
68pub fn is_cgb() -> bool {
69    rt::boot::a() == 0x11
70}
71
72/// Whether the machine is a Game Boy Advance running a Game Boy Color cartridge.
73///
74/// Programs usually ask in order to lighten their palettes, the Advance's screen
75/// being the darker of the two.
76#[inline]
77pub fn is_gba() -> bool {
78    is_cgb() && rt::boot::b() & 1 != 0
79}