ui.rs: Refactor debug screen dump: dumps to pwd with good name

This commit is contained in:
John 2023-04-17 06:35:16 -05:00
parent 45adf0a2b8
commit 0113dd95f6

View File

@ -5,7 +5,6 @@
//! TODO: Destroy this all. //! TODO: Destroy this all.
use std::{ use std::{
ffi::OsStr,
path::{Path, PathBuf}, path::{Path, PathBuf},
time::Instant, time::Instant,
}; };
@ -267,29 +266,28 @@ pub fn identify_key(key: Key) -> Option<usize> {
} }
pub fn debug_dump_screen(ch8: &Chip8, rom: &Path) -> Result<()> { pub fn debug_dump_screen(ch8: &Chip8, rom: &Path) -> Result<()> {
let path = PathBuf::new() let mut path = PathBuf::new().join(format!(
.join("src/cpu/tests/screens/") "{}_{}.bin",
.join(if rom.is_absolute() { rom.file_stem().unwrap_or_default().to_string_lossy(),
Path::new("unknown/") ch8.cpu.cycle()
} else { ));
rom.file_name().unwrap_or(OsStr::new("unknown")).as_ref() path.set_extension("bin");
}) if let Ok(_) = std::fs::write(
.join(format!("{}.bin", ch8.cpu.cycle()));
std::fs::write(
&path, &path,
ch8.bus ch8.bus
.get_region(Region::Screen) .get_region(Region::Screen)
.expect("Region::Screen should exist"), .expect("Region::Screen should exist"),
) ) {
.unwrap_or_else(|_| { eprintln!("Saved to {}", &path.display());
std::fs::write( } else if let Ok(_) = std::fs::write(
"screendump.bin", "screen_dump.bin",
ch8.bus ch8.bus
.get_region(Region::Screen) .get_region(Region::Screen)
.expect("Region::Screen should exist"), .expect("Region::Screen should exist"),
) ) {
.ok(); // lmao eprintln!("Saved to screen_dump.bin");
}); } else {
eprintln!("Saved to {}", &path.display()); eprintln!("Failed to dump screen to file.")
}
Ok(()) Ok(())
} }