#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Summarise a DMA tap log written by scripts/mame/tap.lua. Each log line is ``frame kind bit_address value pc``. The register index is ``(bit_address & 0xFF) >> 4`` (16-bit registers, bit-addressed; the Y-unit's game code writes the 0x01A80000 mirror). The start of a transfer is the write to the control register with bit 15 set: register 0 on the Y-unit, register 1 on the T- and Wolf units (OBSERVED: these writes come last in every burst and the value read back from the same register drops bit 15 while the transfer runs). Per frame it reports the transfers started, the status polls (reads of the control register), and the sum of reg[6] x reg[7] over the transfers: the *candidate* pixel count if registers 6 and 7 are width and height (HYPOTHESIS: it is a reading of the logs, not a document; see docs/dma-blitter.md). python3 -I scripts/dma_stats.py --unit Y tests/mame_traces/tap-term2.txt """ from __future__ import annotations import argparse import sys from collections import defaultdict from pathlib import Path def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--unit", choices="YTW", required=True) parser.add_argument("log", type=Path) args = parser.parse_args() control = 0 if args.unit == "Y" else 1 regs = [0] * 16 starts = defaultdict(int) polls = defaultdict(int) pixels = defaultdict(int) shapes = defaultdict(int) for line in args.log.read_text().splitlines(): frame, kind, address, value, _pc = line.split() if kind not in ("DW", "DR"): continue frame = int(frame) reg = (int(address, 16) & 0xFF) >> 4 value = int(value, 16) if kind == "DR": if reg == control: polls[frame] += 1 continue regs[reg] = value if reg == control and value & 0x8000: starts[frame] += 1 pixels[frame] += regs[6] * regs[7] shapes[(regs[6], regs[7])] += 1 frames = sorted(set(starts) | set(polls)) print("frame transfers status-polls sum(reg6*reg7)") for frame in frames: print(f"{frame:5} {starts[frame]:9} {polls[frame]:12} {pixels[frame]:14}") if frames: n = len(frames) print( f"mean {sum(starts.values()) / n:9.1f} {sum(polls.values()) / n:12.1f} " f"{sum(pixels.values()) / n:14.1f}" ) common = sorted(shapes.items(), key=lambda item: -item[1])[:8] print("commonest (reg6, reg7):", ", ".join(f"{w}x{h}: {c}" for (w, h), c in common)) return 0 if __name__ == "__main__": sys.exit(main())