# Build progress (so another agent can resume from the repository alone) Built to `docs/handoff-brief.md`, one rung per commit, in order 1 to 6. A private GitHub remote (`alewman/w65c02-rust`); pushes are Aubrey's call. The numbers are in `docs/status.md`; this file is the state, the traps and what is next. ## How to work here - `scripts/env.sh` says where everything outside the repository is, by environment variable: `W65C02_PYTHON` (default `../w65c02-python`, which must be at `e49aceb` with a clean `src/`: the rung scripts refuse otherwise), `REFERENCE_PYTHON` (its `.venv-pypy`), the corpus, the test programs and the captures inside its `reference/` (its own `fetch_references.py` and `build_tools.py` fill it; nothing is re-downloaded here). - `cargo build --release`; each `scripts/rungN.sh`; `scripts/ladder.sh` for all of them. - `src/dispatch.rs` is generated: `$REFERENCE_PYTHON scripts/gen_dispatch.py` (its prose and code are `scripts/dispatch_header.rs.in` and `scripts/dispatch_footer.rs.in`; edit those, not the output), then `cargo fmt`. - `cargo clippy` on this machine is an old snap (clippy 0.1.78) that cannot build a crate needing rustc 1.85; use the rustup stable toolchain: `PATH=~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin:$PATH cargo clippy --release --all-targets -- -D warnings` (clippy 0.1.99 passes). - At most 4 processes, `nice -n 19`, `PYPY_GC_NURSERY=1M` (env.sh sets it). ## Rungs | Rung | State | | --- | --- | | 1 trace lockstep, short programs | **passed** (see status.md) | | 2 SingleStepTests | **passed**: counts identical to the reference's | | 3 Dormann and Clark natively | **passed**: counts identical to the reference's | | 4 capture lockstep; interrupt, WAI, STP scenarios | **passed**: all 168M captured instructions, reports identical; 80/80 scenarios | | 5 the frame carries the rows, no NMOS code | **passed** | | 6 seeded faults | **passed**: 46 of 46 caught | **All six rungs pass (2026-11-13; again at the `e49aceb` pin, 2026-11-14).** What is left: - CI (`.github/workflows/ci.yml`) runs fmt, clippy, tests and rung 5; the other rungs stay local because the reference is private. - Re-pin when w65c02-python moves: change `W65C02_PYTHON_PIN` in `scripts/env.sh`, carry every comment change in its `src/` into the same place here (the dispatch's into the `.in` templates), regenerate `src/dispatch.rs`, refresh `conformance/expected/*.txt` from the reference's new numbers, check every seeded fault's text still occurs once (a carried comment can split one), run `FAULTS=1 scripts/ladder.sh`. The `9ca4a2f` to `e49aceb` repin (comments and documents only) went this way. - 6502-rust's last pushed commit is `71747eb`; if it moves, re-pin the git dependency in `Cargo.toml` and run the ladder. - The reference's rung 9 (`cpu.lnx` on the Lynx board) belongs to a future `lynx-rust`; `w65c02-rust-fast` is the next tier when a target needs it. - Evidence tags (MEASURED, DOC, OBSERVED, TEST ROM, HYPOTHESIS) sit beside the source keys exactly where the reference (`e49aceb`) puts them; the interim key-to-tag mapping that `src/core.rs`'s header held before is gone, replaced by the reference's own legend (it had GF as MEASURED; the reference counts GF's bench notes as DOC). ## Traps - The seeded-fault script caches the reference's traces as hashes (`external/faults/reference-hashes.json`, keyed by the reference's commit and each scenario's text); the control run must match them. Fault trees are written anew (fresh timestamps), each slot builds into its own target. - The scratchpad of this session was shared with another agent: commit messages are written to uniquely named files. - The reference's trace reader decodes instruction bytes **for a row**: compare with `read_trace(stream, row)`, or a trace of `$07` on the G65SC02 is rejected (one byte, not two). `scripts/compare_traces.py` takes the row. - The capture replay starts the six mid-run captures where the reference's `decoder_start` says (it runs the GPL `decode6502` as a black box); `scripts/capture_starts.py` asks it once and caches `external/capture-starts.json`. The replay reads the unpacked captures in the reference's `reference/build/` (`$CAPTURES`), Foot's as `foot_data14.bin` there (checked equal to the decompressed `.gz`). - The reference raises `Mismatch` inside a bus callback; the Rust replay panics with a `Mismatch` payload and catches it around `step()`, so the CPU is left mid-instruction as the Python one is (the R65C02 reset capture's V flag is learnt that way, from a mismatch at the first `PHP`). - Random-memory scenarios: each seed is one path (a reset re-enters at the same random vector), hence 16 short seeds per row rather than one long run; the W65C02S ones spend many cycles stopped by `STP`. - The Python core keeps `sync`/`fetch`/`opcode` as attributes a callback reads; here they arrive as `Signals` with each callback (with `pc`, which the capture replay's paging model reads).