Expand description
Cycle-accurate Ricoh 2C02 PPU implementation.
See docs/ppu-2c02.md for the implementation spec and
ref-docs/research-report.md §PPU for the source material.
Background rendering, sprite evaluation + rendering, sprite-zero hit, sprite overflow, and the open-bus latch are all implemented at PPU-dot resolution. PPUSTATUS / PPUDATA / PPUSCROLL / PPUADDR register quirks match the test-ROM corpus. The 2-PPU-clock PPUMASK pipeline delay between a mask write and the odd-frame dot-skip check is wired through.
Region timing (NTSC vs PAL vs Dendy) is parameterized via
PpuRegion; the structural difference between them is the post-
render-to-pre-render scanline span (NTSC: 241..=260; PAL: 241..=310;
Dendy: 241..=290).
Re-exports§
pub use provenance::CIRAM_LEN as ATTRIB_CIRAM_LEN;pub use provenance::OAM_LEN as ATTRIB_OAM_LEN;pub use provenance::PALETTE_LEN as ATTRIB_PALETTE_LEN;pub use provenance::PATTERN_ADDR_NONE;pub use provenance::PixelLayer;pub use provenance::PixelProvenance;pub use provenance::PixelProvenanceFrame;pub use provenance::ProvenanceStash;pub use provenance::SPRITE_SLOT_NONE;pub use provenance::WriteAttrib;pub use provenance::WriteAttribution;
Modules§
- octal_
trace - Zero-cost no-op stand-in for the octal-latch tracer.
- provenance
- v2.3.2 “Lucid” — per-byte write attribution for PPU-visible memory.
- read2007_
diag - Diagnostic: capture the (frame, scanline, dot, mask) of
$2007reads to pin where the$2007 Stresstest’s per-dot reads land vs the visible scanline they target. Gated; default build unaffected.
Structs§
- BgSplit
State - Vertical split-screen override (MMC5
$5200-$5202and equivalents). - ExAttribute
- Re-export of the mapper-side per-tile extended-attribute info.
- HdSprite
- One sprite covering a pixel, for the HD-pack multi-sprite conditions
(
spriteAtPosition/spriteNearby). Carries just the identity those conditions match on. Output-only telemetry. - HdTile
Source - v1.2.0 beta.2 (Workstream C3) — per-pixel HD-pack tile-source record.
- Ntsc
Palette Params - Tunable parameters for
generate_base_palette. - Ppu
- 2C02 PPU.
- Prov
BgAddrs - The three VRAM addresses that produced one background tile.
Enums§
- Palette
Init - v2.1.7 P5 — selectable power-up palette-RAM contents.
- PpuPalette
- Which PPU palette is active for the running console.
- PpuRegion
- Region governs the size of the post-render-to-pre-render scanline span.
- PpuRevision
- v2.1.7 P5 — selectable 2C02 die revision, gating revision-dependent quirks.
- PpuSnapshot
Error - Errors returned by
Ppu::restore.
Constants§
- ATTENUATION
- Per-emphasis-bit attenuation factor (≈ −2.5 dB) applied during the phases that overlap the emphasized primary’s hue region. (Bisqwit / nesdev.)
- BLACK
- Black reference voltage (the composite level that normalizes to 0.0).
- FRAMEBUFFER_
LEN - RGBA8 framebuffer length in bytes (256 × 240 × 4).
- FRAMEBUFFER_
PIXELS - Visible pixel count (256 × 240) — length of the parallel
Ppu::index_framebuffer(oneu16per pixel). - HD_
CHR_ RAM chr_tile_indexsentinel meaning “CHR is RAM” — the tile is keyed by its 16 CHR bytes (content) rather than by an absolute CHR-ROM tile index.- HD_
TILE_ NONE - Sentinel
chr_addrfor a transparent / universal-background HD-pack pixel. - LEVELS
- The eight composite signal voltage levels the 2C02 emits, relative to sync.
- NES_
PALETTE - 64-entry RGB888 NES palette (FBX Smooth). Each entry is
[R, G, B]. - PHASES
- The number of distinct subcarrier phases the 2C02 walks within one pixel. A full color-decode integrates over exactly these twelve samples.
- PPU_
SNAPSHOT_ SLIM_ FLAG - v2.3.3 — high bit of the version byte, marking a slim snapshot: every field except the 245,760-byte framebuffer.
- PPU_
SNAPSHOT_ VERSION - Schema version for the PPU snapshot blob.
- RAW_
ENTRIES - The number of
(index, emphasis)entries in a full raw-signal LUT: 64 base colors × 8 emphasis states. - SCREEN_
HEIGHT - Visible screen height in pixels. Companion to
SCREEN_WIDTH. - SCREEN_
WIDTH - Visible screen width in pixels, and the stride of every per-pixel buffer the PPU exposes.
- WHITE
- White reference voltage (the composite level that normalizes to 1.0).
Statics§
- MASK_
WRITE_ DELAY - v2.0 Phase 6 (
mc-ppu-subpos): the analog$2001PPUMASK write delay.
Traits§
- PpuBus
- Bus interface the PPU sees.
Functions§
- build_
rgba_ lut - v2.8.0 Phase 4 — build the 512-entry
(emphasis << 6) | color→ RGBA8 lookup the PPU’s pixel-emit path uses. - build_
rgba_ lut_ from_ base - Build the 512-entry
(emphasis << 6) | color→ RGBA8 lookup from a custom 64-entry base palette (e.g. a loaded.palfile). - composite_
voltage - Compute the raw composite voltage (relative to sync) for one subcarrier
phase(0..12) of NES paletteindex(0..=63) underemphasis(0..=7, bit0 = red, bit1 = green, bit2 = blue). - generate_
base_ palette - Synthesize the 64-entry RGB888 base palette from
params. - generate_
raw_ signal_ lut - Generate the full raw-signal LUT:
RAW_ENTRIESrows (index-major,index * 8 + emphasis), each the twelve normalized subcarrier samples. - in_
color_ phase - Return
truewhen the chroma square wave for huecolor(0..15) is in its “high” state at subcarrier phasephase(0..12). - nes_
color_ to_ rgba - Convert a 6-bit NES color index to an RGBA8 quad.
- normalize
- Normalize a raw composite voltage to the shader-friendly
[0.0, 1.0]range. - palette_
color_ to_ rgba - Convert a 6-bit color index to RGBA8 under the active PPU palette, applying the palette’s emphasis model.
- signal_
samples - Build the twelve normalized composite samples for one
(index, emphasis)pair — the per-pixel waveform a signal-decode shader convolves across neighbouring pixels. - version
- Returns the crate version string.