pub struct BankNumber(/* private fields */);bank only.Expand description
A ROM bank number, held as a u8 or, under gb_wide_bank="mbc5", a u16.
It is a type rather than a plain integer so that the storage width stays out of
every signature: how wide a bank number is, and how selecting one reaches the
cartridge, is a property of the build. cargo-gb derives it from wide_banks
in header.toml and passes --cfg gb_wide_bank; MAX is
all that changes between modes.
gb_wide_bank | MAX | Bank register writes |
|---|---|---|
| unset | 255 | 0x2000 |
"mbc1" | 127 | 0x2000 (5 bits), 0x4000 (2 bits) |
"mbc5" | 511 | 0x3000 (bit 8), 0x2000 (low byte) |
This is the widest number the build can carry. The cartridge’s own limit is
tighter and gb-bank-pack enforces it at link time.
§Wide banking and GBDK
GBDK reaches the bank register through its own one-byte shadow, exported here
as _current_bank, and writes only 0x2000. "mbc1" keeps both, so linking
gbdk-sys still works; the parts of GBDK that read the shadow (its far
pointers, banked-call trampoline, and crash handler) would misread a bank above
31, and none of them are reachable from Rust. "mbc5" has no one-byte shadow to
export, so a program linking gbdk-sys fails to link, and no interrupt handler
may switch banks (see switch_bank).
Implementations§
Source§impl BankNumber
impl BankNumber
Sourcepub const MAX: u16 = 255
Available on neither gb_wide_bank=mbc1 nor gb_wide_bank=mbc5.
pub const MAX: u16 = 255
gb_wide_bank=mbc1 nor gb_wide_bank=mbc5.The highest bank number this build can represent.
Sourcepub const fn new(n: u16) -> BankNumber
pub const fn new(n: u16) -> BankNumber
Name a bank, rejecting one this build cannot represent.
In a const context an out-of-range number is a compile error.
Trait Implementations§
Source§impl Clone for BankNumber
impl Clone for BankNumber
Source§fn clone(&self) -> BankNumber
fn clone(&self) -> BankNumber
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more