// SPDX-License-Identifier: MIT //! Rung 4: MAME 0.285's traces of real SPC700 code replayed on the core (the //! reference's `tests/test_replay.py` over `replay.replay_file`). //! //! mame_replay IPL_ROM ERROR_LOG [--limit N] //! //! Prints one summary line, in the form `scripts/reference_replay.py` prints //! from the reference: the lines compared, the I/O reads answered and writes //! compared, the unlogged dummy reads and the dropped repeated reads, the //! distinct opcodes, and the first divergence (its position and problems) or //! none. Exit status 1 on a divergence. use std::io::BufReader; use spc700::replay::{parse_trace, replay, START_PC}; fn main() { let args: Vec = std::env::args().skip(1).collect(); if args.len() < 2 { eprintln!("usage: mame_replay IPL_ROM ERROR_LOG [--limit N]"); std::process::exit(2); } let ipl: [u8; 64] = std::fs::read(&args[0]) .expect("IPL ROM") .try_into() .expect("the IPL ROM is 64 bytes"); let limit = args .iter() .position(|a| a == "--limit") .map(|i| args[i + 1].parse::().expect("--limit N")); let file = std::fs::File::open(&args[1]).expect("error.log"); let lines = parse_trace(BufReader::with_capacity(1 << 20, file), START_PC); let result = replay(lines, ipl, limit).unwrap_or_else(|e| panic!("{e}")); let divergence = match &result.divergence { None => "none".to_string(), Some(d) => format!( "at line {} (MAME PC={:04X}): {}", d.position, d.line.pc, d.problems.join("; ") ), }; println!( "compared {}, I/O reads {}, I/O writes {}, unlogged dummy reads {}, repeated reads {}, opcodes {}, divergence {divergence}", result.compared, result.io_reads, result.io_writes, result.unlogged_dummy_reads, result.repeated_reads, result.opcodes.len() ); std::process::exit(if result.ok() { 0 } else { 1 }); }