feat(save_override): Add option to override save type via commandline

Former-commit-id: c4a00744ba20baf5f68072d6b9583616f61417e8
This commit is contained in:
Michel Heily 2020-01-31 14:47:27 +02:00
parent 5fc38546ce
commit bb111f0d0b
4 changed files with 39 additions and 1 deletions

View file

@ -1,4 +1,5 @@
use std::fmt;
use std::convert::TryFrom;
mod backup_file;
pub use backup_file::BackupFile;
@ -15,6 +16,22 @@ pub enum BackupType {
AutoDetect = 5,
}
impl TryFrom<&str> for BackupType {
type Error = String;
fn try_from(s: &str) -> Result<Self, Self::Error> {
use BackupType::*;
match s {
"autodetect" => Ok(AutoDetect),
"sram" => Ok(Sram),
"flash128k" => Ok(Flash1M),
"flash64k" => Ok(Flash512),
"eeprom" => Ok(Eeprom),
_ => Err(format!("{} is not a valid save type", s))
}
}
}
pub trait BackupMemoryInterface: Sized + fmt::Debug {
fn write(&mut self, offset: usize, value: u8);
fn read(&self, offset: usize) -> u8;

View file

@ -9,6 +9,7 @@ mod backup;
use backup::eeprom::SpiController;
use backup::flash::Flash;
use backup::{BackupFile, BackupMemoryInterface};
pub use backup::BackupType;
mod builder;
pub use builder::GamepakBuilder;

View file

@ -13,6 +13,17 @@ args:
help: Sets the game-rom file to use
required: false
index: 1
- save_type:
short: s
help: Override save type, useful for troublemaking games that fool the auto detection
required: false
default_value: autodetect
possible_values:
- sram
- flash128k
- flash64k
- eeprom
- autodetect
- skip_bios:
long: skip-bios
help: Skip running bios and start from the ROM instead

View file

@ -17,6 +17,8 @@ use std::path::{Path, PathBuf};
use std::process;
use std::time;
use std::convert::TryFrom;
#[macro_use]
extern crate clap;
@ -34,6 +36,7 @@ use input::create_input;
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
extern crate rustboyadvance_ng;
use rustboyadvance_ng::core::cartridge::BackupType;
use rustboyadvance_ng::prelude::*;
use rustboyadvance_ng::util::FpsCounter;
@ -123,7 +126,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut savestate_path = get_savestate_path(&Path::new(&rom_path));
let mut rom_name = Path::new(&rom_path).file_name().unwrap().to_str().unwrap();
let gamepak = GamepakBuilder::new().file(Path::new(&rom_path)).build()?;
let gamepak = GamepakBuilder::new()
.save_type(BackupType::try_from(
matches.value_of("save_type").unwrap(),
)?)
.file(Path::new(&rom_path))
.build()?;
let mut gba = GameBoyAdvance::new(
arm7tdmi::Core::new(),