# Handoff: build `pet-python`, the Commodore PET/CBM board ## 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 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 PET is era 1: one clock domain (plus a drive's, when attached), cycle level everywhere, "Python runs the tests, Rust plays". Boards to model this one on: **a2600-python** and **famicom-python** (a 6502-python core driven per bus cycle, chips advanced inside the bus callbacks), and tonight's Phase 0s of the same chip family: **vic20-python** (6522s, the IEC drive plan), **c64-python** (the 1541 as its own board), **bbcmicro-python** (6522s and a 6845), **williams-python** and **coco-python** (the 6821). Read in order: [machines-and-boards.md](machines-and-boards.md), [io.md](io.md), [video.md](video.md), [ieee488-drives.md](ieee488-drives.md), [cbm-ii.md](cbm-ii.md), [domains-and-speed.md](domains-and-speed.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md), [sources.md](sources.md), [provenance.md](provenance.md). Then `python -I scripts/fetch_references.py` (48 files, about 66 MB, and VICE-testprogs' `PET/`, `CRTC/`, `CBM2/`; `--verify` to check). ## Decided by Aubrey (standing rules that apply here) - Name `pet-python`, package `pet_python`. Local, no remote, until he says otherwise. - Bring your own ROMs: BASIC, KERNAL, editor, character and drive ROMs by SHA-1 (census.md); nothing of Commodore's in the repository. - 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 are made, marked provisional and reported; policy waits for him. - The no-JIT path first (proposals/2026-11-jit.md): this board needs none. ## Scope The PET 2001, 2001-N/B, 3000, 4000 and 8000 series as rows of one board: the static, dynamic, 80-column and universal mainboards (machines-and-boards.md), their ROM sets and keyboards, cassette, user port, CB2 sound and the IEEE-488 socket. Later rows: 8096, 8296, SuperPET. **Out of scope:** the CBM-II (a separate board, decision 7), the drives' insides (their own boards, decisions 5-6), add-on graphics boards (HSG, DWW, HRE). ## Reuse first: each chip's family cores | Chip | Existing family core | What it needs | | --- | --- | --- | | 6502 | **6502-python** (`sixfiveohtwo`, pin `81e0eb6`); 6502-rust | nothing for the computer | | 6520 PIA x 2 | none built; `m6821-python` proposed by williams-python and coco-python | a `mos6520` row: no register difference (MOS82 p. 6-5) (decision 2) | | 6522 VIA | none built; `mos6522-python` proposed by five Phase 0s | pin it (decision 3) | | 6545-1 / MC6845 | none built; `crtc6845-python` proposed by bbcmicro-python and cpc-python | a 6545-1 row: status register, linear/row-column addressing (decision 4) | | discrete video, decode, keyboard, cassette | none | in the board | | 2031 drive | `c1541-python` proposed (vic20, c64, plus4) | a `c2031` row with an IEEE-488 front end (decision 5) | | 2040-8250 drives | none; the 6532 lives in a2600-python (`riot.py`) | a drive board of their own; a 6504 package row in 6502-python (decision 6) | | 6809 (SuperPET) | m6809-python (Phase 0 documents only) | the core, later | ## Package and classes (proposed) ``` pet_python/ machine.py # rows: board, ROM set by SHA-1, RAM size, keyboard, 50/60 Hz editor board.py # Pet: the bus, the order of record, build(machine, ieee=None, tape=None, ...) memory.py # decode per board (RAM rows, screen RAM, ROM sockets, $E8xx chip selects by # address line, open bus) video.py # VideoStatic (SCH-2001 sheet 3), VideoDynamic (SCH-320349 sheets 6-8), # VideoCrtc (dot stream from the CRTC core's MA/RA/DE); reverse video, GRAPHIC keyboard.py # 10 x 8 matrix per keyboard row (N, B); the '145 decode cassette.py # two pulse sources, motor and sense lines sound.py # CB2 level over time ieee488.py # Ieee488Bus socket (sixteen wired-AND lines) and a test-only fake device sockets.py # Protocols: Ieee488Device, TapeDeck, UserPortDevice, ExpansionDevice quickload.py # host helper: a .prg into RAM at its load address (tests and smoke lists) savestate.py # whole-machine states naming ROMs by hash ``` The PIAs come from `m6821_python`, the VIA from `mos6522_python`, the CRTC from `crtc6845_python`, the CPU from `sixfiveohtwo`. ## The import boundary The board owns decoding, RAM/ROM, open bus, the video logic (or the dot stream around the CRTC), the wiring of PIA/VIA pins to keyboard, cassette, IEEE-488, user port and sound, and the interrupt wiring (IRQA/IRQB and the VIA's IRQ ORed to the CPU's IRQ). The chip cores own their registers and pins and know nothing of the PET. A drive owns everything on its side of `Ieee488Bus`. ## Sockets `Ieee488Bus` (drives, printers), `TapeDeck` x 2, `UserPortDevice` (CB2 sound, joystick adapters), `ExpansionDevice` (the 8096's 64K, the SuperPET, graphics boards). With nothing attached the base board's gate must not move when an add-on lands. ## The gate (defined at milestone 1) Lockstep of the KERNAL's instruction stream against MAME's `:f3` trace by CPU cycle, `0 unexplained`; unit tests per documented fact, each citing its sheet or page; open-bus (VICE `PET/unconnected`); later pictures and the CRTC tests; seeded faults (validation.md). ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | the shared chip cores this board pins reach their own first milestone: `m6821-python` with a `mos6520` row, `mos6522-python` (decisions 2-3) | data sheets (2) | each core's own exit | | M1 | **`pet2001n` row** (dynamic board, BASIC 2, 8K): bus, decode with the address-line chip selects, RAM rows, ROMs by SHA-1, both PIAs, the VIA, VIDEO ON into PIA1 CB1 at the right cycle, keyboard matrix, IRQ wiring, no pixels | SCH-320349 (2); MAME trace (5) as detector | the KERNAL reaches BASIC (the banner bytes in screen RAM: "7167 BYTES FREE"); the CPU stream equals MAME's to the first I/O write (cycle 22) exactly and for 2 s with every difference named (C1); open-bus test as its readme's 3016 results | | M2 | **dynamic-board pictures**: counters, character ROM, reverse video, GRAPHIC set, the CPU/video interleave | SCH-320349 sheets 6-8 (2); MAME snapshots (5) | the BASIC screen drawn dot for dot; lines per frame settled from the counters (U2); seeded faults caught | | M3 | **`pet2001` row** (static board, BASIC 1, 6550/6540 maps) and its snow | SCH-2001 sheets 2-3 (2), sheet 1 when obtained (U1) | BASIC 1 banner; the snow rule written from the schematic and tagged | | M4 | **CRTC rows**: `pet4032f`, `pet8032` (60 Hz), `cbm8032` (50 Hz), with `crtc6845-python`'s 6545-1 row (decision 4) | R6545-1, MC6845, MOS82 (2); SCH-8032029 (2); Fachat's CRTC photographs (3, 8296D only) | banners in 40 and 80 columns; the editors' CRTC values produce 16,650- and 19,992-cycle frames; C3 settled | | M5 | **cassette, CB2 sound, user port, quickload**; a smoke list (banners plus a dozen PRGs from the census) | SCH-320349 sheet 3 (2), the KERNAL | a `.tap` loads through the KERNAL; smoke PRGs run | | M6 | **IEEE-488 socket**, then the `c2031` row in `c1541-python` (decision 5), then the 2040-family drive board (decision 6) | the KERNAL and DOS ROMs (2), SM2031, SM2040, DRM (2), MAME drive traces (5) | "DEVICE NOT PRESENT" with nothing attached; `LOAD"$",8` lists a disk on a 2031, later a 4040 and 8050 | | M7 | 8096, 8296, SuperPET rows; save states | TR4000, SPTM (2) | a save state loads into a fresh machine and continues identically | ## Unknowns (U) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | the static board's sheet 1 (CPU, PIAs, VIA, decode) and how the 2001 differs from the dynamic board (e.g. what PIA1 CA2 also drives) | zimmers `2001/320008.pdf` (PDF: not fetchable by robots.txt) | decision 9 | | U2 | lines per frame on the static and dynamic boards | SCH-2001 sheet 3, SCH-320349 sheets 6-8 counters; MAME's 16,666-cycle IRQ cadence (5) | 260 or 261 x 64 us, FITTED candidates | | U3 | the universal board's assembly number and schematic | none pinned | a later pin | | U4 | screen RAM mirrors in $8400-$8FFF per board | SCH-320349 sheet 8 decode | read at M1 | | U5 | what reads return where two chips are selected ($E830, $E850...) | SCH-320349 decode | HYPOTHESIS wired-AND, tagged | | U6 | the CRTC's decode at $E880/$E881 on the 80-column board | SCH-8032029 | read at M4 | | U7 | power-on RAM contents | none | selectable, zeros (provisional) | | U8 | the VIA's PB5 connection | SCH-320349 sheet 3 (hard to read in the scan) | read at a higher resolution at M1 | | U9 | the CRTC boards' speaker circuit | SCH-8032029 | M5 | | U10 | snow: on which cycles and with which character on the static board; whether the dynamic board shows any | SCH-2001 sheet 3, sheet 1 | M3 | | U11 | the 6545-1's status register timing; its interlace (C2) | R6545-1 (scan, to OCR) | in crtc6845-python | | U12 | the 8096's 64K board control register | zimmers PDF only (decision 9) | M7 | | U13 | cassette motor and read timing | none | FITTED | ## Conflicts (C) | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | frame length on CRTC-less PETs | MAME: a 62.5 Hz legacy screen (16,000 cycles) while its KERNAL interrupt recurs every 16,666 cycles; the display circuit: a 64 us line | the schematic's counters decide (U2); compare with MAME by cycle | | C2 | does the 6545-1 interlace? | MOS82 p. 6-9 table "No"; the same page's footnote "MOS MPS 6545 has interlaced mode" | the R6545-1 data sheet decides; the PET's editors never set R8 (PET_CRTC.csv) | | C3 | which PIA1 line takes the retrace on CRTC boards | Fachat (8296D readme): CA1; SCH-320349 (dynamic board): CB1; MAME `cbm8032`: the KERNAL re-arms CRB ($E813) at each interrupt | read SCH-8032029; provisional CB1 | | C4 | the CRTC's clock on 80-column PETs | PETIO.DOC (as quoted by Guenther): 2 MHz; Guenther's measurement: 1 MHz at pin 21, two characters fetched per cycle; MAME: SY6545-1 @ 1 MHz | 1 MHz (measured), confirm on SCH-8032029 | ## Domains and speed Full arithmetic in [domains-and-speed.md](domains-and-speed.md). **Domains:** M (the computer: 6502, PIAs, VIA, memory, video or CRTC, all from one crystal divided to 1 MHz) and, when attached, D per drive (own crystal; the 2040 family's 6502 and 6504 share RAM and stay one domain); tape as a timestamped edge producer. **Channels:** the sixteen IEEE-488 lines (M <-> D), video dots and CB2 sound as pure producers, keyboard and tape edges in. **Instructions per second:** 1,000,000 CPU cycles a second; at MAME's observed 3.05-3.21 cycles an instruction, about **310,000-330,000 instructions a second**; a 2031 adds about 300,000, a 4040 or 8050 about 600,000 (two 1 MHz processors); the video fetches 1-2 M characters and 8-16 M dots a second. **No-JIT path:** `pet-rust`, a plain transcription, reaches real time on desktop, phone and browser (wasm) by the family's NES/2600/Game Boy precedents (HYPOTHESIS until measured); no `-fast`, cached interpreter or threads are needed; `recompile: none` on every target. PyPy: expected near or above real time for the computer alone (HYPOTHESIS). ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | 6502 | many | 6502-python | | 6520 / 6821 | PET, Williams, CoCo, Atari 400/800 | `m6821-python` with a `mos6520` row | | 6522 | PET, VIC-20, 1541, BBC, Vectrex, Oric, the IEEE drives | `mos6522-python` | | 6545 / 6845 | PET, BBC, CPC, CBM-II | `crtc6845-python` | | 6532 | 2600, 7800, the IEEE drives | `riot6532-python` when the drive board starts | | 6530 | the IEEE drives only | in the drive board | | PET video logic, decode | PET only | board | ## Open decisions for Aubrey (each with a recommendation) 1. **First rows.** Recommend `pet2001n` (dynamic board, BASIC 2, 8K, fully pinned schematic) first, then `pet4032` (same board, BASIC 4), then the CRTC rows `pet8032` and `cbm8032`; the static `pet2001` after its sheet 1 is in hand. 2. **The 6520.** Recommend a `mos6520` row of the proposed **`m6821-python`** (williams, coco), not a separate core: MOS's own note says it is functionally the MC6820 and differs from the MC6821 only electrically. 3. **The 6522.** Recommend pinning the shared **`mos6522-python`** (the name vic20, bbcmicro, oric and plus4 use; c64-python says `via6522-python`): one name to settle. 4. **The CRTC.** Recommend a 6545-1 row (status register, addressing mode, MOS82 p. 6-9) in the proposed **`crtc6845-python`** (bbcmicro, cpc). 5. **The 2031.** Recommend a **`c2031` row in `c1541-python`** with an `Ieee488Bus` front end in place of the IEC one. 6. **The 2040/3040/4040/8050/8250/SFD-1001.** Recommend one drive board (`cbm-ieee-drives-python`, name provisional) built after M6's socket, an upstream request to 6502-python for a **6504 package row** (13 address lines, no NMI/RDY/SO), and extracting **`riot6532-python`** from a2600-python then (its third user). 7. **The CBM-II.** Recommend a separate **`cbm2-python`** (B and P rows) after c64-python's CIA and SID are extracted, with a **6509 variant** requested from 6502-python then; not a row of this board. 8. **The SuperPET.** Recommend deferring it until `m6809-python` has a core. 9. **Documents only on zimmers as PDF** (its robots.txt disallows PDFs): the static board's sheet 1 (`schematics/computers/pet/2001/320008.pdf`), the 8032 technical manual, the 64K expansion guide, the 8050 schematics. Recommend you fetch these few by hand into `reference/` (facts then cited as from your copy), or let the next agent search archive.org and the bitsavers mirror for other copies first. 10. **MAME's PET files are BSD-3-Clause** by their `license:` lines. Recommend keeping them closed (run only), as the brief says and as the PlayStation and VIC-20 decisions do, until you decide whether BSD MAME files may be read as documentation. 11. **GitHub's robots.txt** has a section for AI agents (ClaudeBot, Claude-User and others) disallowing `/raw/`, `/tree/`, archives, tarballs and `.git` paths. This Phase 0 made one sparse git fetch of VICE-testprogs (paths not in the list; vic20-python and vectrex-python pin the same commit) and read MAME header lines from raw.githubusercontent.com (no robots rules). Recommend you confirm git fetches and the raw host are acceptable, or name an alternative (VICE's own SourceForge repository). 12. **sources.md rows** (seven, in [sources.md](sources.md)): recommend adding them, including the correction that funet.fi `/pub/cbm` now redirects to zimmers. 13. **Remote.** Recommend local until M1 passes, then a private GitHub remote.