#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Measure DRAM bus activity in a Lynx II logic-analyser capture (tier 1 evidence). For every RAS low pulse: its length in 16 MHz ticks (CLK rising edges inside it), the number of CAS falls inside it, and the gap to the next pulse. Pulses with no CAS are RAS-only refresh cycles; pulses with several CAS are page-mode bursts (display DMA or CPU sequential fetches). Prints histograms. python -I scripts/la_bus.py CAPTURE.dsl [--hsync] """ from __future__ import annotations import bisect import collections import itertools import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from dsl import lows, open_capture def rising(capture, name: str) -> list[int]: first, changes = capture.edges(name) level = first out = [] for at in changes: level ^= 1 if level: out.append(at) return out def main(argv: list[str]) -> int: capture = open_capture(Path(argv[0])) clk = rising(capture, "CLK") ras = lows(capture, "RAS") cas_falls = [s for s, _e in lows(capture, "CAS")] rows = [] for start, end in ras: ticks = bisect.bisect_left(clk, end) - bisect.bisect_left(clk, start) cas = bisect.bisect_left(cas_falls, end) - bisect.bisect_left(cas_falls, start) rows.append((start, end, ticks, cas)) kinds = collections.Counter((ticks, cas) for _s, _e, ticks, cas in rows) print(f"{len(rows):,} RAS pulses; (ticks low, CAS falls): count") for (ticks, cas), n in kinds.most_common(25): print(f" {ticks:3} ticks, {cas:2} CAS: {n:,}") refresh = [s for s, _e, _t, cas in rows if cas == 0] if len(refresh) > 2: gaps = collections.Counter( bisect.bisect_left(clk, b) - bisect.bisect_left(clk, a) for a, b in itertools.pairwise(refresh) ) print("refresh (RAS-only) spacing in ticks:", gaps.most_common(8)) bursts = [(s, t, c) for s, _e, t, c in rows if c >= 6] if len(bursts) > 2: gaps = collections.Counter( bisect.bisect_left(clk, b[0]) - bisect.bisect_left(clk, a[0]) for a, b in itertools.pairwise(bursts) ) print("burst (>= 6 CAS) spacing in ticks:", gaps.most_common(8)) if "--hsync" in argv: hs = [s for s, _e in lows(capture, "HSYNC")] gaps = collections.Counter( bisect.bisect_left(clk, b) - bisect.bisect_left(clk, a) for a, b in itertools.pairwise(hs) ) print("HSYNC low-to-low in ticks:", gaps.most_common(5)) # Bursts relative to the preceding HSYNC fall. rel = collections.Counter() for s, _t, _c in bursts: i = bisect.bisect_right(hs, s) - 1 if i >= 0: rel[bisect.bisect_left(clk, s) - bisect.bisect_left(clk, hs[i])] += 1 print("burst start after HSYNC fall (ticks):", sorted(rel.most_common(24))) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))