# SPDX-License-Identifier: MIT """The television stage's frame boundaries (milestone 2, exit d's harness causes). The frame compare against MAME 0.285 found two harness causes, both here: the crop was one line low (lines 28-251 instead of 27-250: every compared frame of Asteroids differed by 1,856 pixels) and the board counted the one-line partial frame at power-on (line 250) as frame 1, so the board's frame N + 1 was MAME's frame N (Joust: 2,336 pixels at offset 0, 0 at +1). """ from a7800_python import television from a7800_python.television import FIRST_LINE, LINES, Television class FakeMaria: on_line = None def feed(tv, maria, lines): pixels = bytearray(454) for line in lines: pixels[television.FIRST_CLOCK] = line & 0xFF maria.on_line(line, pixels, False) def test_crop_is_mames_visible_lines(): assert (FIRST_LINE, LINES) == (27, 224) def test_partial_frame_at_power_is_not_counted(): maria = FakeMaria() tv = Television(maria) feed(tv, maria, [250, 251, 252, 262]) # power at line 250: the end of a frame assert tv.count == 0 feed(tv, maria, range(263)) assert tv.count == 1 frame = tv.frames[-1] assert frame[0][0] == 27 and frame[-1][0] == 250 def test_pal_crop_is_lines_35_to_294(): from a7800_python.machine import PAL maria = FakeMaria() first, lines = television.crop_for(PAL) assert (first, lines) == (35, 260) tv = Television(maria, first_line=first, lines=lines) feed(tv, maria, range(313)) feed(tv, maria, range(313)) frame = tv.frames[-1] assert tv.count == 2 and len(frame) == 260 assert frame[0][0] == 35 and frame[-1][0] == 294 & 0xFF