"""Bus traces as JSON Lines, one object per bus cycle in chip order. The family schema (as in sm83-python) with ARM's extra fields:: {"cycle": 12, "kind": "read", "address": 134217736, "width": 32, "access": 3, "value": 3818127360} {"cycle": 13, "kind": "internal", "address": 134217740} ``kind`` is ``read``, ``write`` or ``internal``; ``access`` is the SEQ/CODE/LOCK bit set the core reported (the TRM's, before any board mapping such as :func:`arm7tdmi_python.gba_access`). """ from __future__ import annotations import json from typing import TextIO class TraceWriter: """An observer for :class:`arm7tdmi_python.harness.Harness` that writes JSON Lines.""" def __init__(self, stream: TextIO) -> None: self.stream = stream self.cycle = 0 def __call__(self, kind: str, address: int, width: int, access: int, value: int) -> None: record: dict[str, int | str] = {"cycle": self.cycle, "kind": kind, "address": address} if kind != "internal": record.update(width=width, access=access, value=value) self.stream.write(json.dumps(record) + "\n") self.cycle += 1