"""The register-file replay behind the period-0/1 survey (scripts/psg_streams.py).""" from __future__ import annotations import sys from conftest import ROOT sys.path.insert(0, str(ROOT / "scripts")) from psg_streams import analyse def test_period_zero_heard_only_while_the_channel_is_on(): events = [ (0x9F, 0), (0xBF, 0), (0xDF, 0), (0xFF, 0), # BIOS: all four off (0x80, 100), (0x00, 140), # channel 0 period 0 (latch low nibble, then high bits) (0x90, 200), # channel 0 attenuation 0: now heard at period 0 (0x85, 1200), # period 5: no longer low (0xA1, 1300), (0x00, 1340), # channel 1 period 1, still off: not heard ] # fmt: skip writes, low, heard = analyse(events) assert writes == 10 assert low[(0, 0)] == 2 and low[(1, 1)] == 2 assert heard == {(0, 0): 1000} def test_noise_driven_by_channel_2_counts(): events = [(0xDF, 0), (0xFF, 0), (0xC0, 10), (0x00, 20), (0xE3, 30), (0xF0, 40), (0xFF, 540)] _, _, heard = analyse(events) assert heard == {("noise", 0): 500}