# PPU status (milestone 2) The picture, dot by dot: `src/snes_python/ppu.py` (registers, the cycle schedule, the frame) and `src/snes_python/ppu_render.py` (backgrounds, mode 7, mosaic, objects, windows, colour math). Worked model: **ares 9408cb4 `sfc/ppu` (ISC)**, ported with its notice (`NOTICE`, each file's header); register meanings from fullsnes and anomie (DOC). No GPL source was read. ## How it runs The PPU keeps its own line and clock. The board calls `sync()` before every `$21xx` access and `end_line()` when a line ends, and the PPU runs ares's schedule (`sfc/ppu/main.cpp`) up to the board's clock: sprite range checks every 8 clocks from H=0 to 1016, BG fetches every 4 clocks to 1054, the sub-screen half-dot at H = 56 + 4x and the main half-dot at H = 58 + 4x, and the sliver fetch from H=1080 as a generator that yields the 4 or 8 clocks of each step. Work at clock H is done once the board's clock has passed H, so a write lands at the dot ares puts it. Lines 241 and later run nothing. Output: `ppu.frame_buffer`, 512 x 478 raw DAC words (BGR555 in bits 0-14, INIDISP brightness in bits 15-18), two per dot (sub-screen or hi-res half, then main half); line V (1-239) is row 2(V-1), plus the field when interlaced. `ppu.picture()` gives the visible frame as RGB (256 or 512 wide, 224 or 239 lines, doubled when interlaced; brightness as fullsnes's c(N+1)/16); `ppu.write_png(path)` saves it. `snes_python.ppu_png` reads and writes PNG (and the one BMP among krom's pictures) without Pillow. Speed (PyPy 7.3.20, one process): 0.1-0.4 s per frame; krom's demos take 3-45 s for 60 frames. ## Departures from ares | Where | ares | The board | Why | | --- | --- | --- | --- | | A BG the mode does not have | still shifts its stale tiles and could draw them | draws nothing | DOC: fullsnes "2105h - BGMODE" lists each mode's BGs | | Object pixels | walks the 34 slivers each dot | resolves the drawn line once (the slivers are fixed once fetched) and applies the enables and the priority map each dot | same result, fewer steps; `Objects._build_line` | | Brightness | `color()` curve with a "deep black" ramp, brightness 0 at 1/4 | c(N+1)/16, 0 = black | DOC: fullsnes "2100h - INIDISP" (U10 asks the console) | | Power-on | random VRAM/CGRAM and registers | zeros | HYPOTHESIS, as milestone 1 | | STAT77 bit 4/5 | (parent's commit 3b85b78) | as the console (MEASURED) | | | CGRAM address in active display | the main-screen lookup (the last in a dot) | the sub-screen lookup | MEASURED: probe suite CGWS/CGRS, 63/63 rows (see below) | | STAT77 bit 6 (range over) | set after the sliver fetch | set when the 33rd object is found | DOC fullsnes "213Eh"; MEASURED: OBJF D1, D4 | Not modelled (open): the INIDISP early-read glitch and the brightness delay (Q10), the first hi-res half-dot (U9, follows ares: black), 128 KiB VRAM. ## Gates Tests: `tests/test_ppu.py` (13 unit tests, fast), `tests/test_milestone2_pictures.py` (slow: 26 pass, 17 xfail with reasons). Milestone 1's slow ROM gate: 30/30 on 3e30f1e. ### krom's PPU demos with a picture 41 ROMs have a `.png` of the same name (`scripts/mesen_frames.py`'s rule); `scripts/ppu_pictures.py` also takes `RedspaceHDMA.png` and `RedspaceIndirectHDMA.png` (case differs): 43. 60 frames, 5 bits per channel. | Date | Commit | Exact vs krom (of 43) | Exact vs Mesen2 frame 60 (of 41) | | --- | --- | ---: | ---: | | 2026-11-19 | first PPU commit (on board c9a22d2) | 26 | 30 | | 2026-11-19 | 3e30f1e (CGRAM address, range over) | 26 (+1 near) | 30 (unchanged) | Exact against krom: all 6 BGMAP, HiColor3840, HiColor575Myst, GreenSpace, the 10 HiColor 64/128-per-tile-row ROMs, Mode7HDMA, RedSpaceHDMA, RedSpaceIndirectHDMA, InterlaceMystHDMA, Perspective, Rings, WindowHDMA. The rest, each with its reason (also in `tests/test_milestone2_pictures.py`): - **U9, the first hi-res half-dot** (one column of 448 rows): the 4 pseudo-hi-res HiColor ROMs (the RGB chart: 190 px), InterlaceRPG, InterlaceSimpsonsHDMA. ares draws it black (the board follows); krom's pictures show it; Mesen2 draws it dimmer (and differs from krom in more of the pseudo-hi-res picture: 5,378-54,198 px). - **U10, brightness**: RedSpace9BitHDMA (512 px off by one 5-bit step; nothing differs by 8 or more in 8 bits). Mesen2: 28,928 px (its curve is floor(c N / 15)). - **Animated**: krom's picture is another frame. Mesen2 at frame 60 matches the board exactly on RotZoom, StarWars, MosaicMode3, WindowMultiHDMA, InterlaceFont, HiColor1241DLair; on InterlaceMoogle, InterlaceScroll and MosaicMode5 it differs only in the first column (U9). - **WaveHDMA**: 40,267 px against krom, 45,230 against Mesen2: animated, not settled. `ppu_pictures.py` also reports **near**: every difference is one 8-bit step that crosses a 5-bit boundary (the reference's own 5-to-8-bit converter). RedSpace9BitHDMA is near; the others are not. ### krom's CPUTest pictures 400 frames, 2026-11-19, board c9a22d2 + the first PPU commit. | Folder | Exact | Near | Different | | --- | ---: | ---: | --- | | `CPUTest/CPU` (23) | 3 (DEC, INC, MOV) | 19 | CPUMSC: the STP row's PASS is missing (94 px) | | `CPUTest/SPC700` (7) | 0 | 0 | 683-793 px each: the S-SMP is not connected (milestone 3) | The 19 "near" pictures differ only in the blue background: the ROM writes colour `$7800` (blue 30, `CPUAND.asm` l.2770); krom's CPUDEC.png saves it as 247 and CPUAND.png as 248 (another converter), so they are right at 5 bits in substance. CPUMSC's missing PASS after `STP` is a CPU-side matter (milestone 1's token count gate does not include it), not the picture. ### The probe suite's PPU tests against the console (tier 1) `scripts/suite_run.py probe-pack/00-OURS/suite.sfc --on board --machine sfc-v1`, then `scripts/suite_results.py tests/console/suite-2026-10-25.srm board.srm --diff --only ...` (the console: CPU 1, PPU1 1, PPU2 1; it ran suite format 1). 2026-11-19, board c9a22d2 + this PPU. | Tag | Result | What it changed or left open | | --- | --- | --- | | CGWS, CGRS | content equal on all 63 + 63 rows (rows still marked differ only by the latched H, +-1 dot, a CPU-side matter) | **changed**: the PPU's CGRAM address in active display is the sub-screen lookup's, not ares's last (main-screen) lookup; before: 7 rows landed at colour 1 where the console has 0 (MEASURED, `ppu_render.DAC.run`) | | OBJF | flags equal in all 5 layouts; range over seen on the evaluation line (V99, dot within one 12-dot poll of the console) | **changed**: STAT77 bit 6 is set when the 33rd object is found (DOC fullsnes "213Eh"; MEASURED), not after the sliver fetch as ares; time over equal within 7 dots | | MIDF | CG H-Blank and V-Blank, OAM V-Blank equal; **CG active**: console colour 1, board 0; **OAM active / H-Blank**: console changes 3-4 bytes near sprite 43-52 (or byte 8), board 2 bytes at byte $100 | open | | OAWA, OAWB, OAMR, PPUW (OAM) | the console's OAM address during active display and H-Blank moves (sprites ~43-52 across line 100, and two-byte writes also change two high-table bytes); ares's model (the address of the last in-range object, else unchanged) does not: the board's writes stay at one place | open: the PPU's own OAM address sequence is not known from a document; format-2 OAWC/OAWD would separate it (the console ran format 1) | | PPUW (CGRAM) | after the sub-screen change: equal | | | DISP | E1 274: equal; E1 0-128 and 330: the console flags range over on line 59 itself, about 140 dots after the display is switched on; the board on line 60 (the objects at indices 0-32 were checked while force-blanked); E2 d, e: the console's OAM address after a mid-frame on/off is $38 / $FC, the board's $24 (no reload, address unchanged) | open: the console keeps evaluating, or keeps its count, through force blank; not modelled | | OBUS `$213E` | bits 0-6 equal; bit 7 (time over) set on the console only | power-on OAM: the console's is not zero (Q21), the board's is | | HVFF | the latched H values differ (CPU-side timing of the test); the flip-flop behaviour and `$213F` bit 5 (PPU2 open bus) follow from the values | not a PPU matter | ### undisbeliever's probes against the detectors (tier 3) No console result is recorded for them yet (probe-pack `results.csv` is empty), so they are compared with the closed boxes' saved frames (`tests/detector_frames/*/{mesen,mame}.png`, 300 frames; `ppu_pictures.py tests/detector_frames --detectors`). 67 ROMs (66 + gradient-test): the board equals **Mesen2 on 40** and MAME 0.285 on 17 (all 17 also Mesen2's). Equal to Mesen2: all 10 `scpu-a-dma-bug`, all 8 `quick-model1-dma-crash`, the 8 `inidisp_hammer`, `hdma-timing-demonstration`, `object-dropout-test`, `vram-mid-scanline-test`, both `setini-early-read`, `hdma-2100-glitch`, `hdma-21ff-glitch`, `hdma-21ff-2100-0f-glitch`, `hdma-failure-last-dma-value-test`, `inidisp_brightness_0`, `inidisp_d7_glitch_test`, `enable-autojoy-late-test`, `joypad_bounce_test`, gradient-test. Most of the rest print measured numbers (auto-joypad, IPL speed, `wrmpyb-in-flight`, reset position): CPU-side timing, not the picture. Picture-side differences: `inidisp_forgot_to_force_blank` (21,232 px; the two detectors differ by 36,376 between themselves), `_2`, `hdma-2100-glitch-2ch-*`, `hdma-21ff-2100-glitch`, `hdmaen_latch_test*`, `inidisp_brightness_delay` (90 px), `inidisp_enable_display_mid_frame` (93 px). `joypad_rapid_read_test` uses overscan (239 lines; not compared). ### gradient-test NovaSquirrel's `gradient-test.sfc`, 300 frames: the board's picture equals Mesen2's frame exactly at 5 bits (`tests/detector_frames/gradient-test/ mesen.png`); MAME 0.285 differs by 15,339 px. Its own text, "there should be a gradient effect and black borders and white text", is what the board shows.