# Status 2026-11-23 (the runs; this line rechecked 2026-11-25). **The ladder passes: all five rungs.** The crate is proven identical to ay8910-python at the pin below on every stream listed. Used by famicom-rust's and famicom-rust-fast's mapper 69, which pin this crate at `9b670a7`. Reference: ay8910-python `a3bb48511db96356581b010e87a6476eaa03e9bc` (its `main`, 2026-11-22), cloned into the git-ignored `external/ay8910-python` and installed, after uninstalling any older copy, into the PyPy venv `external/venv` (`scripts/fetch_ay8910python.sh`, which also checks that the installed files are the clone's, byte for byte). Run on Linux x86_64, rustc 1.93.1 (rustfmt and clippy from the rustup stable toolchain), the reference on PyPy 7.3.23 (Python 3.11.15) with `PYPY_GC_NURSERY=1M`, everything under `nice`. ## How it was built A transcription of ay8910-python alone ([provenance.md](provenance.md)): - Transcribed, not redesigned: method for method, same order, same names (Rust case conventions aside), same comments and citations. Where Rust forces a difference the module header says so (summarised below). - The parts stay data (`PSGVariant`), with ayumi's MIT notice beside its table. - Where the Python looks wrong it is not fixed here: behaviour stays identical, and the case is listed under "Looked at in the reference". ## The rungs | Rung | What | Result | Command | | --- | --- | --- | --- | | 1 | `cargo fmt --check`; clippy `-D warnings` with and without `serde`; every test of ay8910-python's `tests/test_chip.py`, `test_variants.py` and `test_conformance.py` transcribed (`tests/chip.rs`, `variants.rs`, `conformance.rs`; parametrized cases as loops), with the 19 conformance examples vendored and traced; the tables checked bit for bit against Python's formulas; the save-state test; the README's examples | 60 of 60 test functions pass (the reference's 207 fast cases, but for `test_make_examples_is_reproducible`, which runs a Python script of the reference's); 19 of 19 example traces identical | `scripts/rung1.sh` | | 2 | Bus-stream lockstep: 240 seeded scripts, 48 for each part (`scripts/lockstep_gen.py`), of writes of every register with any byte and with the values that matter, bare address bytes (deselecting ones too), bare data bytes, reads and `read_register` of every register, the ports' pins and directions listened to or not, /RESET, the /SEL pin, `run` and the polled `tick` path by every length, `record` on and off; scripted envelope restarts on each of the eight phases with the counter odd and even (both halves of the divider), period 0 and 1 for tone, noise and envelope on every phase, periods shortened while the strobe is open, every mixer value. Compared byte for byte: every clock's three codes (SHA-256 per take or poll), every read, every port change, every `mix()` and `take_samples()` float as bits, the whole state at checkpoints, every part's fields and the DAC tables | 240 of 240 identical: 363,181 data writes, 26,363 reads, 26,685 port changes, 40,781,708 clocks' codes, 1,878 state checkpoints | `scripts/rung2.sh [count] [seed] [steps]` | | 3 | ay8910-python's own validation streams (`scripts/export_streams.py`): the 24 synthetic streams of its `scripts/streams.py` on all five parts, replayed as its referee replays them; and its 7 board streams (*Gimmick!*, 2,400 frames, and rainwarrior's six 5B tests, recorded from famicom-python) as the Sunsoft 5B in CPU clocks and as the AY-3-8910 at half the clock. Every clock's codes (SHA-256 per 65,536-clock take), every read and port change, the final state | 134 of 134 identical (120 synthetic, 14 board): 529,772,275 input clocks' codes | `scripts/rung3.sh` | | 4 | Save states mid-stream: rungs 2's and 3's scripts again, this crate's chip saved and restored (serde_json, then bincode; each restored copy required equal to the chip it came from) at every `save`, `state` and `take` line, the restored copy running on; the traces compared with the same reference traces | 374 of 374 identical: 21,786 round trips (13,147 in rung 2's scripts, 8,639 in rung 3's) | `scripts/rung4.sh` | | 5 | Seeded faults (`scripts/seeded_faults.py`): ay8910-python's 61 of `scripts/mutation.py`, the same rules broken in the Rust text, and 6 of this crate's own (3 in the port queue, 3 in the save state); the unbroken copy judged first | 67 of 67 caught; every one by rung 1 and by rung 4, 64 by rung 2, 62 by rung 3 | `scripts/rung5.sh` | `scripts/ladder.sh` runs rungs 1-4 and the speed report; `scripts/ladder.sh --faults` adds rung 5. `cargo test --release --features serde` (rung 1) needs nothing else; CI runs it with `cargo fmt --check` and clippy, on main and pull requests. Rungs 2 to 5 need the reference; `PYTHON=` names another interpreter, `AY8910_PYTHON=` another reference checkout, `AY8910_BOARD_STREAMS=` the board streams (default: `../ay8910-python/validation/streams`; without them rung 3 runs the synthetic streams only and says so), `JOBS=` the parallelism (default 6). Traces go to the git-ignored `external/lockstep/` and `external/streams/`; to find where a script differs, change its second line to `mode full` and run both sides on it (`external/venv/bin/python scripts/lockstep_ref.py SCRIPT`, `cargo run --release --features serde --example ay8910-trace -- SCRIPT`). ## Seeded faults Run 2026-11-23 (`scripts/rung5.sh`, 4 copies at a time, about 40 minutes on a shared machine). The unbroken copy passes rungs 1 to 4 first. Then: | Rung | Faults it notices (of 67) | | --- | ---: | | 1, any test file | 67 | | 1, `tests/chip.rs` (test_chip.py) | 60 | | 1, `tests/conformance.rs` (the 19 examples) | 60 | | 1, `tests/variants.rs` | 6 | | 1, `tests/save_state.rs` | 3 | | 2, lockstep | 64 | | 3, the reference's streams | 62 | | 4, save states mid-stream | 67 | | **any** | **67** | What each misses, and why: - **Rung 2 misses the three save-state faults** (65-67: a field left out of the save state): rung 2 never saves. Rungs 1 (`save_state.rs`) and 4 catch all three. - **Rung 3 also misses the two DAC-table faults** (58, 59): its streams compare codes and state, not levels. Rung 1 (`variants.rs`, the formulas bit for bit) and rung 2 (the `tables`, `mix` and `samples` lines) catch both. - **The 19 conformance examples alone miss 7**: the two DAC faults and "a deselecting byte moves the latch", as ay8910-python's `mutation.py --examples-only` finds (58 of 61), plus this crate's "a port is told when nothing changed" (the trace's `P` lines record only changes) and the three save-state faults. ay8910-python calls the latch fault "an equivalent mutant at the pins"; here rung 2's state checkpoints, which print the latch, catch it, and so do rung 3's. - Fault 15 ("noise register sixteen bits") made the transcribed `test_the_noise_register_repeats_after_131071_steps` loop for ever, as an unbounded loop does in Python; the Rust test is bounded at 2^17 + 1 steps so that it fails instead (re-run alone: caught by rung 1 chip, conformance, rungs 2, 3, 4), and the fault script now times a test run out after 15 minutes. The faults, in `scripts/seeded_faults.py`'s order: 1-61 are ay8910-python's `mutation.py` list under its names (the strobe and count phases, the tones' reset state and comparator, period 0, the open strobe, the noise register's taps, width, start, polarity and halving, the envelope's halving, period 0, both halves of the restart, its shapes, the mixer, the Yamaha codes, the address latch and internal bus, the ports, the divider, reset, and the parts' data); 62-64 break the port queue that stands for Python's callables; 65-67 leave a field out of the save state. ## Speed `scripts/speed.sh` (`examples/speed.rs`, `scripts/speed_ref.py`), release build, on this shared machine (load average about 9), 2026-11-23. Reported, not a gate: a reference transcription, not tuned. | Path | ay8910-rust | ay8910-python on PyPy 7.3.23 | | --- | ---: | ---: | | Sunsoft 5B at 1,789,773 Hz, polled as a board polls it (`tick`, `levels`, `mix` on a change) | **261 x real time** | 32.5 x | | AY-3-8910 at 1,773,400 Hz, `run` and `take_samples` | **77 x real time** | 3.9 x | The polled path is the one famicom-rust uses: at 261 x the 5B costs well under 1% of a real-time NES frame. (The two sides count `mix` calls differently: the Python script, like famicom-python, tests `levels()` by identity, which is a new tuple at every strobe; the Rust compares values.) ## The API a board uses The README's table maps ay8910-python's contract onto this crate. famicom-python's mapper 69 calls, and so famicom-rust calls: `PSG::with_record(SUNSOFT_5B, false)`, `select(value)` on $C000-$DFFF, `write(value)` on $E000-$FFFF, `tick()` once per CPU cycle, `levels()` each cycle and `mix()` when the levels change, `reset()`; for a save state, the `serde` feature. ## Rust-forced differences Each module's header lists its own. In short: - **The ports.** Python's `port_a_in`/`port_b_in` callables are `Option` levels the board sets; Python's `port_a_out`/`port_b_out` callables are flags, and the changes they would have been told are queued for `take_port_changes()`, in the same order, at the same places. - **Private attributes are public fields** without the underscore (`levels_now` for `_levels`), for save states and the lockstep's state dump. - **`PSGVariant`'s values are `const`s**, written out field by field; `name`, `ports` and `dac` are `Cow`s, so a restored variant owns its data. The computed DAC tables are written out as Python's numbers and checked against the formulas bit for bit. - **The conformance kit** reads JSON with a small reader of its own (the crate has no dependencies); its command line is a function and a binary, with Python's commands, output and exit codes. - **Save states** (the `serde` feature) are this crate's addition; Python's state is plain attributes. ## Looked at in the reference Nothing in ay8910-python's engine looked wrong: every rung is equal, and the transcription met no rule that disagreed with its documents. Two small things in its conformance kit, on malformed input only (the examples are unaffected), reported here and not fixed (fixes start upstream): - `manifest_from_dict` accepts a negative `clocks` and runs it as 0, and coerces types it should refuse: `{"version": true, "name": 7, "clocks": "12", "events": [[0.0, "write", true, 1]]}` loads, with `version` `True`, `name` `'7'`, `clocks` 12 and an event at `t=0.0`, `a=True`. Repro: `python -c "from ay8910_python.conformance import manifest_from_dict as m; print(m({'version': True, 'name': 7, 'variant': 'AY-3-8910', 'clocks': '12', 'events': [[0.0, 'write', True, 1]]}))"`. This crate refuses such manifests. - `docs/conformance.md` and `contract.md` describe what a port must reproduce; neither says that `reset()` leaves the ports' last driven levels in place (so a reset tells the board $FF for a port that was an output). Both cores do that; it is only undocumented.