# SPDX-License-Identifier: MIT """The VDP-stream instrument's canonical form, on writes and decoded events built here. BlastEm is a detector (docs/validation.md): these check that the two sides are put into one form, not that either is right. BlastEm's side is built as the GPL tool ``blastem-events`` writes it (its README), so no log bytes are made here. """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path[:0] = [str(ROOT / "scripts"), str(ROOT / "tests")] import blastem_events as be # noqa: E402 import vdp_streams as vs # noqa: E402 from test_blastem_events import write_output # noqa: E402 def test_the_128k_rearrangement_is_kabutos(): # "Writes to address a in 128K mode end up in the 68k VRAM address # (((a & 2) >> 1) ^ 1) | ((a & $400) >> 9) | a & $3FC | ((a & $1F800) >> 1)" assert vs.target_128k(0x0000) == 0x0001 assert vs.target_128k(0x0002) == 0x0000 assert vs.target_128k(0x0400) == 0x0003 assert vs.target_128k(0x0800) == 0x0401 assert vs.target_128k(0x0001) == vs.target_128k(0x0000) # bit 0 is ignored def test_blastem_events_take_the_boards_store_layout(tmp_path): records = [ {"t": 16, "event": "vdp-reg", "register": 1, "value": 0x04}, # mode 5 {"t": 32, "event": "vram-b", "address": 0x1234, "value": 0xAB}, {"t": 48, "event": "vram-w", "address": 0x00400, "value": 0x12CD}, {"t": 64, "event": "intram", "memory": "cram", "index": 3, "value": 0x0EEE}, {"t": 80, "event": "intram", "memory": "vsram", "index": 5, "value": 0x07FF}, ] decoded = be.Log(write_output(tmp_path / "out", records, video=1)) streams, meta = vs.read_blastem(tmp_path / "test.bel", decoded) assert list(streams.values["reg"]) == [1 << 8 | 0x04] # a byte at address a lands at a ^ 1, as the board's _vram_write_byte stores it assert list(streams.values["vram"]) == [0x1235 << 8 | 0xAB, 0x0003 << 8 | 0xCD] assert list(streams.values["cram"]) == [3 << 16 | 0x0EEE] assert list(streams.values["vsram"]) == [5 << 16 | 0x07FF] assert meta["frames"] == 1 def test_replay_gives_the_state_at_the_end_of_each_frame(): streams = vs.Streams() streams.add("cram", 1 << 16 | 0x0AA, vs.where(0, 10)) streams.add("cram", 1 << 16 | 0x0BB, vs.where(1, 10)) streams.add("cram", 2 << 16 | 0x0CC, vs.where(3, 10)) states = dict(vs.replay(streams, "cram", [0, 1, 2, 5])) assert states[0][1] == 0x0AA assert states[1][1] == 0x0BB assert states[2][2] == 0 assert states[5][2] == 0x0CC def test_copy_bytes_can_be_left_out_of_a_replay(): streams = vs.Streams() streams.add("vram", 0x10 << 8 | 0x11, vs.where(0, 0)) streams.add("vram", vs.COPY | 0x10 << 8 | 0x22, vs.where(0, 1)) ((_, kept),) = vs.replay(streams, "vram", [0], skip_copy=True) ((_, all_),) = vs.replay(streams, "vram", [0]) assert kept[0x10] == 0x11 assert all_[0x10] == 0x22