# nuked-harness One family of closed-box harnesses around four of Nuke.YKT's die-derived chip models, built from their pins and nothing else: Nuked-OPN2 (YM2612, YM3438), Nuked-OPLL (YM2413, DS1001), Nuked-PSG (the SN76489-family PSG) and Nuked-OPM (YM2151, YM2164). Version 0.1.0 (`CHANGELOG.md`). `run.py` speaks the family's tool contract, version 0 (`emu-tools/docs/contract.md`), for its manifest, command line and exit codes; the record streams are tool-specific formats described below. Regrouped on 2026-11-23 from the harnesses gathered here one folder per consumer on 2026-11-22 (ym2612-, ym2413-, sn76489-, ym2151- and megadrive-python). Those folders keep their old file names as one-line shims that include the family's sources, so each consumer's own compile command builds the same program (gated: the stripped binaries are identical, and the consumers' closed-box runs give the same output before and after). ## What it measures What each model's public header lets a caller see, clock by clock: the FM chips' output words and status byte (with BUSY and the timer flags), the OPN2's IRQ pin, the OPM's serial-output pins (SO, SH1, SH2), its IRQ, CT1 and CT2 pins and its decoded DAC levels, the PSG's output level and its four channel attenuations as its read call reports them. **No internal node of a model is exported**: each harness calls only the functions its model's header declares and allocates the model's state structure without looking into it (one exception was removed at the regrouping, below). **Every output is OBSERVED** (the model at its pin, via nuked-harness 0.1.0): a closed-box measurement of a die-derived model, never a hardware fact, overruled by any document or hardware measurement that disagrees. The consumers use these models as detectors, not judges. ## Upstreams, licences and pins | Model | Author | Licence (as checked at the pin) | Pin | | --- | --- | --- | --- | | Nuked-OPN2 | Nuke.YKT (nukeykt) | LGPL-2.1-or-later (header grant) | `335747d78cb0abbc3b55b004e62dad9763140115` | | Nuked-OPLL | Nuke.YKT | GPL-2.0-or-later (LICENSE: GPL-2.0 text; header grants "any later version") | `1269cf5a783b65583b50fa2464d08be75830aaa0` | | Nuked-PSG | Nuke.YKT | GPL-2.0-or-later (header: "GPLv2+") | `d15a168c676f4669e23660be9225b34ad7c1764e` | | Nuked-OPM | Nuke.YKT | LGPL-2.1-or-later (header grant) | `f209e6ed3712032b641d53ce8fb24824eae6adc3` | Each is fetched from `https://github.com/nukeykt/` and never committed here. No patches. The harness sources are ours (alewman), first published under MIT in the consuming repositories; each keeps its MIT header (`../../notices/MIT-emulator-family.txt`). Built with its model, each binary is a combined work under the model's licence; this repository is GPL-3.0-or-later (`../../LICENSE`). If a built harness is ever shared, its source, this folder and the model at its pin go with it. Checked against `emulator-lineage/docs/sources.md` (Nuked models: closed box only on the MIT side). ## Build `./build.sh` clones the four models into `upstream/` (git-ignored) at their pins and compiles the six harnesses into `build/` (git-ignored) with `cc -O2 -w`, the consumers' flags (the warnings would quote the models' source; `CC` and `CFLAGS` override). It writes `build/build-info.json` (compiler, flags, the four commits), which the manifest quotes. It never deletes anything. Seconds on this machine once the models are fetched (2026-11-23). | Binary | Source | Model | First used by | | --- | --- | --- | --- | | `opn2-stream` | `src/opn2_stream.c` | Nuked-OPN2 | ym2612-python (rung 6) | | `opn2-events` | `src/opn2_events.c` | Nuked-OPN2 | megadrive-python (withdrawn) | | `opll-stream` | `src/opll_stream.c` | Nuked-OPLL | ym2413-python (rung 6) | | `psg-stream` | `src/psg_stream.c` | Nuked-PSG | sn76489-python (rung 5) | | `psg-events` | `src/psg_events.c` | Nuked-PSG | megadrive-python (withdrawn) | | `opm-events` | `src/opm_events.c` | Nuked-OPM | ym2151-python | The binaries keep the command lines and record formats they had (each source's opening comment describes its own): the three stream harnesses read commands on standard input (write a byte to a port, read a port, advance a number of clock calls, set a chip type, a test register or a mute mask, as the model offers) and write fixed-size records to standard output; the three event harnesses read a sorted file of timed writes and write fixed-size records to a file, optionally one record in every N clocks. ## Command line python3 -I run.py --machine CHIP --input WRITES.jsonl --cycles N --out DIR [--stride N] python3 -I run.py --version `CHIP` is `ym2612` or `ym3438` (Nuked-OPN2), `ym2413` or `ds1001` (Nuked-OPLL), `psg` (Nuked-PSG), `ym2151` or `ym2164` (Nuked-OPM). `--cycles` counts the harness's clock calls from reset: for the OPN2 one internal clock (six master clocks; 24 make an output sample), for the OPM one internal cycle (two input clocks; 32 make a sample), for the PSG one input clock, for the OPLL one model clock call (what that is in input clocks, the header does not say: ym2413-python measures it from the output). `--stride N` keeps one record in N. `--version` prints the tool, its version and the four pins. Exit status as the contract says: 0 done, 2 a usage error (a malformed write script among them), 3 a missing input or an unbuilt harness. The write script is JSON Lines, one write a line: `t` (the clock call before which the write is applied), `port` and `data` (0-255). Ports: OPN2 0 to 3 (address and data, part I and II), OPLL and OPM 0 (address) and 1 (data), PSG none (one port). For the OPM a line with `ic` (1 asserts /IC, 0 releases it) drives the reset pin instead. ## Outputs (in `--out`) - `manifest.json`: the contract's run manifest: tool, version, this repository's commit (`-dirty` when the tool's files differ), the model, its commit and licence, the build record, the chip, the write script's SHA-1, the arguments, `"time_origin": "reset"`, the output's record count and layout, and `"evidence": "OBSERVED"`. - `.bin`: little-endian fixed-size records, one per clock call (or per stride), the record layout stated in the manifest as a Python struct format: - OPN2 (`nuked/opn2`): the left and right output words (signed 16-bit) and the status byte (BUSY in bit 7, timer B in bit 1, timer A in bit 0), padded to six bytes. - OPLL (`nuked/opll`): the first two words of the model's output buffer, signed 32-bit each (the header does not name them; ym2413-python reads them as the melody and rhythm outputs, measured from the output). - PSG (`nuked/psg`): the four channel attenuations as the read call reports them (a 4-bit nibble each, tone 1, 2, 3, noise; 15 silent) and the output level (the model's analogue level x 8192, signed 16-bit). - OPM (`nuked/opm`): a pin byte (bit 0 SO, 1 SH1, 2 SH2, 3 IRQ asserted, 4 CT1, 5 CT2), the status byte (bit 7 BUSY, bit 1 timer B, bit 0 timer A) and the model's YM3012 levels left and right (signed 16-bit). SO, SH1 and SH2 are the chip's pins; the levels are a decoded convenience. Owed (a later wave): the contract's own formats for these streams, a WAV of each chip's output at its sample rate and `trace/pins` JSON Lines for the OPM's pins; until then consumers read the documented records above. ## The old entry points (shims) | Shim | Consumer, through | Includes | | --- | --- | --- | | `tools/ym2612-python/nuked_harness.c` | ym2612-python, `YM2612_GPL_TOOLS` (`validation/closed_box.py` compiles it) | `src/opn2_stream.c` | | `tools/ym2413-python/nuked_harness.c` | ym2413-python, `YM2413_GPL_TOOLS` (the same) | `src/opll_stream.c` | | `tools/sn76489-python/nuked_harness.c` | sn76489-python, `SN76489_GPL_TOOLS` (the same) | `src/psg_stream.c` | | `tools/ym2151-python/opm_ref.c` | ym2151-python, `YM2151_GPL_TOOLS` (`validation/build_referee.sh` compiles it) | `src/opm_events.c` | | `tools/megadrive-python/validation/opn2_ref.c`, `psg_ref.c` | none (megadrive-python's withdrawn sound cores) | `src/opn2_events.c`, `src/psg_events.c` | One change of behaviour, in a harness nobody runs: megadrive-python's OPN2 harness read the status byte from the model's state structure; `src/opn2_events.c` reads it through the header's read call on port 0, so the family touches no model internals. Its output is the same (checked 2026-11-23 on a write script that sets BUSY and both timer flags, in both chip modes: identical files). megadrive-python's YM2608-LLE harness (`lle2612_ref.c`) is not a Nuked model; it moved to `emu-tools-gpl2` (`tools/ym2608-lle/`) on 2026-11-24. ## Not folded in here: the Nuked-MD harness The Nuked-MD harness (once the separate repository megadrive-nuked-md-harness, through `NUKED_MD_HARNESS`) is not part of this family. It does not fold in cleanly: it drives a whole-board gate-level model (68000, Z80, VDP, FM, PSG, arbiter, cartridge, controller) through environment variables, with SDL stand-ins and a renamed save-state entry point, built and found by megadrive-python inside that repository's directory, which is a different shape from this family's chip harnesses; and its licence needs a call first: several of the Nuked-MD files it links (the cartridge, controller, save-state and FJ3002 sources) carry no licence grant, the repository's LICENSE being the GPL-2.0 text, the question YM2608-LLE raised. Aubrey settled it on 2026-11-24: a file with no "or later" grant in a repository whose LICENSE is the GPL-2.0 text is GPL-2.0-only, so the harness is GPL-2.0-only and cannot fold into this GPL-3.0-or-later repository at all. On 2026-11-24 it was folded, with its history, into `emu-tools-gpl2` as `tools/nuked-md` (nuked-md 0.2.0; the separate repository is archived), where megadrive-python's `NUKED_MD_HARNESS` can name `$EMU_TOOLS_GPL2/tools/nuked-md`. ## Smoke test `python3 -I tests/smoke.py` needs no ROM. It checks the version line and the exit codes, and, once `build.sh` has run, runs every chip on a short synthetic write script (a keyed tone) for 200,000 clock calls and checks the manifest, the record count, and that the tone is heard.