From 1de1d817ceea8535bcca88282a51a706218d04cb Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Fri, 3 Mar 2023 09:40:16 +1100 Subject: [PATCH] optional skip save --- src/lib.rs | 15 ++++++++++----- src/main.rs | 6 ++++++ src/processor/memory/rom.rs | 16 ++++++++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 302a87e..bdbce77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ pub mod util; pub struct Options { pub rom_path: String, pub save_path: Option, + pub no_save: bool, pub bootrom_path: Option, pub connect_serial: bool, pub verbose: bool, @@ -54,12 +55,16 @@ pub fn init( ) { VERBOSE.set(options.verbose).unwrap(); - let maybe_save = if let Some(path) = options.save_path { - PathBuf::from_str(&path).unwrap() + let maybe_save = if options.no_save { + None } else { - PathBuf::from_str(&options.rom_path) - .unwrap() - .with_extension("sav") + Some(if let Some(path) = options.save_path { + PathBuf::from_str(&path).unwrap() + } else { + PathBuf::from_str(&options.rom_path) + .unwrap() + .with_extension("sav") + }) }; let rom: Rom = match fs::read(options.rom_path) { diff --git a/src/main.rs b/src/main.rs index 36a7178..c3ba034 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ use minifb::{Key, Window, WindowOptions}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] #[command(group(ArgGroup::new("prints").args(["verbose","cycle_count"])))] +#[command(group(ArgGroup::new("saves").args(["save","no_save"])))] struct Args { /// ROM path #[arg(short, long)] @@ -26,6 +27,10 @@ struct Args { #[arg(long)] save: Option, + /// Skip save file + #[arg(long)] + no_save: bool, + /// BootROM path #[arg(short, long)] bootrom: Option, @@ -67,6 +72,7 @@ fn main() { let options = gb_emu::Options { rom_path: args.rom, save_path: args.save, + no_save: args.no_save, bootrom_path: args.bootrom, connect_serial: args.connect_serial, verbose: args.verbose, diff --git a/src/processor/memory/rom.rs b/src/processor/memory/rom.rs index 2af2dd1..9cf6b01 100644 --- a/src/processor/memory/rom.rs +++ b/src/processor/memory/rom.rs @@ -97,7 +97,7 @@ pub struct Rom { } impl Rom { - pub fn load(data: Vec, save_path: PathBuf) -> Self { + pub fn load(data: Vec, save_path: Option) -> Self { let mut title_length = 0x143; for (i, val) in data.iter().enumerate().take(0x143).skip(0x134) { title_length = i; @@ -114,20 +114,20 @@ impl Rom { 0x00 => Box::new(None::init(data)), 0x01 => Box::new(Mbc1::init(data, rom_size, 0, None)), 0x02 => Box::new(Mbc1::init(data, rom_size, ram_size, None)), - 0x03 => Box::new(Mbc1::init(data, rom_size, ram_size, Some(save_path))), + 0x03 => Box::new(Mbc1::init(data, rom_size, ram_size, save_path)), 0x05 => Box::new(Mbc2::init(data, rom_size, None)), - 0x06 => Box::new(Mbc2::init(data, rom_size, Some(save_path))), - 0x0F => Box::new(Mbc3::init(data, rom_size, 0, true, Some(save_path))), - 0x10 => Box::new(Mbc3::init(data, rom_size, ram_size, true, Some(save_path))), + 0x06 => Box::new(Mbc2::init(data, rom_size, save_path)), + 0x0F => Box::new(Mbc3::init(data, rom_size, 0, true, save_path)), + 0x10 => Box::new(Mbc3::init(data, rom_size, ram_size, true, save_path)), 0x11 => Box::new(Mbc3::init(data, rom_size, 0, false, None)), 0x12 => Box::new(Mbc3::init(data, rom_size, ram_size, false, None)), - 0x13 => Box::new(Mbc3::init(data, rom_size, ram_size, false, Some(save_path))), + 0x13 => Box::new(Mbc3::init(data, rom_size, ram_size, false, save_path)), 0x19 => Box::new(Mbc5::init(data, rom_size, 0, false, None)), 0x1A => Box::new(Mbc5::init(data, rom_size, ram_size, false, None)), - 0x1B => Box::new(Mbc5::init(data, rom_size, ram_size, false, Some(save_path))), + 0x1B => Box::new(Mbc5::init(data, rom_size, ram_size, false, save_path)), 0x1C => Box::new(Mbc5::init(data, rom_size, 0, true, None)), 0x1D => Box::new(Mbc5::init(data, rom_size, ram_size, true, None)), - 0x1E => Box::new(Mbc5::init(data, rom_size, ram_size, true, Some(save_path))), + 0x1E => Box::new(Mbc5::init(data, rom_size, ram_size, true, save_path)), _ => panic!("unimplemented mbc: {:#X}", data[0x147]), }; Self { title, mbc }