# SPDX-License-Identifier: MIT """ANTIC and GTIA together on a synthetic BIOS: a mode line reaches the frame.""" from __future__ import annotations from helpers import fake_board def _program(dmactl: int, ir: int) -> tuple[bytes, dict[int, int]]: code = bytes( ( 0xA9, 0x00, 0x8D, 0x02, 0xD4, # DLISTL = $00 0xA9, 0x10, 0x8D, 0x03, 0xD4, # DLISTH = $10 0xA9, 0xF8, 0x8D, 0x09, 0xD4, # CHBASE = $F8 (the fake BIOS: $EA bytes) 0xA9, 0x94, 0x8D, 0x18, 0xC0, # COLPF2 0xA9, 0xCA, 0x8D, 0x17, 0xC0, # COLPF1 0xA9, 0x46, 0x8D, 0x16, 0xC0, # COLPF0 0xA9, dmactl, 0x8D, 0x00, 0xD4, # DMACTL 0x4C, 0x23, 0xF8, # JMP * (at $F823) ) ) # fmt: skip ram = {0x1000: ir, 0x1001: 0x00, 0x1002: 0x20, 0x1003: 0x41, 0x1004: 0x00, 0x1005: 0x10} # Name $10: its glyph rows are at $F880, past the program, all $EA. ram.update({0x2000 + i: 0x10 if ir & 0x0F < 8 else 0x01 for i in range(48)}) return code, ram def _frame_row(dmactl: int, ir: int, row: int = 8) -> bytes: code, ram = _program(dmactl, ir) board = fake_board(code) for address, value in ram.items(): board.ram[address] = value board.run_frame() board.run_frame() return bytes(board.frame[row * 456 : (row + 1) * 456]) def test_mode_2_hires_pixels_reach_the_frame(): line = _frame_row(0x22, 0x42) # Normal width starts at $30; $EA = 11101010 in PF2's hue with PF1's luma. start = 2 * 0x30 assert line[start - 2] == 0 # background left of the playfield pixels = line[start : start + 8] assert pixels == bytes((0x9A, 0x9A, 0x9A, 0x94, 0x9A, 0x94, 0x9A, 0x94)) def test_mode_e_bitmap_reaches_the_frame(): line = _frame_row(0x22, 0x4E) start = 2 * 0x30 # $01 = 00 00 00 01: three background pixels then PF0, one colour clock each. assert line[start : start + 8] == bytes((0, 0, 0, 0, 0, 0, 0x46, 0x46)) # -- GTIA modes: players and missiles keep colour-clock resolution ------------ def _gtia_line(gtia) -> None: """One scan line of ANTIC codes: blank outside $22-$DD, background (pixel 00) inside.""" for c in range(114): a = 2 if (2 * c < 0x22 or 2 * c >= 0xDE) else 0 b = 2 if (2 * c + 1 < 0x22 or 2 * c + 1 >= 0xDE) else 0 gtia.cycle(a, b, False, 0) def _missile_positions(prior: int) -> list[int]: from a5200_python.gtia import GTIA gtia = GTIA() gtia.write(0x1A, 0xC0) # COLBK gtia.write(0x19, 0x06) # COLPF3: the fifth player's colour gtia.write(0x1B, prior) # PRIOR (GTIA mode bits included) gtia.write(0x07, 0x39) # HPOSM3 gtia.write(0x06, 0x3B) # HPOSM2 gtia.write(0x11, 0x60) # GRAFM: M3 = 01 (shows on its second clock), M2 = 10 for _ in range(3): _gtia_line(gtia) return [p for p in range(0x30, 0x48) if gtia.line[2 * p] == 0x06] def test_missiles_keep_colour_clock_positions_in_gtia_modes(): # [AHRM] 6.5: positions have colour-clock resolution; 6.9 widens and (mode # 10) delays only the playfield pixel. Rescue on Fractalus! draws its # canopy ticks this way (PRIOR $94, GRAFM $66, HPOSM2/3 $3B/$39): M3's # bit lands on even clock $3A, M2's on odd clock $3B. # Mode 11 is left out: over pixel 0000 it forces the fifth player's # luminance to 0 ([AHRM] 6.9), so the colour is not COLPF3 there. for prior in (0x14, 0x54, 0x94): # fifth player in the normal mode, mode 9, mode 10 assert _missile_positions(prior) == [0x3A, 0x3B], hex(prior)