Skip to main content

module

Macro module 

module!() { /* proc-macro */ }
Available on crate feature bank only.
Expand description

Declare the enclosing module as a ROM bank group.

Generates the group brand (__BankGroup) that the module’s #[bank] items are anchored to, its Group impl, and the link-time bank marker that gb-bank-pack patches. Call it once, at the top of a banked module.

§Bank assignment

  • bank::module!() lets gb-bank-pack auto-assign a bank (it bin-packs all auto modules into 16 KiB banks).
  • bank::module!(N) pins the module to bank N (1 or higher); the packer reserves that bank for it instead of auto-assigning. Pin every module to a distinct bank when you want a deterministic, one-module-per-bank layout (so a call between two modules is always a real cross-bank switch). Bank 0 is the always-mapped region and cannot be pinned to.

To make a submodule share its parent’s bank, use bank::inherit!() instead of declaring a separate group.

§Examples

mod sound {
    use gb_bank::*;
    bank::module!(3);            // pinned to bank 3

    #[bank]
    pub fn play(note: u8) -> u8 { note }
}