// SPDX-License-Identifier: MIT //! Milestone 6: a2600-rust's gates, run through this board's 2600 mode (the reference's //! `scripts/gates_2600.py`, command for command). //! //! The gates live in `a2600::gates` (a2600-rust f9af024, transcribing a2600-python //! 28fb095's). Each takes the a2600-python checkout with its references fetched //! (`A2600_PYTHON_ROOT`, default `../a2600-python` beside this repository) and a factory //! for the candidate; the 2600 dumps are read from `$NO_INTRO_DIR/Atari - Atari 2600`. //! //! ```text //! a7800-gates die # every Sim2600 trace into a TIA made as board.rs makes it //! a7800-gates timers # Stella #108/#606 timer ROMs on both 7800 rows (make_system) //! a7800-gates smoke [CYCLES FRAMES] # gates::lockstep beside a2600-rust's own board, and //! # gates::run_hashes on both sides, for gates::smoke_names //! a7800-gates bios # six dumps from each BIOS row: 60 TIA frames' digests //! a7800-gates serial [PHASE] # the PAL 7800's seven #699 tables (PAL_7800) //! ``` //! //! `--fault NAME` (any command, before it) seeds a board fault into the 7800 side. //! Exit status 1 when any result fails. use std::path::PathBuf; use std::time::Instant; use a2600::cartridge::{load_default, read_image, Rom}; use a2600::gates::{ default_system, die_traces, dump_path, lockstep, run_hashes, serial_tables, smoke_names, timer_roms, }; use a2600::machine::{console_row, NTSC_7800}; use a2600::tia::TIA; use a7800::machine::{NTSC, PAL}; use a7800::mode2600::{make_system, row_console, System2600}; const BIOS_DUMPS: [&str; 6] = [ "Combat (Europe)", "Pitfall! - Pitfall Harry's Jungle Adventure (USA)", "Space Invaders (USA)", "Adventure (USA)", "River Raid (USA)", // DPC: its music oscillator counts the row's CPU clock (a2600-python 28fb095) "David Crane's Pitfall II - Lost Caverns (USA)", ]; 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"), } } /// A TIA as board.rs makes it: a2600-rust's type, the NTSC 7800 row's revision. fn board_tia() -> TIA { TIA::new(0, NTSC.mode_2600.tia_revision) } fn main() { let args: Vec = std::env::args().skip(1).collect(); let root = root(); let began = Instant::now(); let mut ok = true; match args.first().map(String::as_str) { Some("die") => { let results = die_traces(&root, &mut board_tia, None).expect("die traces"); let passed = results.values().filter(|r| r.2).count(); for (name, (_, bad, pass)) in &results { if !pass { println!(" FAIL {name}: {bad:?}"); } } println!( "die traces: {passed} of {} pass ({:.0} s)", results.len(), began.elapsed().as_secs_f64() ); ok &= passed == results.len(); } Some("timers") => { for machine in [NTSC, PAL] { // the row goes to the gate, which hands it to the factory (the console // results are NTSC 2600s': a pass says they reproduce on this row) let t = Instant::now(); let results = timer_roms(&root, &make_system, machine.mode_2600).expect("timer ROMs"); let passed = results.values().filter(|v| **v).count(); for (k, v) in &results { if !v { println!(" FAIL {k}"); } } println!( "timer ROMs on {}: {passed} of {} pass ({:.0} s)", machine.mode_2600.name, results.len(), t.elapsed().as_secs_f64() ); ok &= passed == results.len(); } } Some("smoke") => { let cycles: usize = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(1_000_000); let frames: u64 = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(30); let names = smoke_names(&root).expect("the smoke list"); let (mut same, mut refused) = (0, 0); for name in &names { let path = dump_path(name).expect("NO_INTRO_DIR"); if !path.exists() { println!(" missing: {name}"); continue; } let image = read_image(&path).expect("a dump").0; let (agreed, difference) = match lockstep(&image, &make_system, NTSC_7800, cycles) { Ok(r) => r, Err(e) => { refused += 1; println!(" {name}: not loadable on a2600-rust ({e})"); continue; } }; // gates::lockstep compares bus cycles only; the picture, the audio and the // registers at each frame's end come from gates::run_hashes on both sides. let mut hashes = Vec::new(); for factory in [default_system as fn(_, _) -> _, make_system] { let cartridge = load_default(Rom::Path(&path)).expect("a dump").cartridge; hashes.push(run_hashes(&mut factory(cartridge, NTSC_7800), frames)); } let pictures = hashes[0] == hashes[1]; if difference.is_none() && pictures { same += 1; } let mut verdict = match difference { None => "identical".to_string(), Some(d) => format!("{d:?}"), }; if !pictures { let parts: Vec<&str> = ["pixels", "audio", "registers"] .into_iter() .filter(|k| hashes[0][*k] != hashes[1][*k]) .collect(); verdict += &format!("; frame hashes differ: {}", parts.join(", ")); } println!(" {name}: {verdict} ({agreed} cycles, {frames} frames)"); } println!( "smoke group: {same} of {} identical to a2600-rust's board over {cycles} bus cycles and {frames} frames' hashes each, {} ({refused} not loadable; {:.0} s)", names.len(), NTSC_7800.name, began.elapsed().as_secs_f64() ); ok &= same + refused == names.len(); } Some("bios") => { for machine in [NTSC, PAL] { for name in BIOS_DUMPS { let t = Instant::now(); let image = read_image(&dump_path(name).expect("NO_INTRO_DIR")).expect("a dump").0; let mut system = System2600::from_rom(Rom::Bytes(&image), machine, "bios", None, 0, None, Default::default()) .expect("a BIOS start"); let frame = system.seven.board().maria.frame; // 60 TIA frames' digests (pixels, audio, registers), to compare runs let hashes = run_hashes(&mut system.system, 60); let digest: Vec = hashes.iter().map(|(k, v)| format!("{k} {}", &v[..12])).collect(); println!( " {}: {name}: BIOS handed over at MARIA frame {frame}, then 60 TIA frames: {} ({:.0} s)", machine.name, digest.join(" "), t.elapsed().as_secs_f64() ); } } } Some("serial") => { let phase: u32 = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let row = console_row("PAL_7800").expect("the PAL 7800 row"); let phased = move |cartridge, machine| { System2600::new( cartridge, row_console(&machine).expect("a 7800 row"), "direct", None, phase, ) .expect("a direct start") .system }; let results = serial_tables(&root, row, "PAL_7800", None, &phased).expect("the #699 tables"); let (mut matched, mut total) = (0, 0); for (rom, (m, t, misses)) in &results { matched += m; total += t; let first = misses .first() .map(|m| format!(", first miss {m:?}")) .unwrap_or_default(); println!(" {rom}: {m} of {t} cells{first}"); } println!( "#699 PAL_7800 tables on {}, phase +{phase} half clocks: {matched} of {total} cells ({:.0} s)", row.name, began.elapsed().as_secs_f64() ); ok &= matched == total; } _ => { eprintln!("usage: a7800-gates die | timers | smoke [CYCLES FRAMES] | bios | serial [PHASE]"); std::process::exit(2); } } std::process::exit(if ok { 0 } else { 1 }); }