# Build progress (so another agent can resume from the repository alone) The build session followed `docs/handoff-brief.md`: the rungs of `docs/validation.md`, one per commit, in the order 0, 1, 2, 3, 4, 6, 5, 7, 8. **All nine are passed (2026-11-12).** Rung 9 needs the Lynx board and is not this session's. Local git only: no remote, nothing pushed. ## How to work here - `.venv` (CPython 3.14.4) and `.venv-pypy` (PyPy 7.3.23, Python 3.11.15) are made with `python3 -m venv .venv` / `pypy3.11 -m venv .venv-pypy` and `pip install -e ".[dev]"` (the dependency is `6502-python` at `741419a`, fetched from GitHub by commit). - Lint: `.venv/bin/ruff check .` and `.venv/bin/ruff format --check .` (ruff 0.16.8, the siblings' pin; its default rule set wants scripts executable). - Quick loop: `.venv/bin/python -m pytest -m "not slow"` (861 tests, about a minute). Everything: `.venv-pypy/bin/python -m pytest` (885 tests). - The smoke list of the brief, as commands: .venv-pypy/bin/python -I scripts/run_single_step.py --limit 100 .venv-pypy/bin/python -I scripts/run_programs.py --row g65sc02 .venv-pypy/bin/python -I scripts/run_capture.py master reset .venv/bin/python -m pytest tests/test_directed.py tests/test_tooling.py - The whole gates (PyPy, at most four processes, `PYPY_GC_NURSERY=1M nice -n 19`): `run_single_step.py` (30 s), `run_capture.py` (2 to 5 minutes), `run_programs.py` (1 minute), `run_mame_replay.py` (3 minutes, needs the traces), `seeded_faults.py` (45 minutes). - Anything that reads `reference/` (gitignored, 2 GB, already fetched and built on this machine) or `tests/mame_traces/` (gitignored, 2.2 GB of MAME traces recorded with `scripts/mame_trace.py --bus`) skips with a hint when it is missing. ## Rungs | Rung | State | Judge, tier | Measured | | --- | --- | --- | --- | | 0 tables | **passed** | DS Table 5-2 and 7-1, GDS Tables IV and V (tier 2); CAP counts (tier 1); SST grid as detector | `tests/test_tables.py`: 212 / 210 / 178 / 210 documented opcodes per row; all 178 of GDS Table IV by bytes and cycles with three stated exceptions (BRA, BRK's second byte, C11); 253 opcodes against the counts measured on two real parts; the corpus grid differs in exactly C1, C2, C3. CPython and PyPy | | 1 SingleStepTests | **passed** | SST 65x02, three CMOS sets (tier 5, detector) | `scripts/run_single_step.py`: 7,660,000 cases, 0 fail; 5,777,843 pass in full; 1,882,157 counted under a named contradiction (C1, C2, C3, C10 as the exit named, and the new C13 to C18) with the reduced comparison. Same counts on CPython. Numbers per class in validation.md | | 2 Dormann | **passed** | self-checking; tier 1 for G65SC02 and R65C02 | `scripts/run_programs.py`: the extended test reaches `$24F1` / `$2569` / `$2434` / `$2569` on W65C02S / R65C02 / G65SC02 / Lynx2Cell (22.0 million instructions each), the NMOS functional test `$3469` on all four (30.6 million). A wrong CMP carry traps; each image fails on the wrong row | | 3 Clark decimal | **passed** | self-checking; tier 1 for G65SC02 and R65C02 | `ERROR` = 0 on all four rows (18.4 million instructions each), pre-filled; one wrong sum, or V from the binary sum, fails it | | 4 capture lockstep | **passed** | CAP (tier 1): a G65SC12 and an R65C02, eight captures | `scripts/run_capture.py`: 83,856,649 + 84,037,666 instructions, 65,772 interrupt entries, 2 resets; 0 mismatches (RnW, SYNC, written bytes, cycle counts), 0 model differences in 502.7 million reads compared. It decided the dummy-read addresses (table in validation.md) | | 4b Foot's capture | **passed** | CAP, data bus only | 1,471,138 instructions on W65C02S and on R65C02: 0 written-byte differences, 0 model differences; cannot tell the two rows apart; G65SC02 falls out of step at the first bit instruction | | 6 directed | **passed** | data sheets (tier 2), CL LK GF GW LT (tier 3), CAP where it settled the entry | `tests/test_directed.py`: 341 tests, every one of the 32 U and C entries has a test named for it and citing it. CPython and PyPy | | 5 MAME lockstep | **passed** | MAME 0.285 (tier 5, detector) | `scripts/run_mame_replay.py`: lynx, bbcm, apple2ee on G65SC02 and cexpert on R65C02, 5,093,752 instructions and 2,470 interrupt entries: no register or written byte differs; 65 cycle counts differ (57 `abs,X` shifts: MAME 7, core 6, C19; 8 `STZ $FD91`: MAME's CPUSLEEP hold). Beyond the exit: cmmb103 and arbv2 on W65C02S, 10,694,568 instructions and 1,306 interrupt entries, no difference | | 7 fault injection | **passed** | every rung above, on a faulted copy of `src/` | `scripts/seeded_faults.py`: 44 faults, 44 caught, none by rung 1 alone; 37 by a tier-1 judge (rung 4 catches 31), 7 by the directed tests only. Matrix in validation.md | | 8 tooling | **passed** | 6502-python's hooks; the data sheets for the disassembler; MAME's tables and `da65` as detectors | `tests/test_tooling.py`: 60 tests, CPython and PyPy; 256 opcodes x 4 rows disassemble to rung 0's mnemonics and lengths | | 9 `cpu.lnx` on the Lynx board | **not this session's**: needs `lynx-python`'s milestone 2 | LT (tier 3) | not run | Speed, for the record (not a goal: this is the reference core): Dormann's functional test on a bare `bytearray` host, measured on a machine under load (60 or more): CPython 3.14 1.1 million instructions a second (3.5 million cycles: 0.87 of a Lynx's 4 MHz); PyPy 8.9 million instructions a second (28 million cycles: 7 times a Lynx). ## Decisions made in the build - Classes: `W65C02S`, `R65C02`, `G65SC02`, `Lynx2Cell`, all subclasses of `CMOS65C02` (the instruction core; not a part). A row is class attributes: `bit_instructions`, `wai_stp`, `reset_writes_stack`, `one_cycle_nops_poll`, `nop_5c_reads`, `nop_dc_fc_reads`. The opcode table is built once per class. - `step()` returns the opcode's base count plus `_extra` (as `6502-python`); every runner asserts it equals the number of callbacks. - **The dummy-read addresses are the captures', not the corpus's.** The capture lockstep was built before rung 1 was run, because it is the tier-1 judge and it contradicts SingleStepTests in seven kinds of dummy read (new entries C13 to C18, and C10). Rung 1 therefore counts those cases by name with a reduced comparison instead of passing them. - `cpu.fetch` is True exactly when the address on the bus is the program counter (handoff-brief.md, "The contract as built"). - The capture replay lives in `tests/capture_replay.py`, not in `w65c02_python.harness` as the brief's layout sketched: it is a judge that needs `reference/`, not part of the product. `w65c02_python.harness` is the flat-memory host only. - New entries: C13 to C18 (the corpus's dummy addresses against the captures), C19 (MAME's 7-cycle `abs,X` shifts against the data sheets and the captures). U4 is mostly closed. ## What is left - **Rung 9**, with `lynx-python`: `cpu.lnx` on the board, `G65SC02` for the Lynx I and `Lynx2Cell` for the Lynx II. - Open decisions of the brief that were deferred by their own wording: 7 (more rows: later), 8 (ask upstream for a W65C02S reset capture and a run of Dormann's `wdc_op = 0` build on real non-WDC parts: "decide after rung 4"; the list of what the captures could not settle is in timing.md, "What the captures could not show"), 9 (public after rung 1: the user's call), 10 (Rust and `-fast` forks: not now). - No tier-1 evidence exists for: the W65C02S's reset (U1) and its `WAI`/`STP` beyond bench notes; the Lynx cells (U2, U10, C12 beyond LT); `$CB`/`$DB` on parts without `WAI`/`STP` (U3); the poll (U5, U6, U7); `BRK`'s bus on a real part; the seventh cycle of `BBR`/`BBS` and of the `abs,X` shifts. - The RDS scan and the NCR data book were not re-read in the build; rung 0 rests on DS and GDS (and CL for the bit instructions). ## Traps found - **Never write `self._read(self._fetch())`** or `self._write(mode(self), value)`: Python looks `self._read` up before it runs the inner call, and the frame replaces `_read`/`_write` with confirming wrappers when a bus callback changes an interrupt request. The nested form bypasses the wrapper, and a request made in the second-to-last cycle is then treated as made in the last. Found by a rung 6 test; no corpus, program or capture sees it (they do not change requests inside callbacks). Compute the address in its own statement. - **SingleStepTests files are JSON arrays with one case per line**, and the first or last case can share its line with the bracket: strip `[`, `]` and `,` or 25 cases a set go missing. - **`ruff format .` rewrites Python code blocks inside Markdown** (ruff 0.16.8): it re-spaced snippets in `docs/handoff-brief.md` and `README.md`. Harmless, but look at `git diff` after formatting. - **The capture decoder numbers samples from 1** (`decode6502 -Y`): the raw index is one less. - **The corpus's `p` has a B bit** (set in half the initial states, cleared by its `PLP`/`RTI`): drop it going in, do not compare it coming out. - **SST's address for the decimal cycle of the immediate forms is a constant per file** (`$007F`, `$0059`, `$0000`...), not related to the instruction. - BBC paging matters to the capture replay's memory model: ROMSEL and, on the Master, ACCCON (shadow memory, the RAM over the MOS). A write to ROM does not stick; the model learns that from the first read that contradicts it. - **A reset capture does not give the flags**: the R65C02's V was unknown until its first `PHP`, 158,777 instructions in. The replay restarts with the flag as the chip had it and says so. - **MAME's trace line is written when the opcode has been fetched**: with `--bus` the opcode's read comes before its line, and a line followed by an interrupt entry is an instruction that did not run (mame-oracle.md). - `scripts/seeded_faults.py` starts every judge from the working tree: do not edit `src/` or `tests/` while it runs. - Machine load matters to nothing but wall time; the full lockstep took 81 seconds once and 4.5 minutes another time. ## Requests to sibling repositories (none made; nothing was changed there) R1 to R5 of the brief stand; none was needed to build. As found in the build: - **R1, `6502-python`**: `note_stall()` from a write callback works as the brief expected; `tests/test_directed.py::test_u12_...` holds it here. The request is still only its docstring and a test there. - **R3, `6502-python`**: `self._polled = NO_POLL; self._deferred = None` in a subclass handler is what the one-cycle NOPs do (`_nops.py`); listing it as a supported use would cover it. - **R6 (new), `6502-python`**, documentation: say in `docs/api-stability.md` that a subclass must look `self._read` and `self._write` up at the moment of the access (not hold them, and not write `self._read(self._inner())` where the inner call makes bus accesses), because the frame swaps those attributes when a callback changes a request. See the first trap above. - **R4, `huc6280-python`** (optional): this core's `w65c02_python._alu.decimal_add` and `decimal_subtract` are now the tier-1-backed 65C02 reference it could compare its two formulas with. - **R5, `lynx-python`**: the contract as built is in handoff-brief.md. Three things the board will notice: reset writes three bytes to the stack on both Lynx rows (U2); an indexed store that does not cross a page reads its target before writing it (C14: `STA $FDxx,X` reads the register); and the dummy reads of `zp,X` and `(zp),Y` are at PC+1 and at the pointer, not where SingleStepTests has them.