"""The H-scroll measuring tool must reject missing or contradictory latch evidence.""" import sys import pytest from conftest import ROOT sys.path.insert(0, str(ROOT / "scripts")) from run_hscroll_latch import cartridge, check_trace TRACE = """0 HA 0 400 0 1 HB 0 400 0 2 H 0 461 1 3 DISPLAY 1 486 1 4 HREQUEST 1 487 1 5 HA 16 491 1 6 HB 16 492 1 7 H 0 461 2 8 DISPLAY 1 487 2 9 H 0 461 3 """ def test_successful_fetch_then_retained_previous_values(): result = check_trace(TRACE) assert result["fetched"] == 1 assert result["retained"] == 1 assert result["request_h"] == {0x1E7: 1} assert result["enable_phases"] == [(0x1E6, True, 1), (0x1E7, False, 1)] def test_a_missed_fetch_must_not_take_the_new_table_value(): bad = TRACE.replace("9 H", "8 HA 0 491 2\n8 HB 0 492 2\n9 H") with pytest.raises(ValueError, match="line 2: scroll"): check_trace(bad) def test_a_successful_fetch_must_update_both_planes(): with pytest.raises(ValueError, match="line 1: scroll"): check_trace(TRACE.replace("6 HB 16", "6 HB 0")) def test_missing_latch_evidence_is_not_a_pass(): with pytest.raises(ValueError, match="missing initial"): check_trace(TRACE.replace("0 HA 0 400 0\n", "")) with pytest.raises(ValueError, match="both successful and missed"): check_trace("") def test_request_must_use_the_measured_horizontal_phase(): with pytest.raises(ValueError, match="requests must occur"): check_trace(TRACE.replace("HREQUEST 1 487", "HREQUEST 1 488")) @pytest.mark.parametrize("enable_h", [485, 487]) def test_enable_boundary_must_be_exercised_and_respected(enable_h): with pytest.raises(ValueError, match="probe must exercise an H="): check_trace(TRACE.replace("DISPLAY 1 486", f"DISPLAY 1 {enable_h}")) def test_both_rom_modes_have_valid_vectors_and_distinct_mode_registers(): for h40 in (False, True): rom = cartridge(h40) assert len(rom) == 0x10000 assert int.from_bytes(rom[4:8], "big") == 0x200 assert bytes.fromhex("32bc8c81" if h40 else "32bc8c00") in rom[0x200:]