#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Find the DRAM refresh cycles in a Lynx II logic-analyser capture (tier 1 evidence). A refresh cycle shows on the bus as a single read whose row and column bytes are equal and step by one from refresh to refresh (found in ``lynx2-mikey-page_mode`` with ``la_trace.py``: rows $B7, $B8, $B9 ... about 256 ticks apart). This script lists them: spacing histogram, the tick (mod 16) each starts on, the cycle lengths around them, and their position relative to the display DMA bursts. python -I scripts/la_refresh.py CAPTURE.dsl [...] """ from __future__ import annotations import collections import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from la_trace import Bus def refreshes(bus: Bus) -> list[tuple[int, int, int]]: """(tick, row, index in the cycle list) of each refresh cycle: row == column, a new row, and the next refresh's row one higher.""" cycles = list(bus.cycles(0, bus.clk[-1])) candidates = [ (tick, row, k) for k, (tick, new, row, col, _low) in enumerate(cycles) if new and row == col ] out = [] for a, b in zip(candidates, candidates[1:], strict=False): if b[1] == (a[1] + 1) & 0xFF and 0 < b[0] - a[0] < 400: if not out or out[-1] != a: out.append(a) out.append(b) return out, cycles def main(argv: list[str]) -> int: for name in argv: bus = Bus(Path(name)) found, cycles = refreshes(bus) spacing = collections.Counter(b[0] - a[0] for a, b in zip(found, found[1:], strict=False)) phase = collections.Counter((tick - 1) % 16 for tick, _r, _k in found) print(f"{Path(name).name}: {len(found)} refresh cycles") print(f" spacing: {sorted(spacing.most_common(12))}") print(f" start tick mod 16: {sorted(phase.items())}") # The gap from the previous CAS and to the next one (the refresh's cost). around = collections.Counter() for tick, _row, k in found: if 0 < k < len(cycles) - 1: around[(tick - cycles[k - 1][0], cycles[k + 1][0] - tick)] += 1 print(f" (ticks from previous CAS, to next CAS): {around.most_common(8)}") # Attached to a display DMA run (the cycle before is a 2-tick page-mode CAS), # or alone; and the spacing of the lone ones. alone = [ tick for tick, _row, k in found if k and tick - cycles[k - 1][0] > 2 and not (k > 1 and cycles[k - 1][0] - cycles[k - 2][0] == 2) ] spacing = collections.Counter(b - a for a, b in zip(alone, alone[1:], strict=False)) print(f" alone: {len(alone)}; attached: {len(found) - len(alone)}") print(f" alone spacing: {sorted(spacing.most_common(14))}") return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))