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§
- cgb
cgb - Game Boy Color hardware registers.
Structs§
- Audio
Ctrl - Audio master control (
NR52). - Envelope
- Volume and envelope (
NR12/NR22/NR42). - Interrupts
- Interrupt sources.
IEandIFshare 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. - Master
Volume - Master volume and VIN panning (
NR50). - Noise
Ctrl - Channel 4 control (
NR44). - Noise
Freq - 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. - Period
Ctrl - Period high bits and channel control (
NR14/NR24/NR34). - Pulse
Length Duty - Length timer and duty cycle (
NR11/NR21). - Serial
Ctrl - Serial transfer control (
SC). - Stat
- LCD status (
STAT). - Sweep
- Channel 1 frequency sweep (
NR10). - Timer
Ctrl - Timer control (
TAC). - WaveDac
- Channel 3 DAC power (
NR30). - Wave
Output - Channel 3 output level (
NR32).
Enums§
- Duty
- Square-wave duty cycle (
NR11/NR21bits 7-6). - PpuMode
- Current PPU mode (
STATbits 1-0). - Shade
- One of the four DMG gray shades.
- Timer
Clock - Timer input clock: the
TACclock-select field (bits 1-0). - Wave
Level - Wave-channel output level (
NR32bits 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
xx00into 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.