# megadrive-nuked-md-harness `nuked_md_headless.c` drives Nuked-MD (nukeykt, ogamespec, andkorzh; GPL-2.0), the gate-level Mega Drive model, headless, for megadrive-python's closed-box measurements: its milestone 6 bus-stream comparisons and the pin-level fits recorded in its `docs/provenance.md` and `docs/validation.md`. megadrive-python runs the built binary as a separate program, through the environment variable `NUKED_MD_HARNESS` (the path to this directory), and reads only what it writes. **Pins only.** The driver records the 68000 and Z80 buses, the work-RAM and cartridge selects, the VRAM's pins, the board's control lines, the VDP's /HSYNC and /VSYNC, its RGB outputs, the sound outputs, and the memories' contents (work RAM, Z80 RAM, VRAM). It exposes no internal node of the model. An earlier version, inside megadrive-python, also logged internal latches and counters (trace record types 6-9 and 11, `NMD_VDPSIG`, `NMD_FMSIG`, the V counter in each plotted row); those taps were removed on 2026-11-19 (provenance wave 2), and their numbers and variables are not reused. **Licence: GPL-2.0-only as built** (`LICENSE`, Nuked-MD's own GPL-2.0 text). The driver is compiled and linked with Nuked-MD and reads its structures and pin fields, so the tool is treated as part of Nuked-MD's GPL world (family charter, "Licences and provenance", rule 6). By Aubrey's rule of 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) several of the Nuked-MD files it links (the cartridge, controller, save-state, audio and FJ3002 sources among them) are GPL-2.0-only, and so is the tool as built; it cannot be combined with GPL-3.0 code (the family's GPL-3.0-or-later `emu-tools-gpl` meets it only across a process boundary). Our own files keep their headers: `nuked_md_headless.c` and `build_nuked_md.sh` GPL-2.0-or-later, `nuked_md_sdl.h` MIT (our own glue); files added from 2026-11-24 are GPL-2.0-only. Code flows one way: never copy from here into an MIT project. Local only. Moved out of the MIT repository megadrive-python on 2026-11-19 (provenance wave 2, following the precedent of m68000-winuae-referee and hg51b-mesen-harness). It was in megadrive-python's history as `validation/nuked_md_headless.c`, `validation/nuked_md_sdl.h` and `validation/build_nuked_md.sh` from milestone 6 (2026-09-23) to that date. If it is ever shared, its complete source and Nuked-MD at the pinned commit (594ca2a) go with it. ## Build and use Version 0.1.0 (`CHANGELOG.md`). The path a consumer uses is the directory itself (megadrive-python finds it through `NUKED_MD_HARNESS`): the build is `$NUKED_MD_HARNESS/build_nuked_md.sh`, its output `$NUKED_MD_HARNESS/build/nukedmd-headless` (with `build/build-info.json`: compiler, flags, the Nuked-MD commit and whether the tree was fetched or given). ```sh sh build_nuked_md.sh # fetch Nuked-MD at 594ca2a into upstream/ (git-ignored), build sh build_nuked_md.sh --version # megadrive-nuked-md-harness 0.1.0 (Nuked-MD 594ca2a) NUKED_MD_SRC=DIR sh build_nuked_md.sh # build from a tree of your own instead (an override) NMD_BUILD_DIR=DIR sh build_nuked_md.sh # put the binary elsewhere (an experiment) ``` With `NUKED_MD_SRC` unset (from 2026-11-24) the script clones into `upstream/Nuked-MD` beside it at **`594ca2a494104df559a907db7c8f5602a93b2078`**, or checks an existing clone out at the pin; a clone with local changes stops it, and it never deletes anything. `NUKED_MD_SRC` keeps working as an override: megadrive-python's `scripts/nuked_md.py` still passes its own `reference/src/Nuked-MD` that way. Gated on 2026-11-24: the binary built from the fetched tree is byte-identical to the one built from megadrive-python's tree (the fetched tree is file-for-file identical to it), megadrive-python's `tests/test_milestone6.py` passes on it, and its probes give identical traces and memory dumps (`CHANGELOG.md`). Exit status as the family's tool contract says: 0 built, 3 no Nuked-MD tree (or a failed fetch), anything else a failed build. About a minute and a half to compile (2026-11-24). ```sh # megadrive-python today: it builds on first use, passing its own tree export NUKED_MD_HARNESS=$PWD cd ../megadrive-python && python scripts/run_nuked_md.py ``` The binary itself takes the ROM on its command line (megadrive-python puts `-pal` or `-jap` before it for the other regions); everything else is driven by environment variables, documented at the top of `nuked_md_headless.c` (`NMD_STOP`, `NMD_TRACE`, `NMD_TRACE_MASK`, `NMD_PLOT`, `NMD_PICS`, `NMD_VRAMSIG`, ...). Format changes made with the move: plotted frames (`NMD_PLOT`, `NMD_PICS`) end after the samples (no V-counter array); `NMD_VRAMSIG` lines carry the half-MCLK time instead of the model's H and V counters; save states' `.drv` side files are shorter, so saves made by the old driver do not load. ## Smoke test python3 -I tests/smoke.py Needs no ROM: it checks the version line and the missing-tree exit status, and, once the harness is built, runs a 1 KB cartridge of its own (reset vectors and a branch-to-self loop) past the board's reset and checks that the 68000 reads the vectors and keeps fetching the loop. About ten seconds.