// SPDX-License-Identifier: MIT //! The television stage's frame boundaries (the reference's tests/test_television.py). //! //! 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) and the board counted the //! one-line partial frame at power-on (line 250) as frame 1. use a7800::machine::{NTSC, PAL}; use a7800::maria::Maria; use a7800::television::{crop_for, Television, FIRST_CLOCK, FIRST_LINE, LINES}; fn feed(maria: &mut Maria, lines: impl IntoIterator) { let mut pixels = vec![0u8; 454]; for line in lines { pixels[FIRST_CLOCK] = (line & 0xFF) as u8; (maria.on_line.as_mut().unwrap())(line, &pixels, false); } } fn maria() -> Maria { Maria::new(NTSC.lines, 16, 242, 250, 444) } #[test] fn crop_is_mames_visible_lines() { assert_eq!((FIRST_LINE, LINES), (27, 224)); } #[test] fn partial_frame_at_power_is_not_counted() { let mut maria = maria(); let tv = Television::new(&mut maria, 2, FIRST_LINE, LINES); feed(&mut maria, [250, 251, 252, 262]); // power at line 250: the end of a frame assert_eq!(tv.count(), 0); feed(&mut maria, 0..263); assert_eq!(tv.count(), 1); let frame = tv.last_frame().unwrap(); assert!(frame[0][0] == 27 && frame[frame.len() - 1][0] == 250); } #[test] fn pal_crop_is_lines_35_to_294() { let mut maria = maria(); let (first, lines) = crop_for(&PAL); assert_eq!((first, lines), (35, 260)); let tv = Television::new(&mut maria, 2, first, lines); feed(&mut maria, 0..313); feed(&mut maria, 0..313); let frame = tv.last_frame().unwrap(); assert!(tv.count() == 2 && frame.len() == 260); assert!(frame[0][0] == 35 && frame[frame.len() - 1][0] == (294 & 0xFF) as u8); }