optional skip save

This commit is contained in:
Alex Janka 2023-03-03 09:40:16 +11:00
parent d8771a27a3
commit 1de1d817ce
3 changed files with 24 additions and 13 deletions

View file

@ -31,6 +31,7 @@ pub mod util;
pub struct Options { pub struct Options {
pub rom_path: String, pub rom_path: String,
pub save_path: Option<String>, pub save_path: Option<String>,
pub no_save: bool,
pub bootrom_path: Option<String>, pub bootrom_path: Option<String>,
pub connect_serial: bool, pub connect_serial: bool,
pub verbose: bool, pub verbose: bool,
@ -54,12 +55,16 @@ pub fn init(
) { ) {
VERBOSE.set(options.verbose).unwrap(); VERBOSE.set(options.verbose).unwrap();
let maybe_save = if let Some(path) = options.save_path { let maybe_save = if options.no_save {
PathBuf::from_str(&path).unwrap() None
} else { } else {
PathBuf::from_str(&options.rom_path) Some(if let Some(path) = options.save_path {
.unwrap() PathBuf::from_str(&path).unwrap()
.with_extension("sav") } else {
PathBuf::from_str(&options.rom_path)
.unwrap()
.with_extension("sav")
})
}; };
let rom: Rom = match fs::read(options.rom_path) { let rom: Rom = match fs::read(options.rom_path) {

View file

@ -17,6 +17,7 @@ use minifb::{Key, Window, WindowOptions};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
#[command(group(ArgGroup::new("prints").args(["verbose","cycle_count"])))] #[command(group(ArgGroup::new("prints").args(["verbose","cycle_count"])))]
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
struct Args { struct Args {
/// ROM path /// ROM path
#[arg(short, long)] #[arg(short, long)]
@ -26,6 +27,10 @@ struct Args {
#[arg(long)] #[arg(long)]
save: Option<String>, save: Option<String>,
/// Skip save file
#[arg(long)]
no_save: bool,
/// BootROM path /// BootROM path
#[arg(short, long)] #[arg(short, long)]
bootrom: Option<String>, bootrom: Option<String>,
@ -67,6 +72,7 @@ fn main() {
let options = gb_emu::Options { let options = gb_emu::Options {
rom_path: args.rom, rom_path: args.rom,
save_path: args.save, save_path: args.save,
no_save: args.no_save,
bootrom_path: args.bootrom, bootrom_path: args.bootrom,
connect_serial: args.connect_serial, connect_serial: args.connect_serial,
verbose: args.verbose, verbose: args.verbose,

View file

@ -97,7 +97,7 @@ pub struct Rom {
} }
impl Rom { impl Rom {
pub fn load(data: Vec<u8>, save_path: PathBuf) -> Self { pub fn load(data: Vec<u8>, save_path: Option<PathBuf>) -> Self {
let mut title_length = 0x143; let mut title_length = 0x143;
for (i, val) in data.iter().enumerate().take(0x143).skip(0x134) { for (i, val) in data.iter().enumerate().take(0x143).skip(0x134) {
title_length = i; title_length = i;
@ -114,20 +114,20 @@ impl Rom {
0x00 => Box::new(None::init(data)), 0x00 => Box::new(None::init(data)),
0x01 => Box::new(Mbc1::init(data, rom_size, 0, None)), 0x01 => Box::new(Mbc1::init(data, rom_size, 0, None)),
0x02 => Box::new(Mbc1::init(data, rom_size, ram_size, 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)), 0x05 => Box::new(Mbc2::init(data, rom_size, None)),
0x06 => Box::new(Mbc2::init(data, rom_size, Some(save_path))), 0x06 => Box::new(Mbc2::init(data, rom_size, save_path)),
0x0F => Box::new(Mbc3::init(data, rom_size, 0, true, Some(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, Some(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)), 0x11 => Box::new(Mbc3::init(data, rom_size, 0, false, None)),
0x12 => Box::new(Mbc3::init(data, rom_size, ram_size, 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)), 0x19 => Box::new(Mbc5::init(data, rom_size, 0, false, None)),
0x1A => Box::new(Mbc5::init(data, rom_size, ram_size, 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)), 0x1C => Box::new(Mbc5::init(data, rom_size, 0, true, None)),
0x1D => Box::new(Mbc5::init(data, rom_size, ram_size, 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]), _ => panic!("unimplemented mbc: {:#X}", data[0x147]),
}; };
Self { title, mbc } Self { title, mbc }