Skip to main content

BankNumber

Struct BankNumber 

Source
pub struct BankNumber(/* private fields */);
Available on crate feature 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_bankMAXBank register writes
unset2550x2000
"mbc1"1270x2000 (5 bits), 0x4000 (2 bits)
"mbc5"5110x3000 (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

Source

pub const MAX: u16 = 255

Available on neither gb_wide_bank=mbc1 nor gb_wide_bank=mbc5.

The highest bank number this build can represent.

Source

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.

Source

pub const fn get(self) -> u16

The bank number, for a Mapper writing it to the cartridge.

Trait Implementations§

Source§

impl Clone for BankNumber

Source§

fn clone(&self) -> BankNumber

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BankNumber

Source§

impl Debug for BankNumber

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for BankNumber

Source§

impl PartialEq for BankNumber

Source§

fn eq(&self, other: &BankNumber) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BankNumber

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CellValue for T
where T: Copy + BankSafe,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.