# Handoff: build `supervision-python`, the Watara Supervision board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. The CPU core already exists: `w65c02-python` (`../w65c02-python`, pin `fca677f`; Rust transcription `../w65c02-rust`). Everything else on this machine is one ASIC's peripherals, used by no other family board, so by the chip rule it stays in this board. Nearest models in the family: `a2600-python` and `lynx-python` (6502-family boards on one clock; `lynx-python` uses the same core), `gameboy-python` (an LCD handheld with a similar register style). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL code (MAME's Supervision files, Potator, the openGateware core are closed: validation.md); no cartridge or TV-Link bytes in the repository; `NO_INTRO_DIR`, `MAME_ROMPATH`; local git only; no sweeps over the library. ### Read in this order README.md; docs/start-here.md; memory-map.md; cpu.md; lcd.md; sound.md; link-and-tvlink.md; census.md; domains.md; validation.md; mame-oracle.md; provenance.md; then KH itself (`reference/docs/Supervision_Tech.txt`, after `python -I scripts/fetch_references.py`), all of it: it is 33 KB and the main judge. ## Scope In: the memory map and banking (and the large-cart mapper once known), the LCD controller (scan, slots, size and scroll registers, the two fields), the video DMA, the timer, NMI and IRQ logic, the four sound sources and the mixer, the pad, the link port, the cartridge port; later the TV-Link and the colour models. Out: the 65C02 (w65c02-python); hosts, windows, sites; any palette or LCD-persistence simulation (host side). ## Proposed names - Package **`supervision_python`**; `supervision_python.Supervision` (the board), built with a `cartridge` (bytes the player supplies) and a `model` (`"handheld"` 4.000 MHz; later `"tvlink-ntsc"` 3.56 MHz, `"tvlink-pal"` 4.43 MHz, OBSERVED from MAME). - Modules: `bus.py` (map, WRAM, VRAM, slot accounting), `cart.py` (bank rule, 32 KB mirroring, mapper hook), `lcd.py` (scan and fields), `dma.py` (video DMA), `sound.py` (squares, noise, sample DMA, mixer), `timers.py` (IRQ timer, NMI divider, 2023-2027), `pad.py`, `link.py` (the `LinkDevice` socket), `tvlink.py` (late), `machine.py`. - Sockets: the CPU (w65c02-python's read/write callables, `note_stall()`, request lines), the cartridge (`Cartridge` protocol: read(address17), write latch hook), the link port (`LinkDevice`), the pad. ## Import boundary The board imports `w65c02_python` (the `G65SC02` row, decision 1) and nothing else. The core never imports the board. The board keeps time: each callback is one 4 MHz clock. ## Unknowns (U) and contradictions (C) - U1 2030-3FFF; U2 6000-7FFF (memory-map.md). - U3 the mapper of the 256 KB 4-in-1 and the 512 KB Journey to the West. - U4 register read-back values; U5 NMI phase and enable behaviour. - U6 the CPU cell's variant beyond "CMOS" (bit instructions, `WAI`/`STP`). - U7 cartridge wait states; U8 code in VRAM; U9 the CPU during video DMA; U10 the sample fetch's cost to the CPU; U11 2026's reset value and 32 KB wiring. - U12 grey weights of the two fields; U13 DMA to non-VRAM; U14 the DMA source's bank. - U15 the noise LFSR taps and output bit; U16 speaker vs headphone mixing; U17 DC levels. - U18 which games use the link; U19 what the TV-Link is and does. - C1 MAME's 61 Hz screen vs KH's 50.81 Hz frame (MAME shows a frame per NMI). - C2 KH's line-length formula vs his measured 246 clocks (the formula's units are off by four). - C3 X_Scroll bits 1-0: a pixel delay (KH) vs unused (CC65). - C4 square length for L = 0: one tick (KH's formula) vs 256/60 s (CC65). - C5 201B bits 3-2 left/right (KH) vs volume (CC65); rates 256-2048 clocks (KH) vs "15360" (CC65). - C6 2021/2022 direction + data (KH) vs read port + write port (CC65). - C7 2026 bit 2 unknown (KH) vs the sample-DMA IRQ enable (CC65). - C8 KH's pseudo-code loops from 1 (159 lines of 39 bytes) vs his measured 160 lines of 40. - C9 "15-bit LFSR tapped at bits 14 and 15". KH outranks CC65 wherever he says he measured; CC65's readings stay recorded beside. ## Milestones (exit tests in validation.md) M1 map, banking, vectors, NMI, the core wired (rung 0); M2 LCD scan and VRAM slots (1); M3 video DMA (2); M4 timer and IRQ (3); M5 sound (4); M6 MAME lockstep and pictures (5, 6); M7 seeded faults (7); M8 link socket, large carts, TV-Link (8). ## Domains and speed (domains.md) - **Domains and channels:** one domain, the console on one 4 MHz clock; channels to the outside only (link port: a sync point at every 2021/2022 access when two consoles share a process; pad; cartridge port). - **Instructions per second:** ceiling 4 MHz / 2 = 2.0 M/s; MAME observed 1.20-1.50 M/s (2.69-3.35 clocks per instruction) in three games. - **No-JIT path:** Python (PyPy) about 1/4-1/6 of real time; `supervision-rust` alone (w65c02-rust measured ~190 M instructions/s as a bare core) estimates 10-20x real time on desktop, phone and browser, ~4x on a Cortex-A55 handheld. No `-fast`, turbo, threads or recompilation needed. Capabilities: `recompile: none`, no threads, cheap run-ahead and rewind (~16 KB state). ## Open decisions for Aubrey 1. **CPU row: `G65SC02` (base CMOS, no bit instructions, no `WAI`/`STP`).** Recommended, provisional: games use `BRA`/`STZ`/`PHX` (so CMOS) and nothing more; MAME runs the same set; it has a captured part behind it. A one-instruction probe cartridge (cpu.md) is queued for the day a unit and a flash cart exist. 2. **KH outranks CC65 and MAME on every contradiction (C1-C9), each recorded.** Recommended: KH is the only bench measurement; CC65 and MAME are a toolchain and an emulator. 3. **The LCD's four greys are the host's palette, the board outputs 2-bit pixels per field.** Recommended: the grey weights are the panel's analogue behaviour (U12); no evidence to fix them in the specification. 4. **The two large carts (256 KB, 512 KB) wait for evidence (a disassembly of their bank writes) and are listed as unsupported until then.** Recommended; the hypothesis (a /WR latch) is tested by reading their code, not guessed. 5. **TV-Link and colour models as a late milestone, OBSERVED from MAME's descriptions only.** Recommended: the handheld is the product; the TV-Link has no document at all. 6. **One tier: `supervision-rust` only; no `-fast` unless a measured target needs it.** Recommended (domains.md: 10-20x real time estimated everywhere). 7. **No new core repository.** Recommended: the CPU is w65c02-python; the ASIC's other parts serve no second family board (chip rule).