optional skip save
This commit is contained in:
parent
d8771a27a3
commit
1de1d817ce
15
src/lib.rs
15
src/lib.rs
|
@ -31,6 +31,7 @@ pub mod util;
|
|||
pub struct Options {
|
||||
pub rom_path: String,
|
||||
pub save_path: Option<String>,
|
||||
pub no_save: bool,
|
||||
pub bootrom_path: Option<String>,
|
||||
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) {
|
||||
|
|
|
@ -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<String>,
|
||||
|
||||
/// Skip save file
|
||||
#[arg(long)]
|
||||
no_save: bool,
|
||||
|
||||
/// BootROM path
|
||||
#[arg(short, long)]
|
||||
bootrom: Option<String>,
|
||||
|
@ -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,
|
||||
|
|
|
@ -97,7 +97,7 @@ pub struct 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;
|
||||
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 }
|
||||
|
|
Loading…
Reference in a new issue