// SPDX-License-Identifier: MIT //! ANTIC and GTIA together on a synthetic BIOS: a mode line reaches the frame //! (a5200-python's tests/test_picture.py, transcribed). mod common; use a5200::gtia::GTIA; use a5200::Running; use common::{fake_board, picture_program}; fn frame_row(dmactl: u8, ir: u8, row: usize) -> Vec { let (code, ram) = picture_program(dmactl, ir); let mut cpu = fake_board(&code, None); for (address, value) in ram { cpu.bus.ram[address] = value; } cpu.run_frame(); cpu.run_frame(); cpu.bus.frame[row * 456..(row + 1) * 456].to_vec() } #[test] fn mode_2_hires_pixels_reach_the_frame() { let line = frame_row(0x22, 0x42, 8); // Normal width starts at $30; $EA = 11101010 in PF2's hue with PF1's luma. let start = 2 * 0x30; assert_eq!(line[start - 2], 0); // background left of the playfield assert_eq!( &line[start..start + 8], &[0x9A, 0x9A, 0x9A, 0x94, 0x9A, 0x94, 0x9A, 0x94] ); } #[test] fn mode_e_bitmap_reaches_the_frame() { let line = frame_row(0x22, 0x4E, 8); let start = 2 * 0x30; // $01 = 00 00 00 01: three background pixels then PF0, one colour clock each. assert_eq!(&line[start..start + 8], &[0, 0, 0, 0, 0, 0, 0x46, 0x46]); } // -- GTIA modes: players and missiles keep colour-clock resolution ------------ /// One scan line of ANTIC codes: blank outside $22-$DD, background (pixel 00) inside. fn gtia_line(gtia: &mut GTIA) { for c in 0..114 { let a = if 2 * c < 0x22 || 2 * c >= 0xDE { 2 } else { 0 }; let b = if 2 * c + 1 < 0x22 || 2 * c + 1 >= 0xDE { 2 } else { 0 }; gtia.cycle(a, b, false, 0); } } fn missile_positions(prior: u8) -> Vec { let mut gtia = GTIA::new(false, false); 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 0..3 { gtia_line(&mut gtia); } (0x30..0x48).filter(|&p| gtia.line[2 * p] == 0x06).collect() } #[test] fn 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_eq!(missile_positions(prior), vec![0x3A, 0x3B], "{prior:#x}"); } }