Skip to main content

Module mmio

Module mmio 

Source
Expand description

Typed, volatile handles to the Game Boy’s hardware registers and memory.

The Game Boy has no faulting memory, so an accessor is unsafe only when it can make the CPU execute arbitrary bytes (OAM DMA started outside HRAM, or enabling an interrupt with no handler) or physically damage the panel (turning the LCD off outside VBlank). Plain VRAM, OAM, and register access is safe: at worst it draws wrong pixels, which is not undefined behavior.

Each handle is VolAddress<T, R, W> (or VolBlock/VolGrid2d): R and W are the read and write permissions, each Safe, Unsafe, or () (no such method). Addresses follow the Pan Docs / GBDK hardware.h map.

Registers and their value types are re-exported flat (mmio::LCDC).

Modules§

cgbcgb
Game Boy Color hardware registers.

Structs§

AudioCtrl
Audio master control (NR52).
Envelope
Volume and envelope (NR12 / NR22 / NR42).
Interrupts
Interrupt sources. IE and IF share this type (same bit layout).
Joypad
Joypad register (JOYP). Active low: a cleared bit means selected, or the input pressed.
Lcdc
LCD control (LCDC). Each field’s name describes the meaning when set.
MasterVolume
Master volume and VIN panning (NR50).
NoiseCtrl
Channel 4 control (NR44).
NoiseFreq
Channel 4 frequency and randomness (NR43).
OamAttr
Sprite attribute byte (OamEntry::attr).
OamEntry
A single OAM sprite entry (4 bytes).
Palette
A DMG palette (BGP / OBP0 / OBP1): one shade per color index. Object palettes ignore color index 0 (transparent).
Panning
Sound panning (NR51): which channels reach each output.
PeriodCtrl
Period high bits and channel control (NR14 / NR24 / NR34).
PulseLengthDuty
Length timer and duty cycle (NR11 / NR21).
SerialCtrl
Serial transfer control (SC).
Stat
LCD status (STAT).
Sweep
Channel 1 frequency sweep (NR10).
TimerCtrl
Timer control (TAC).
WaveDac
Channel 3 DAC power (NR30).
WaveOutput
Channel 3 output level (NR32).

Enums§

Duty
Square-wave duty cycle (NR11 / NR21 bits 7-6).
PpuMode
Current PPU mode (STAT bits 1-0).
Shade
One of the four DMG gray shades.
TimerClock
Timer input clock: the TAC clock-select field (bits 1-0).
WaveLevel
Wave-channel output level (NR32 bits 6-5).

Constants§

BGP
Background palette (DMG).
DIV
Divider: reads the upper byte of the divider, any write resets it to 0.
DMA
OAM DMA: writing a high byte copies 160 bytes from xx00 into OAM.
IE
Interrupt enable: which interrupts may fire.
IF
Interrupt flag: pending interrupt requests.
JOYP
Joypad: write selects the button or d-pad group, read returns its state.
LCDC
LCD control: display/window/sprite/background enables and tile sources.
LY
Current scanline. Read-only.
LYC
Scanline compare value for the LYC=LY STAT interrupt.
NR10
Channel 1 sweep.
NR11
Channel 1 length timer and duty cycle.
NR12
Channel 1 volume and envelope.
NR13
Channel 1 period low byte (write-only).
NR14
Channel 1 period high byte and control.
NR21
Channel 2 length timer and duty cycle.
NR22
Channel 2 volume and envelope.
NR23
Channel 2 period low byte (write-only).
NR24
Channel 2 period high byte and control.
NR30
Channel 3 DAC power.
NR31
Channel 3 length timer (write-only).
NR32
Channel 3 output level.
NR33
Channel 3 period low byte (write-only).
NR34
Channel 3 period high byte and control.
NR41
Channel 4 length timer (write-only).
NR42
Channel 4 volume and envelope.
NR43
Channel 4 frequency and randomness.
NR44
Channel 4 control.
NR50
Master volume and VIN panning.
NR51
Sound panning: which channels go to which output.
NR52
Audio master control: power and per-channel status.
OAM
Object attribute memory: 40 sprite entries at 0xFE00..=0xFE9F.
OBP0
Object palette 0 (DMG).
OBP1
Object palette 1 (DMG).
SB
Serial transfer data (the byte shifted in/out).
SC
Serial transfer control.
SCX
Background scroll X.
SCY
Background scroll Y.
STAT
LCD status: PPU mode and STAT interrupt sources.
TAC
Timer control: enable and input clock select.
TILEMAP_0
Tile map 0: a 32x32 grid of tile indices at 0x9800, indexed (x, y).
TILEMAP_1
Tile map 1: a 32x32 grid of tile indices at 0x9C00, indexed (x, y).
TIMA
Timer counter.
TMA
Timer modulo (reload value on overflow).
VRAM_TILES
Tile data: 384 tiles at 0x8000..0x97FF (shared by BG and sprites on DMG).
WAVE_RAM
Wave pattern RAM: 16 bytes of channel 3 sample data at 0xFF30.
WX
Window X position plus 7.
WY
Window Y position.

Type Aliases§

Tile
One 8x8 2bpp tile: 16 bytes, two bytes per row.