#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Find the display DMA bursts in a Lynx II logic-analyser capture (tier 1 evidence). A display fetch shows on the bus as a run of four CAS falls two ticks apart in one row (a page-mode read faster than any CPU cycle), followed by a refresh cycle (row = column). Found with ``la_trace.py`` in the ``refresh_rate`` captures. This script lists, per line (HSYNC fall to HSYNC fall), the ticks of each half-burst after the line's HSYNC fall, the number per line, and the spacing histogram. python -I scripts/la_dma.py CAPTURE.dsl [--lines N] """ from __future__ import annotations import argparse import bisect import collections import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from dsl import lows from la_trace import Bus def half_bursts(bus: Bus) -> list[int]: """Ticks of the first CAS of each 4-CAS, 2-tick run.""" cycles = list(bus.cycles(0, bus.clk[-1])) out = [] for k in range(len(cycles) - 3): t0, new = cycles[k][0], cycles[k][1] if not new: continue if all(cycles[k + m][0] - cycles[k + m - 1][0] == 2 for m in (1, 2, 3)): out.append(t0) return out def main(argv: list[str]) -> int: parser = argparse.ArgumentParser() parser.add_argument("capture", type=Path) parser.add_argument("--lines", type=int, default=6) args = parser.parse_args(argv) bus = Bus(args.capture) halves = half_bursts(bus) hsync = [bus.tick(s) for s, _e in lows(bus.capture, "HSYNC")] per_line = collections.Counter() shown = 0 for a, b in zip(hsync, hsync[1:], strict=False): inside = halves[bisect.bisect_left(halves, a) : bisect.bisect_left(halves, b)] per_line[len(inside)] += 1 if inside and shown < args.lines: print(f"line of {b - a} ticks: {[t - a for t in inside]}") shown += 1 print(f"half-bursts per line: {sorted(per_line.items())}") spacing = collections.Counter(b - a for a, b in zip(halves, halves[1:], strict=False)) print(f"spacing: {sorted(spacing.most_common(16))}") return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))