#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Rung 3's streams: the 51 streams of sn76489-python's ``validation/closed_box.py`` (its ``streams()``), written as lockstep scripts for each of the four parts. PYTHONPATH=REFERENCE/src python3 scripts/export_closed_box.py REFERENCE OUT_DIR Only the stream table is used. ``closed_box.py`` compares the core with Nuked-PSG run as a closed box; nothing here builds or runs that model (``build()`` is never called, and the reference clone has no ``reference/`` directory to build it from). Each stream is replayed as ``core_ticks`` replays it through the core: ``run`` up to each event's clock, then the write (``w``) or the test bits (``t``), then ``run`` to the stream's length. ``core_ticks`` records the registers at every tick and the left level; the trace records every state field after every call and both levels of every tick. Two differences from the reference's use, both because the model is not run: the streams are replayed on every part, not only ``YM7101_PSG`` (on the others ``t`` reports the missing register, identically in both cores), and with each part's own volume table rather than the model's measured levels. """ from __future__ import annotations import re import sys from pathlib import Path PARTS = ("SN76489AN", "SEGA_VDP_PSG", "GAME_GEAR_PSG", "YM7101_PSG") def slug(name: str) -> str: return re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-") def main() -> int: reference, out_dir = Path(sys.argv[1]), Path(sys.argv[2]) sys.path.insert(0, str(reference / "validation")) import closed_box # noqa: PLC0415 (the reference's module, from its validation/) out_dir.mkdir(parents=True, exist_ok=True) table = closed_box.streams() for index, (name, (events, length)) in enumerate(table.items()): body, now = [], 0 for clock, kind, value in events: body.append(f"run {clock - now}") body.append(f"{kind} {value}") now = clock body.append(f"run {length - now}") body.append("take") for part in PARTS: lines = [f"variant {part}", "new 0", *body] path = out_dir / f"{index:02d}-{slug(name)}-{part}.txt" path.write_text("\n".join(lines) + "\n") print(f"{len(table)} streams x {len(PARTS)} parts in {out_dir}") return 0 if __name__ == "__main__": sys.exit(main())