pak only.Expand description
The Game Pak’s own hardware.
The memory bank controller answers writes to the ROM address range as register
writes, and one 8 KiB window at 0xA000..=0xBFFF shows whatever those
registers last selected. For example SRAM, where a game saves its data.
§Sharing the window
Every peripheral here shares that window, and selecting one deselects the rest, so they do not nest:
// Wrong: the second read comes from the rtc.
FILE.open(cs, |f| {
let a = f.gold.get();
let t = rtc::time(cs); // selects rtc registers
let b = f.gold.get(); // reads the rtc, not the save
});An interrupt handler nests the same way without the code showing it, and one
racing a scope for the same bytes would be a data race. Sram::open
takes a CriticalSection to rule that out, from gb::interrupt::free or
critical_section::with. The rest only write registers, and the rule above is
all that keeps a handler off them.
§What a cartridge has
cargo-gb derives the capabilities below from cartridge_type and ram_size
in header.toml, so a program that reaches for hardware the cartridge lacks
fails to compile rather than writing to a chip that is not there.
MBC1 spends the same two register bits on ROM banks above 512 KiB and on SRAM
banks, so wide_banks and more than one SRAM bank cannot both be set.
Modules§
- eeprom
gb_pak_tilt - MBC7’s save storage: 128 words on a serial EEPROM.
- rtc
gb_pak_rtc - The MBC3 clock: seconds to days, running on the cartridge battery.
- rumble
gb_pak_rumble - The MBC5 rumble motor.
- sram
- The cartridge’s own RAM, usually kept alive by a battery.
- tilt
gb_pak_tilt - The MBC7 accelerometer.
Structs§
- Critical
Section - Critical section token.
Attribute Macros§
- sram
- Place a value at the base of an SRAM bank.