// SPDX-License-Identifier: MIT //! The reference's judges run natively on this board (gates.rs), each against //! an a2600-python checkout with its references fetched: `A2600_PYTHON_ROOT`, //! default `../a2600-python` beside this repository. //! //! a2600-gates die # the 39 Sim2600 die traces, every pin //! a2600-gates timers [--every-row] # Stella #108 and #606 timer ROMs, console results //! a2600-gates serial CONSOLE # ale-79's seven #699 tables, every cell (PAL_7800 ...) //! a2600-gates hashes # the reference's tests/frame_hashes.tsv (needs NO_INTRO_DIR) //! a2600-gates hashes-rows # its tests/frame_hashes_rows.tsv: Pitfall II's music per row //! //! Exit status 1 when any result fails. use std::path::PathBuf; use a2600::gates::{ default_system, die_traces, dump_path, frame_hashes, hash_row, run_hashes, serial_tables, timer_roms, CONSOLES, }; use a2600::machine::{console_row, machine, Machine, MACHINES, NTSC_7800, PAL_7800, VCS_NTSC}; // machine::HOSTED_MACHINES, spelled out so that the seeded fault that renames // that listed name (api-name-gone) still builds this binary and is judged by // the API test, as the reference judges it. const HOSTED: [Machine; 2] = [PAL_7800, NTSC_7800]; use a2600::tia::TIA; use a2600::System; fn root() -> PathBuf { match std::env::var("A2600_PYTHON_ROOT") { Ok(r) if !r.is_empty() => PathBuf::from(r), _ => PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../a2600-python"), } } fn main() { let args: Vec = std::env::args().skip(1).collect(); let root = root(); let started = std::time::Instant::now(); let failed = match args.first().map(String::as_str) { Some("die") => { let results = die_traces(&root, &mut TIA::default, None).expect("die traces"); let mut failed = 0; for (name, (scored, bad, passed)) in &results { println!( "{name}: {scored} records, {} {bad:?}", if *passed { "pass" } else { "FAIL" } ); failed += !passed as usize; } println!("{} of {} die traces pass", results.len() - failed, results.len()); failed } Some("timers") => { // `timers` runs the NTSC row the console results were captured on; // `timers --every-row` hands each row of MACHINES and HOSTED_MACHINES // to the factory (gates.timer_roms(machine=)): a pass there is the // NTSC result reproduced on that row, nothing more. let rows: Vec = if args.get(1).map(String::as_str) == Some("--every-row") { MACHINES.iter().chain(HOSTED.iter()).copied().collect() } else { vec![VCS_NTSC] }; let (mut failed, mut total) = (0, 0); for row in rows { let results = timer_roms(&root, &default_system, row).expect("timer ROMs"); for (name, ok) in &results { println!( "{} {name}: {}", row.name, if *ok { "console result" } else { "DIFFERS" } ); } failed += results.values().filter(|ok| !**ok).count(); total += results.len(); } println!("{} of {total} timer ROMs show the console's result", total - failed); failed } Some("hashes-rows") => { // The reference's tests/frame_hashes_rows.tsv, as its scripts/frame_hashes.py // --machine ROW --start 100 --check runs it: System.from_rom on the row // (the row's clock reaches the DPC), Reset for frames 30-39, fire for // frames 100-109, then the hashed frames. let text = std::fs::read_to_string(root.join("tests/frame_hashes_rows.tsv")).expect("rows record"); let (mut failed, mut total) = (0, 0); for record in text.lines().filter(|r| !r.is_empty() && !r.starts_with('#')) { let label = record.split('\t').next().unwrap(); let (name, settings) = label.rsplit_once(" [").expect("a [ROW, start N] label"); let (row_name, start) = settings .trim_end_matches(']') .rsplit_once(", start ") .expect("ROW, start N"); let start: u64 = start.parse().expect("start frame"); let frames: u64 = record.split('\t').nth(1).unwrap().parse().expect("frames"); let row = machine(row_name) .or_else(|| HOSTED.iter().copied().find(|m| m.name == row_name)) .expect("a machine row"); let mut system = System::from_path(&dump_path(name).expect("NO_INTRO_DIR"), row).expect("load"); system.run_frames(30); system.board().riot.borrow_mut().input_b &= !0x01; // Reset (SWCHB D0) pressed system.run_frames(10); system.board().riot.borrow_mut().input_b |= 0x01; system.run_frames(start.saturating_sub(40)); system.board_mut().tia.fire[0] = true; system.run_frames(10); system.board_mut().tia.fire[0] = false; let row_line = hash_row(label, frames, &run_hashes(&mut system, frames)); let same = row_line == record; println!("{row_line}\t{}", if same { "same" } else { "CHANGED" }); failed += !same as usize; total += 1; } println!( "{} of {total} row runs identical to the reference's record", total - failed ); failed } Some("serial") => { let console = args .get(1) .map(String::as_str) .unwrap_or_else(|| panic!("a console: {CONSOLES:?}")); let row = console_row(console).expect("a #699 console"); let results = serial_tables(&root, row, console, None, &default_system).expect("serial tables"); let (mut matched, mut total) = (0, 0); for (rom, (m, t, misses)) in &results { println!( "{console} {rom}: {m} of {t} cells{}", if misses.is_empty() { String::new() } else { format!(", first misses {:?}", &misses[..misses.len().min(3)]) } ); matched += m; total += t; } println!("{console}: {matched} of {total} cells"); total - matched } Some("hashes") => { let results = frame_hashes(&root, None, &default_system, VCS_NTSC).expect("frame hashes"); let failed = results.values().filter(|ok| !**ok).count(); for (name, ok) in &results { println!("{name}: {}", if *ok { "same" } else { "CHANGED" }); } println!( "{} of {} runs identical to the reference's record", results.len() - failed, results.len() ); failed } _ => { eprintln!("usage: a2600-gates die | timers [--every-row] | serial CONSOLE | hashes | hashes-rows"); std::process::exit(2); } }; eprintln!("({:.1} s)", started.elapsed().as_secs_f64()); std::process::exit(if failed == 0 { 0 } else { 1 }); }