# ay-die-model A headless Icarus Verilog testbench around lvd's transistor-level Verilog model of the AY-3-8910, made from deathsoft's schematics of the decapped die (lvd2/ay-3-8910_reverse_engineered). It drives the chip's pins from an event file and samples its three channel codes and both ports clock by clock. Version 0.1.0 (`CHANGELOG.md`). Regrouped on 2026-11-24 from `tools/ay8910-python/` (ay8910-python's referee driver, gathered here on 2026-11-22); the tool now fetches, patches and builds its upstream itself, and `run.py` speaks the family's tool contract, version 0 (`emu-tools/docs/contract.md`), for its manifest, command line and exit codes. The testbench's own command line and outputs are as they were. ## Paths Under **`$EMU_TOOLS_GPL`** (a checkout of `emu-tools-gpl`): | Path | What | | --- | --- | | `tools/ay-die-model/build.sh` | fetches the model at the pin, patches a copy, compiles the testbench | | `tools/ay-die-model/build/ay_ref` | the compiled testbench, run with `vvp` (git-ignored) | | `tools/ay-die-model/build/ay_model_icarus.v` | the patched copy of the model it was compiled from (git-ignored) | | `tools/ay-die-model/build/build-info.json` | Icarus version, flags, upstream commit, patches | | `tools/ay-die-model/run.py` | the contract's command line | | `tools/ay-die-model/tests/smoke.py` | the smoke test | | `tools/ay-die-model/ay_tb.v` | the testbench's source (old location: `tools/ay8910-python/ay_tb.v`, now a link to this file) | | `tools/ay-die-model/patches/trireg-keepers.patch` | the Icarus port of the model (below) | ## Build OSS_CAD_SUITE=DIR "$EMU_TOOLS_GPL/tools/ay-die-model/build.sh" Needs Icarus Verilog (`iverilog`, `vvp`) on the PATH or under `$OSS_CAD_SUITE/bin` (the YosysHQ oss-cad-suite bundle has both), and `patch`. The script clones into `upstream/` (git-ignored) at **`cf8d14db0aec5ae86ed4f4e6e67bf14c40a42d77`**, checking out only `rtl/` and the top-level files (the schematics and PDFs are not fetched); a clone with local changes stops it, and it never deletes anything. Icarus has no `trireg` (a net that keeps its last driven value while nothing drives it), so `patches/trireg-keepers.patch` is applied to a copy of `rtl/ay_model.v` in `build/ay_model_icarus.v`: each of the model's six trireg nets becomes a plain wire with a weak keeper (a module defined in `ay_tb.v`) that holds the same charge. The script checks that no trireg is left and six keepers are in. It is the change ay8910-python's `validation/icarus_port.py` makes, kept as a patch file (the contract's rule: patch files, not forks). Then `iverilog -g2012` compiles `ay_tb.v` with the copy into `build/ay_ref`. Seconds. Gated on 2026-11-24 against ay8910-python's own `validation/build_referees.sh`: the patched model is byte-identical to the copy that script makes, the compiled testbench is identical once the run-to-run pointer values and the absolute file names Icarus writes into it are set aside, and the consumer's 31 streams give byte-identical outputs (the longer ones capped at 400,000 clocks; `CHANGELOG.md`). ## The testbench (`build/ay_ref`) vvp "$EMU_TOOLS_GPL/tools/ay-die-model/build/ay_ref" +events=EVENTS.hex +count=N +out=OUT.bin +reads=READS.bin +clocks=CLOCKS `EVENTS.hex` holds one 64-bit hex word per line, sorted by clock: the clock (40 bits), the event kind (8 bits), then two bytes `a` and `b`. Kinds: 0 select register `a` and write `b` to it; 1 select register `a` and read it; 2 and 3 drive port A's or port B's pins with `a` (while the port is an input); 4 pulse /RESET over one extra clock that is not counted or sampled; 5 latch the address byte `a` alone; 6 write `b` alone to whatever is selected; 7 read alone. An event is applied before the rising edge of the clock it names; clock 0 is the first clock after the one the power-on /RESET is released in. At most one event a clock, at most 4,194,304 events. `OUT.bin` gets one little-endian 32-bit word per clock, sampled after the falling edge: channel A's, B's and C's DAC codes (4 bits each, 0 to 15, bits 0 to 11), port A's pins (bits 12 to 19) and port B's pins (bits 20 to 27). `READS.bin` gets one 32-bit word per read, the data bus in the low byte. The data bus at rest is pulled low. ## run.py (the contract) python3 -I run.py --input EVENTS.jsonl --cycles N --out DIR python3 -I run.py --version `EVENTS.jsonl` is JSON Lines, one event a line: `t` (the clock), `kind` (0-7, above), `a` and `b` (0-255, default 0). `--cycles` is the number of input clocks run and sampled. Writes `ay.bin` (format `ay-die-model/pins`, layout `, pinned at **`cf8d14db0aec5ae86ed4f4e6e67bf14c40a42d77`**. LICENSE: the GPL-3.0 text; `rtl/ay_model.v` grants "either version 3 of the License, or (at your option) any later version". Not committed here. - **`ay_tb.v`:** our code (alewman), first published under MIT in ay8910-python (`../../notices/MIT-emulator-family.txt`); it keeps its MIT header. `build.sh`, `run.py`, `tests/smoke.py` and the patch are new here, GPL-3.0-or-later; the patch carries the model's context lines. Its added lines are the output of ay8910-python's MIT `icarus_port.py`. Compiled with the model, the testbench is a GPL-3.0-or-later work; this repository is GPL-3.0-or-later (`../../LICENSE`). If a build is ever shared, its source, this folder and the model at its pin go with it. - Checked against `emulator-lineage/docs/sources.md`.