feat(save_override): Add option to override save type via commandline
Former-commit-id: c4a00744ba20baf5f68072d6b9583616f61417e8
This commit is contained in:
parent
5fc38546ce
commit
bb111f0d0b
|
@ -1,4 +1,5 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
mod backup_file;
|
mod backup_file;
|
||||||
pub use backup_file::BackupFile;
|
pub use backup_file::BackupFile;
|
||||||
|
@ -15,6 +16,22 @@ pub enum BackupType {
|
||||||
AutoDetect = 5,
|
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 {
|
pub trait BackupMemoryInterface: Sized + fmt::Debug {
|
||||||
fn write(&mut self, offset: usize, value: u8);
|
fn write(&mut self, offset: usize, value: u8);
|
||||||
fn read(&self, offset: usize) -> u8;
|
fn read(&self, offset: usize) -> u8;
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod backup;
|
||||||
use backup::eeprom::SpiController;
|
use backup::eeprom::SpiController;
|
||||||
use backup::flash::Flash;
|
use backup::flash::Flash;
|
||||||
use backup::{BackupFile, BackupMemoryInterface};
|
use backup::{BackupFile, BackupMemoryInterface};
|
||||||
|
pub use backup::BackupType;
|
||||||
|
|
||||||
mod builder;
|
mod builder;
|
||||||
pub use builder::GamepakBuilder;
|
pub use builder::GamepakBuilder;
|
||||||
|
|
|
@ -13,6 +13,17 @@ args:
|
||||||
help: Sets the game-rom file to use
|
help: Sets the game-rom file to use
|
||||||
required: false
|
required: false
|
||||||
index: 1
|
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:
|
- skip_bios:
|
||||||
long: skip-bios
|
long: skip-bios
|
||||||
help: Skip running bios and start from the ROM instead
|
help: Skip running bios and start from the ROM instead
|
||||||
|
|
|
@ -17,6 +17,8 @@ use std::path::{Path, PathBuf};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ use input::create_input;
|
||||||
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
|
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||||
|
|
||||||
extern crate rustboyadvance_ng;
|
extern crate rustboyadvance_ng;
|
||||||
|
use rustboyadvance_ng::core::cartridge::BackupType;
|
||||||
use rustboyadvance_ng::prelude::*;
|
use rustboyadvance_ng::prelude::*;
|
||||||
use rustboyadvance_ng::util::FpsCounter;
|
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 savestate_path = get_savestate_path(&Path::new(&rom_path));
|
||||||
|
|
||||||
let mut rom_name = Path::new(&rom_path).file_name().unwrap().to_str().unwrap();
|
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(
|
let mut gba = GameBoyAdvance::new(
|
||||||
arm7tdmi::Core::new(),
|
arm7tdmi::Core::new(),
|
||||||
|
|
Reference in a new issue