# SPDX-License-Identifier: MIT """Deterministic boundary traces of a 65C02: write, read and compare them. 6502-python's trace functions (its docs/trace-schema.md, version 1) with this core's record types: one JSON object per boundary, with ``kind`` one of :class:`~w65c02_python.debug.BoundaryKind`'s values, ``before`` and ``after`` :class:`~w65c02_python.state.CPUState`'s fields, and ``accesses`` ``[kind, address, value]`` with the kinds of :mod:`w65c02_python.debug` (``"rs"``, ``"rf"``, ``"r"``, ``"w"``), one per cycle. A trace does not say which part made it; the reader is told the row, so that ``$07`` reads back as the instruction that row runs. A trace written here is read back equal, and two cores' traces are compared with :func:`first_trace_divergence`. """ from __future__ import annotations from collections.abc import Iterator from typing import TextIO from sixfiveohtwo.trace import ( TRACE_SCHEMA_VERSION, TraceDifference, TraceDivergence, compare_step_records, first_session_divergence, first_trace_divergence, iter_session_steps, iter_trace_divergences, step_record_to_dict, write_trace, ) from sixfiveohtwo.trace import read_trace as _read_trace from sixfiveohtwo.trace import step_record_from_dict as _step_record_from_dict from w65c02_python.cpu import W65C02S from w65c02_python.debug import W65C02Record, record_type def step_record_from_dict(value: object, row: type = W65C02S) -> W65C02Record: """Reconstruct one strictly validated record of ``row`` (a CPU class).""" return _step_record_from_dict(value, record_type=record_type(row)) def read_trace(stream: TextIO, row: type = W65C02S) -> Iterator[W65C02Record]: """Yield strictly validated records of ``row`` lazily from a JSON Lines stream.""" return _read_trace(stream, record_type=record_type(row)) __all__ = [ "TRACE_SCHEMA_VERSION", "TraceDifference", "TraceDivergence", "compare_step_records", "first_session_divergence", "first_trace_divergence", "iter_session_steps", "iter_trace_divergences", "read_trace", "step_record_from_dict", "step_record_to_dict", "write_trace", ]