#!/usr/bin/env python3 """The PACKED CONTAINER's own bytes, through px68k's real GVRAM code. python3 tools/bench/gvpack/verify_dlxp.py [packed.dlxp] [frame] [--controls] `verify_gvpack.py` checks the LAYOUT: it hands the harness a picture and lets the harness compute the interleave, so what it proves is that FINDINGS 47.2's scheme renders. This checks the CONTAINER: it writes a DLXP1 record's bytes into GVRAM VERBATIM -- no interleave computed anywhere in the harness -- and asks px68k what they display as. That is the only way to test a format whose whole design is that nothing parses it (dlxp.py): if the encoder's byte order were wrong, every check upstream of the display would still pass, because the container round-trips against its own inverse. It is the same second-emulator argument tools/bench/c68k makes for cycles: the address decode, the R20 bit-11 write path, the page-byte selection, the scroll wrap and the index-0 transparency test are px68k's own `x68k/gvram.c`. Two negative controls, because a test that cannot fail proves nothing, and both are mechanisms this container depends on rather than decoration: --nobuffer R20 bit 11 CLEAR -- the high byte of every word is masked away, so page 1 (columns 128..255) never gets written --noscroll page 1 unscrolled -- its storage sits under the wrong columns """ import os, struct, subprocess, sys sys.path.insert(0, "tools/encoder") import numpy as np from dlxp import DLXP args = [x for x in sys.argv[1:] if not x.startswith("--")] path = args[0] if args else "tmp/packed_singe.dlxp" frame = int(args[1]) if len(args) > 1 else 0 controls = "--controls" in sys.argv d = DLXP(path) _, pic = d._split(frame) blob = b"DLXQ" + struct.pack(">HH", d.W, d.H) + b"\0" * 768 + pic open("tmp/dlxp_gvpack.bin", "wb").write(blob) BIN = "tools/bench/gvpack/gvpack" if not os.path.exists(BIN): sys.exit(f"{BIN} not built -- make -C tools/bench/gvpack PX68K=...") def run(extra=None): cmd = [BIN, "tmp/dlxp_gvpack.bin", "tmp/dlxp_gvpack.raw", "--packed", "0x02"] if extra: cmd.append(extra) subprocess.run(cmd, check=True, stderr=subprocess.DEVNULL) g = np.frombuffer(open("tmp/dlxp_gvpack.raw", "rb").read(), np.uint8) return g.reshape(256, 256) want = d.indices(frame) yoff = (256 - d.H) // 2 g = run() act = g[yoff:yoff + d.H] fail = [] if not np.array_equal(act, want): bad = act != want fail.append(f"{bad.sum()} px differ (left half {bad[:, :128].sum()}, " f"right half {bad[:, 128:].sum()})") bars = np.concatenate([g[:yoff], g[yoff + d.H:]]) if bars.size and (bars != 255).any(): fail.append(f"letterbox is not index 255: {(bars != 255).sum()} px") if (act == 0).any(): fail.append(f"index 0 reached the screen: {(act == 0).sum()} px") if controls and not fail: for flag, why in (("--nobuffer", "R20 bit 11 clear"), ("--noscroll", "page 1 unscrolled")): c = run(flag)[yoff:yoff + d.H] n = int((c != want).sum()) print(f" control {flag:<11s} ({why}): {n:,} px differ" + ("" if n else " <-- IT DID NOT FAIL")) if not n: fail.append(f"control {flag} passed -- the test cannot fail on it") for x in fail: print("FAIL " + x) if fail: sys.exit(1) print(f"OK {os.path.basename(path)} frame {frame}: px68k's own gvram.c renders " f"the container's {d.pic_bytes:,} bytes index-exact over {d.W}x{d.H},") print(f" letterbox on the reserved black, and the transparency key never " f"reaches the screen. The harness computed no interleave.")