# nuked-md: a headless pin tracer around Nuked-MD `nuked_md_headless.c` drives Nuked-MD (nukeykt, ogamespec, andkorzh), 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 and reads only what it writes. Version 0.2.0 (`CHANGELOG.md`). Until 2026-11-24 this was the stand-alone repository `megadrive-nuked-md-harness` (now archived as `zzz-megadrive-nuked-md-harness`); its three commits were merged into this repository's history with the folder, and the tool is unchanged apart from its name, its version and a usage-error exit status. ## Paths Under **`$EMU_TOOLS_GPL2`** (a checkout of `emu-tools-gpl2`): | Path | What | | --- | --- | | `tools/nuked-md/build_nuked_md.sh` | fetches Nuked-MD at the pin (unless `NUKED_MD_SRC` names a tree) and builds the binary | | `tools/nuked-md/build/nukedmd-headless` | the built binary (git-ignored) | | `tools/nuked-md/build/build-info.json` | compiler, flags, the Nuked-MD commit, and whether the tree was fetched or given | | `tools/nuked-md/upstream/Nuked-MD` | the fetched upstream tree (git-ignored, never committed) | | `tools/nuked-md/tests/smoke.py` | the smoke test | | `tools/nuked-md/nuked_md_headless.c`, `nuked_md_sdl.h` | the driver and its stand-in for SDL's declarations | megadrive-python finds this folder as `$EMU_TOOLS_GPL2/tools/nuked-md` (its `NUKED_MD_HARNESS` variable was retired on 2026-11-24, following the one-variable-per-repository rule): it calls `build_nuked_md.sh` here and runs `build/nukedmd-headless`. ## Build sh "$EMU_TOOLS_GPL2/tools/nuked-md/build_nuked_md.sh" # fetch Nuked-MD at 594ca2a, build sh "$EMU_TOOLS_GPL2/tools/nuked-md/build_nuked_md.sh" --version # nuked-md 0.2.0 (Nuked-MD 594ca2a) NUKED_MD_SRC=DIR sh .../build_nuked_md.sh # an override: build from a tree of your own NMD_BUILD_DIR=DIR sh .../build_nuked_md.sh # put the binary elsewhere (an experiment) With `NUKED_MD_SRC` unset 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 (the fetched tree is file-for-file identical to it, and the binaries built from either are byte-identical). It compiles with `gcc -O2 -w -Wno-incompatible-pointer-types -DTMSS_ENABLE=0` (`CC` and `CFLAGS` override; zlib needed), about a minute and a half on the family's machine. `-DTMSS_ENABLE=0` gives the pre-TMSS board, one of the referee's named departures from any real console (the script's header says why). Exit status as the family's tool contract says: 0 built, 2 a usage error, 3 no Nuked-MD tree (or a failed fetch), anything else a failed build. ## What it measures, and the outputs **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. **Every output is OBSERVED** (Nuked-MD at `594ca2a`, via nuked-md 0.2.0): a closed-box measurement of a die-derived model, never a hardware fact. The binary takes the ROM on its command line (`-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` (required: stop at that half-MCLK), `NMD_TRACE` with `NMD_TRACE_FROM`, `NMD_TRACE_TO` and `NMD_TRACE_MASK` (the binary bus and signal trace), `NMD_PRESS`, `NMD_RESET`, `NMD_DUMP_RAM`, `NMD_DUMP_ZRAM`, `NMD_DUMP_VRAM`, `NMD_AUDIO`, `NMD_PLOT` (with `NMD_PLOT_FRAME`, `NMD_PLOT_FRAMES`, `NMD_PLOT_LIST`), `NMD_PICS`, `NMD_VRAMSIG` (with `NMD_VRAMSIG_FROM`, `NMD_VRAMSIG_TO`), `NMD_PROGRESS`, and the save states' `NMD_SAVE_DIR`, `NMD_SAVE_EVERY` and `NMD_LOAD`. The trace is little-endian records of a 64-bit half-MCLK time, the Z80 time, address, data, length, kind and flags (the record layout is in the driver's header and in megadrive-python's `scripts/nuked_md.py`). Format changes made with the move out of megadrive-python (2026-11-19): 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 "$EMU_TOOLS_GPL2/tools/nuked-md/tests/smoke.py" Needs no ROM: it checks the version line and the usage-error and missing-tree exit statuses, 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. ## Upstream, licence and pin - **Nuked-MD** by nukeykt, ogamespec and andkorzh, , pinned at **`594ca2a494104df559a907db7c8f5602a93b2078`** ("FJ3002 FM wip"; megadrive-python's `scripts/pinned_repos.json` pins the same). Its LICENSE is the GPL-2.0 text; several of the files the tool links (the cartridge, controller, save-state, audio and FJ3002 sources among them) carry no "or later" grant, so by the family's rule of 2026-11-24 they are GPL-2.0-only (`../../docs/upstreams.md`). - **The tool as built is GPL-2.0-only.** The driver is compiled and linked with Nuked-MD and reads its structures and pin fields, so it is part of Nuked-MD's GPL world (family charter, "Licences and provenance", rule 6), and it cannot be combined with GPL-3.0 code: `emu-tools-gpl` meets it only across a process boundary. This repository is GPL-2.0-only (`../../LICENSE`; the stand-alone repository carried Nuked-MD's own copy of the same GPL-2.0 text). - **Our own files keep their headers:** `nuked_md_headless.c` and `build_nuked_md.sh` GPL-2.0-or-later (Aubrey accepted that default, 2026-11-24), `nuked_md_sdl.h` MIT (our own glue, `../../notices/MIT-emulator-family.txt`); files added from 2026-11-24 are GPL-2.0-only. Code flows one way: never copy from here into an MIT project. - **History.** Moved out of the MIT repository megadrive-python on 2026-11-19 (provenance wave 2). 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. Nuked-MD is never committed here; if the tool is ever shared, its complete source and Nuked-MD at the pin go with it. - Checked against `emulator-lineage/docs/sources.md`.