# Handoff: build `plus4-python`, the Commodore 264 series board (Plus/4, C16, C116) ## Context you are inheriting The family's shape: chips are cores, boards compose cores; CPUs always get their own core; a non-CPU chip used by one machine stays in its board and is extracted only when a second family project needs it; never copy a file between repositories, pin the sibling by commit. Read the charter first (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md). The 264 series is **era 1**: one clock domain on the main board, cycle level everywhere, Python runs the tests, Rust plays. Boards to model this one on: **c64-python** and **vic20-python** (Phase 0 only, tonight's siblings: the same 6502 family, the IEC bus and the 1541), **famicom-python** and **a2600-python** (a 6502-family CPU on a cycle-stepped bus with a video chip that owns the clock), **a5200-python** (`docs/sally-halt.md`: RDY on a 6502). Read in order before writing code: [README.md](../README.md), [start-here.md](start-here.md), [cpu-7501.md](cpu-7501.md), [ted.md](ted.md), [memory-io.md](memory-io.md), [drives.md](drives.md), [domains-and-speed.md](domains-and-speed.md), [sources.md](sources.md), [provenance.md](provenance.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md). Then `python -I scripts/fetch_references.py` (33 documents, ~31 MB, and VICE-testprogs' `Plus4/` and `TED/`, sparse; `--verify` to check). PDFs become text in `reference/text/`; the GIF scans need tesseract (the 7501 pages 1, 3-6 were OCR'd that way here). ## Decided by Aubrey (standing rules that apply here) - Name `plus4-python`, package `plus4_python`. Local, no remote. - Bring your own ROMs, cartridges, disks and tapes, found by `NO_INTRO_DIR` and `MAME_ROMPATH`; firmware identified by SHA-1, never copied or committed. - Python floor = PyPy's (3.11), PyPy must work; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps; technical choices made, marked provisional and reported. - Closed boxes (VICE xplus4, YAPE, plus4emu, FPGATED, MAME) are run, never opened; their source is never fetched into this repository. ## Scope and rows `plus4` (NTSC) and `plus4p` (PAL) from M1; `c16`, `c16p`, `c116` at M8 (16 KB, no ACIA, no user-port 6529, no 3-plus-1); prototypes (`c232`, `v364` with its speech ROM, `c264`, `c16_hu`) last. Out of scope: the C128 and the 1571/1581. ## Package and classes (proposed) ``` plus4_python/ machine.py # rows: TED model and video standard, RAM size, ROM SHA-1s, which I/O chips exist console.py # build(machine, rom_dir, cartridge=None, iec=None, expansion=None) -> Plus4 bus.py # the scheduler: TED dot/half-cycle steps; PHI edges start CPU cycles; BA/AEC/GATE IN ted.py # Ted: counters and decodes, clock windows, DMA, refresh, video, sound, timers, IRQ, keyboard latch pla.py # Pla: the 82S100 fuse map as a logic table (from the player's dump) banks.py # the $FDD0-$FDDF bank latch, $FF3E/$FF3F ROM/RAM spi6529.py # Spi6529 (two on the Plus/4, one on the C16) acia6551.py # Acia6551 (Plus/4 only), pin-shaped for later extraction (decision 5) keyboard.py # the 8x8 matrix and joysticks presented to the TED latch datasette.py # tape pulses into the port; motor, write, sense (6529 bit 2) iec.py # IecBus socket (shared definition with c64-python/vic20-python) expansion.py # ExpansionPort: cartridges (CBM at offset 7), the 1551's TCBM cartridge socket savestate.py ``` ## What the board needs from its cores From **6502-python** (`sixfiveohtwo`, pin `81e0eb6`): 1. **`MOS7501`** beside c64-python's requested **`MOS6510`** (one port mechanism, a pin mask: P0-P4, P6, P7 for the 7501; no NMI input) (decision 2). 2. RDY on reads: `note_stall()` / `dma_stalled` exist. 3. Nothing for the clock switch: the board decides each cycle's length; the core is called once per cycle. 4. For the 1551 later: **`MOS6510T`** (unknown port width, U17) and, for the 1541, the SO input c64-python requests. No other core: TED, the 6529s, the 6551 and the PLA stay in the board (chip rule below). ## The gate (defined at M1) Unit tests of documented facts (L0), boot lockstep with MAME by instruction stream and register-write order (L1), the READY picture (L2), seeded faults each caught. Cartridge slot, expansion port and IEC socket empty. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | upstream: `MOS7501` (and `MOS6510`) in 6502-python | 7501DS, TSHM 5 (2); 6502-python's suites | suites unchanged; port unit tests; a fault (DDR/data swapped) caught | | M1 | **bus, TED counters and decodes, clock windows, DMA/BA, refresh slots, PLA, banking, RAM/ROM, timers, IRQ, keyboard latch, the 7501 port** | TEDDS, TSHM (2); MAME (5) | **boot to READY in lockstep with MAME's instruction stream** (801,584 instructions, NTSC, first 3 s) or a named reason per difference; the PAL row boots | | M2 | **TED pictures**: text, multicolour, ECM, bitmap, MC bitmap, attributes, flash, cursor, border, 38/40 columns, 24/25 rows, the TSHM 4.4 palette | TEDDS (2), VICE `Plus4/openmem` (3) | READY screen equal to MAME's in colour indices; openmem's real-machine pattern reproduced | | M3 | **timing**: cycles per line in each region, DMA lines, mid-line register writes | TEDDS sheets 11-12 (2); VICE `TED/` | the L4 programs match the data-sheet arithmetic; each disagreement with a GPL detector named | | M4 | **sound** (two voices, noise, D/A mode) | TEDDS registers (2); good-enough rule | register behaviour per TEDDS; audio compared with detectors, differences named | | M5 | **cartridges and 3-plus-1** | the images | the 10 No-Intro cartridges reach their titles (smoke list); F1 starts 3-plus-1 | | M6 | **datasette** | the KERNAL's own loader | a `.tap` loads through the KERNAL; motor timing FITTED | | M7 | **drives**: IEC socket + `c1541-python`; TCBM + the `c1551` row (decision 3) | DOS ROMs, schematics (2) | `LOAD"$",8` lists a disk on a 1541 and on a 1551 | | M8 | **rows and the rest**: C16/C116, PAL, prototypes; ACIA and user port; save states | MAME boots (5); MOS82/ACIA (2) | each row boots to READY; a save state continues identically | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | the 7501 port's bit assignments (serial, cassette) | SCH sheets 1-4 | read at M1 | | U2 | what the missing P5 reads; any fade on undriven bits | none | FITTED by tests | | U3 | 7501 vs 8501 differences | none found | one class | | U4 | what RAM receives on writes to $0000/$0001 | none | M1, tests | | U5 | PAL dot and cycle divisors (MAME: TED 3.54 MHz, CPU 886.72 kHz) | TEDDS, SCH | M1 | | U6 | the OCR-damaged decode counts (NTSC vertical sync, attribute fetch lines) | TEDDS page images | re-read at M1 | | U7 | the sound frequency formula, noise polynomial, D/A mode | none | good-enough rule | | U8 | C16 RAM mirroring | C16 schematic 251788 | M8 | | U9 | the bank latch's range (OCR reads like $FDD0-$FDDF) | TSHM 11.2 image | M1 | | U10 | MAME's boot writes to $FD20 ($09, $89) | PLA dump, SCH | M1 | | U11 | the PLA image's format (245 bytes) | the image itself | M1 | | U12 | joystick select bits in the keyboard latch write | SCH, SM | M1 | | U13 | the 1551's PLA has no good dump (MAME) | none | M7 blocker for exactness | | U14 | the TCBM handshake | 1551 schematics, DOS behaviour | M7 | | U15 | why TEDDS limits the gap between timer low and high writes to 125 us | none | test | | U16 | the shape of a CPU cycle at a single/double boundary (stretched half-cycles?) | TSHM 4.5.2 diagram, TIMING GIF | M3 | | U17 | the 6510T's port width | 1551 schematic | M7 | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | port addresses | 7501DS p. 5: output register $0001, DDR $0000; TSHM 5.1: port $0000, DDR $0001 | the data sheet (the 6510 arrangement; MAME's boot writes fit it) | | C2 | port width | 7501DS p. 1 and TSHM 5: 7 bits; 7501DS p. 5: "Eight pins" | 7 (the pinout lists 7; page 5 is reworked 6510 text) | | C3 | double-clock frequency | SM: ".89 or 1.76 MHz"; TEDDS: 1.788 MHz | 1,789,773 Hz (14,318,180 / 8); SM rounds | | C4 | refresh window | TEDDS prose: counts 304-344; TEDDS table: refresh single clock 288-328 | re-read both images; tests decide | | C5 | PAL timer rate | TEDDS: 884 kHz; 17,734,475 / 20 = 886,724 (MAME 886.72 kHz) | the arithmetic, marked; settle by a PAL timing test | | C6 | colour count | TSHM 1: "128 colors"; distinct colours 121 (black at every luminance) | 128 codes, 121 colours: both true | ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | 7501/8501 | 264 series | `MOS7501` in 6502-python (decision 2) | | 6510T | the 1551 | `MOS6510T` in 6502-python, with the drive | | TED 7360/8360 | 264 series only | board | | 6529 SPI | Plus/4, C16 | board | | 6551 ACIA | Plus/4; Oric Telestrat (oric-python later row) | board now; `mos6551-python` when the Telestrat row starts (decision 5) | | 6525 TPI | the 1551 | drive board | | 82S100 PLA | here, c64-python | board each; shared evaluator only if both land one (decision 6) | | 6522 VIA | the 1541 | `mos6522-python` (the shared core vic20/bbc/oric propose) | | 1541, 1551 | C64, VIC-20, 264 series | `c1541-python` with a `c1551` row (decision 3) | ## Domains and speed Full page: [domains-and-speed.md](domains-and-speed.md). **Domains:** M (7501, TED, memory, PLA, 6529s: one crystal, TED sets every cycle's length), A (the 6551's 1.8432 MHz baud clock), D (a drive: 1541 on IEC, 1551 on TCBM). **Channels:** IEC lines, the TCBM port and handshake, the ACIA's registers and serial lines, tape edges; pixels and sound as pure producers. **Instructions per second (NTSC):** from TED's windows, ~17,300 CPU cycles a frame x 59.9 Hz = ~1.04 M cycles a second (arithmetic, HYPOTHESIS); at MAME's 3.35 cycles an instruction, ~310,000 instructions a second; TED 7.16 M dot steps a second; a 1541 adds ~283,000 instructions, a 1551 ~560,000. **No-JIT path:** `recompile: none` reaches real time on desktop, phone and browser through a Rust transcription; no cached interpreter; threads only at the drive channel. Speed is trivial. ## Open decisions for Aubrey (each with a recommendation) 1. **First row.** Recommend NTSC `plus4` first (MAME's default; the boot lockstep is recorded for it) with `plus4p` a row from M1, since most of the platform's software and community (Hungary, Germany) is PAL; C16/C116 at M8. 2. **6502-python variants.** Recommend one request with c64-python's: `MOS6510` and `MOS7501` sharing a port mechanism with a pin mask and a no-NMI flag, before either board's M1; `MOS6510T` with the drive work. 3. **The 1551.** Recommend a `c1551` row in the shared `c1541-python` on a `TcbmBus` socket (same mechanism, GCR and 64H156; different CPU, host interface, DOS and PLA), rather than a separate drive repository. 4. **TED evidence.** No die-level, hardware-capture or measured timing source for TED was found (tier 2 at best, plus three test readmes). Recommend accepting tier 2 for M1-M3, and asking (you or a later agent, with your approval) on plus4world, whose robots.txt allows reading, whether measured timing tables or a TED die project exist. 5. **The 6551.** Recommend keeping it in this board, pin-shaped, and extracting `mos6551-python` when oric-python's Telestrat row begins (its second family user). 6. **PLA evaluator.** Recommend each board evaluates its own 82S100 dump now; extract a shared helper only after both exist and match. 7. **Tiers.** Recommend `plus4-python` then `plus4-rust`; no `-fast` unless a phone or browser measurement asks for it. 8. **MAME's BSD files.** They are BSD-3-Clause by their `license:` lines. Recommend keeping them closed (run only) as tonight's brief says, for consistency with the other boards. 9. **The library.** No TOSEC Plus/4/C16 set is in the mirror; No-Intro has 10 cartridges and one disk. Recommend fetching TOSEC's Commodore Plus-4 and C16 sets (tapes, disks) before M5-M6 for smoke lists: your call, as it adds to the mirror. 10. **funet now redirects to zimmers.** Every `/pub/cbm` URL on funet.fi answers 301 to zimmers.net, whose robots.txt disallows PDFs and archives. vic20-python's pins (and c64-python's zimmers pins) fetch PDFs and ZIPs that way. Recommend repinning those documents to pagetable.com, bitsavers mirrors or archive.org where copies exist, and treating zimmers as GIF/text only. 11. **sources.md rows** (six, in [sources.md](sources.md)): recommend adding them. 12. **Remote.** Recommend local until M1 passes, then a private GitHub remote.