#!/usr/bin/env python3 """Resolve the a9 message pointers from a cap.lua debug.log capture. cap.lua breaks at the firmware's console-print entry (bit 0x3FDE00C0) and logs `PRINT pc=.. a9=.. a11=.. a5=..` lines (they land in MAME's -debuglog file, i.e. `debug.log` in the CWD). a9 is a BIT address; the ROM image is byte-based at 0x07E40000, so the string bytes are at file offset (a9 >> 3) - 0x07E40000. Usage: resolve_console.py [rom.bin] """ import sys ROM_BASE_BYTE = 0x07E40000 def main() -> int: log = sys.argv[1] rompath = sys.argv[2] if len(sys.argv) > 2 else "vt1200_v22.bin" with open(rompath, "rb") as f: rom = f.read() seen = set() with open(log, "r", errors="replace") as f: for line in f: if "PRINT pc=" not in line: continue fields = dict( kv.split("=", 1) for kv in line.split() if "=" in kv ) a9 = fields.get("a9") a11 = fields.get("a11") if a9 is None: continue bit = int(a9, 16) off = (bit >> 3) - ROM_BASE_BYTE key = (a9, a11) if key in seen: continue seen.add(key) if 0 <= off < len(rom): end = rom.find(b"\x00", off) raw = rom[off:end if end != -1 else off + 80] txt = raw.decode("latin-1").replace("\n", "\\n") print(f"a9={a9} a11={a11} {txt!r}") else: print(f"a9={a9} a11={a11} ") return 0 if __name__ == "__main__": sys.exit(main())