save path as option

This commit is contained in:
Alex Janka 2023-03-02 19:10:50 +11:00
parent 2ba3de1894
commit 717bba9352
2 changed files with 13 additions and 3 deletions

View file

@ -30,6 +30,7 @@ pub mod util;
pub struct Options {
pub rom_path: String,
pub save_path: Option<String>,
pub bootrom_path: Option<String>,
pub connect_serial: bool,
pub verbose: bool,
@ -53,9 +54,13 @@ pub fn init(
) {
VERBOSE.set(options.verbose).unwrap();
let maybe_save = PathBuf::from_str(&options.rom_path)
.unwrap()
.with_extension("sav");
let maybe_save = 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) {
Ok(data) => Rom::load(data, maybe_save),

View file

@ -22,6 +22,10 @@ struct Args {
#[arg(short, long)]
rom: String,
/// Save path
#[arg(long)]
save_path: Option<String>,
/// BootROM path
#[arg(short, long)]
bootrom: Option<String>,
@ -62,6 +66,7 @@ fn main() {
let options = gb_emu::Options {
rom_path: args.rom,
save_path: args.save_path,
bootrom_path: args.bootrom,
connect_serial: args.connect_serial,
verbose: args.verbose,