# Handoff: build `gamate-python`, the Bit Corporation Gamate board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. Both cores this machine needs exist: the CPU (`../6502-python`, `MOS6502` row, pin `81e0eb6`; or `../w65c02-python`, decision 1) and the sound chip (`../ay8910-python`, `AY8910` row, pin `76cace3`). Everything else 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: `supervision-python` (a 65C02 LCD handheld of the same years, also documented by Kevin Horton), `a2600-python` (6502-python on a board), `gameboy-python` (an LCD handheld with a boot ROM). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL code (MAME's driver is closed: validation.md); no BIOS or cartridge 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; cartridges.md; bios.md; link-and-pad.md; census.md; domains.md; validation.md; mame-oracle.md; provenance.md; then KH itself (`reference/docs/Gamate_Inside.txt`, after `python -I scripts/fetch_references.py`), all of it: 24 KB and the main judge. ## Scope In: the memory map with open bus, RAM mirroring, BIOS mapping; the LCD controller (VRAM port, scroll, windows, triple-scan frame timing); the IRQ timer; the AY wiring (address, tick rate, stereo routing); the cartridge port (protection handshake, plain/banked/4-in-1 mappers); the pad; the link shift registers and NMI. Out: the CPU (a core); the AY (a core); hosts, windows, sites; the LCD's grey response and any persistence simulation (host side); the analogue audio mix. ## Proposed names - Package **`gamate_python`**; `gamate_python.Gamate` (the board), built with a `bios` (bytes the player supplies), a `cartridge` (bytes) and an optional `mapper` override. - Modules: `bus.py` (map, RAM, open bus), `bios.py` (mapping only; the bytes are the player's), `lcd.py` (VRAM port, scroll, frame timing), `irq.py` (the 32,768-clock timer), `sound.py` (the AY socket: address decode, tick, stereo), `cart.py` (`Cartridge` protocol; `ProtectionChip` handshake; `PlainMapper`, `BankedMapper`, `FourInOneMapper`), `pad.py`, `link.py` (`LinkDevice` socket), `machine.py`. - Sockets: the CPU (the core's read/write callables, request lines), the AY (`write_register`, `tick`, `levels`), the cartridge (`Cartridge`: read/write at 6000-DFFF, plus the audio-in hook), the link (`LinkDevice`), the pad. ## Import boundary The board imports `sixfiveohtwo` (or `w65c02_python`) and `ay8910_python` and nothing else. The cores never import the board. The board keeps time: each CPU callback is one phi2 cycle (two crystal clocks); the AY ticks on every second CPU cycle; the LCD and IRQ count crystal clocks. ## Unknowns (U) and contradictions (C) - U1 the CPU cell's opcode set beyond the documented NMOS 151; U2 its bus shapes (dummy reads, RMW writes, `JMP (xxFF)`, decimal cycle, D at reset/interrupt). - U3 mirroring inside 4000-43FF and 5000-53FF; U4 open bus beyond absolute addressing; U5 the IRQ line's acknowledge (vector pull, per KH's "should"). - U6 CPU/LCD-refresh contention on VRAM; U7 5001 bits 3-1 and E/N's side effects; U8 5006 read buffering; U9 window-mode row selection in detail; U10 VRAM at power-on. - U11 AY registers 14-15; U12 the AY tick's phase; U13 cartridge audio in; U14 the analogue mix. - U15 cart-space reads before unlock; U16 the protection chip's and bank latches' address decode; U17 the handshake's bit timing; U18 the bank register width; U19 16 KB image mirroring. - U20 how many BIOS revisions exist (three ASIC versions); U21 link pin roles; U22 the link NMI's clearing; U23 which games use the link. - C1 NCR's data sheet (65CX02 supercell: full CMOS set with bit instructions) vs KH's bench ("NOT a 65C02, the 65C02 instructions are missing") vs MAME (NMOS 6502) vs the brief ("65C02-family"). - C2 visible height: 150 (KH, MAME) vs 152 (CC65). - C3 5006 Rdat: increments (KH) vs "no auto inc?" (CC65). - C4 KH's VRAM address figures repeat entries at row ends: typing slips, not behaviour. - C5 AY channel A left / B right (KH) vs registers 0/1 right, 2/3 left (CC65). - C6 BIOS chronology: Bit image "newer"/"Rev 1" (MAME, No-Intro) vs Bit Corp first, UMC later (KH's history). KH outranks CC65 and MAME wherever he says he measured; the others stay recorded beside. ## Milestones (exit tests: validation.md rungs) M1 map, open bus, RAM, BIOS mapping, CPU wired, IRQ timer (rung 0 begins); M2 cartridge port: protection chip and the plain mapper, the BIOS reaches `JMP 6020h` (rung 0); M3 LCD (rung 1); M4 banked and 4-in-1 mappers, read off a longer MAME `CW` trace first (rung 2); M5 AY socket (rung 3); M6 MAME lockstep and pictures (rung 4); M7 seeded faults (rung 5); M8 link socket (rung 6). ## Domains and speed (domains.md) - **Domains and channels:** one domain, the console on one 4.433 MHz crystal (CPU /2, AY /4, LCD rows of 162 clocks, IRQ /32,768); channels to the outside only: the link (a sync point at every 4400 write and 4C00 access when two consoles share a process), the pad, the cartridge port. - **Instructions per second:** ceiling 2,216,500 / 2 = 1.108 M/s; MAME observed 0.83 M/s (2,489,567 in 3 s; 4,965,591 in 6 s; 2.679 cycles each). - **No-JIT path:** Python on PyPy about 1/2 to 1/3 of real time (lynx-python's ~0.5 M instructions/s); `gamate-rust` alone (w65c02-rust measured ~190 M instructions/s as a bare core; a board at ~1/5 of that) estimates ~35x real time on desktop, ~27x phone, ~18-20x browser, ~7x on an A55 handheld. No `-fast`, turbo, threads or recompilation needed. Capabilities: `recompile: none`, no threads, cheap run-ahead and rewind (~17.5 KB state). ## Open decisions for Aubrey 1. **CPU row: `MOS6502` from 6502-python, provisional (HYPOTHESIS for bus shapes).** Recommended: KH's bench statement is the only evidence from the machine itself, MAME agrees, and the software executes nothing outside the documented NMOS set (7.46 M instructions traced). NCR's data sheet (C1) is recorded beside it; if a probe shows CMOS bus shapes without the new opcodes, that becomes a new row raised on 6502-python. A probe cartridge (cpu.md) goes into the probe batch. 2. **KH outranks CC65 and MAME on every contradiction (C2-C6).** Recommended: KH is the only bench measurement; CC65 restates PeT's emulator-era notes, and MAME is a model. 3. **The board outputs 2-bit pixels; the four greys are the host's palette.** Recommended: the triple-scan greys are the panel's analogue response (as decided for the Supervision). 4. **The BIOS is required; a "skip BIOS" start is a named concession, off by default.** Recommended: the handshake and the BIOS's IRQ/NMI handlers stay in charge after boot (CC65), so skipping it changes behaviour, not just start-up time. The player supplies either image, identified by SHA-1. 5. **No new core repository; ay8910-python's `AY8910` row as is.** Recommended: the CPU and AY cores exist; the LCD, timer, link and cartridge logic serve no second family board. 6. **Cite the NCR data book through w65c02-python's pin instead of fetching a second copy.** Recommended: one pinned copy in the family; the page numbers are cited here. 7. **One tier: `gamate-rust` only; no `-fast` unless a measured target needs it.** Recommended (domains.md: ~7x real time even on the slowest handheld class).