added a state dumper for headless checks
This commit is contained in:
+24
-2
@@ -5,6 +5,7 @@ mod mapper;
|
||||
mod palette;
|
||||
mod render;
|
||||
mod ppu;
|
||||
mod dump;
|
||||
|
||||
use crate::bus::{Bus, NesBus};
|
||||
use crate::cartridge::Cartridge;
|
||||
@@ -17,6 +18,7 @@ fn main() {
|
||||
match args.len() {
|
||||
1 => run_nestest(),
|
||||
3 if args[1] == "blargg" => run_blargg(&args[2]),
|
||||
3 if args[1] == "dbg" => run_dbg(&args[2]),
|
||||
2 => run_cart(&args[1]),
|
||||
_ => eprintln!("usage: rnes [<rom> | blargg <rom>]"),
|
||||
}
|
||||
@@ -28,14 +30,14 @@ fn run_cart(path: &str) {
|
||||
let mut cpu = Cpu::new();
|
||||
cpu.reset(&mut bus);
|
||||
let mut renderer = PpmRenderer::new();
|
||||
let frames: u32 = 60;
|
||||
let frames: u32 = 180;
|
||||
|
||||
for _ in 0..frames {
|
||||
while !bus.frame_done() {
|
||||
let cycles = cpu.step(&mut bus);
|
||||
bus.tick_ppu(cycles as u64);
|
||||
if bus.take_nmi() { cpu.set_nmi(); } // NMI fires when vblank hits, mid-frame
|
||||
}
|
||||
if bus.take_nmi() { cpu.set_nmi(); }
|
||||
renderer.present(bus.framebuffer(), 256, 240);
|
||||
bus.begin_frame();
|
||||
}
|
||||
@@ -70,3 +72,23 @@ fn run_nestest() {
|
||||
cpu.step(&mut bus);
|
||||
}
|
||||
}
|
||||
|
||||
fn run_dbg(path: &str) {
|
||||
let cart = Cartridge::from_file(path).unwrap();
|
||||
let mut bus = NesBus::new(cart);
|
||||
let mut cpu = Cpu::new();
|
||||
cpu.reset(&mut bus);
|
||||
let mut dumper = dump::Dumper::new();
|
||||
let frames: u32 = 180;
|
||||
|
||||
for f in 0..frames {
|
||||
while !bus.frame_done() {
|
||||
let cycles = cpu.step(&mut bus);
|
||||
bus.tick_ppu(cycles as u64);
|
||||
if bus.take_nmi() { cpu.set_nmi(); }
|
||||
}
|
||||
dumper.snapshot(f, &bus, &cpu);
|
||||
bus.begin_frame();
|
||||
}
|
||||
println!("wrote debug_out/ (state.txt + pctrace.txt), {frames} frames");
|
||||
}
|
||||
Reference in New Issue
Block a user