args better typed
This commit is contained in:
parent
4128a93f54
commit
5078712142
2 changed files with 30 additions and 23 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#[cfg(feature = "camera")]
|
#[cfg(feature = "camera")]
|
||||||
use camera::Webcam;
|
use camera::Webcam;
|
||||||
use clap::{ArgGroup, Parser};
|
use clap::{ArgGroup, Parser, ValueEnum};
|
||||||
use debug::Debugger;
|
use debug::Debugger;
|
||||||
use gb_emu_lib::{
|
use gb_emu_lib::{
|
||||||
config::ConfigManager,
|
config::ConfigManager,
|
||||||
|
@ -32,30 +32,43 @@ compile_error!("select only one rendering backend!");
|
||||||
#[cfg(all(not(feature = "vulkan"), not(feature = "pixels")))]
|
#[cfg(all(not(feature = "vulkan"), not(feature = "pixels")))]
|
||||||
compile_error!("select one rendering backend!");
|
compile_error!("select one rendering backend!");
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Debug, Clone, Copy)]
|
||||||
|
enum SerialTargetOption {
|
||||||
|
None,
|
||||||
|
Ascii,
|
||||||
|
Hex,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SerialTargetOption> for SerialTarget {
|
||||||
|
fn from(value: SerialTargetOption) -> Self {
|
||||||
|
match value {
|
||||||
|
SerialTargetOption::None => Self::None,
|
||||||
|
SerialTargetOption::Ascii => Self::Stdout(StdoutType::Ascii),
|
||||||
|
SerialTargetOption::Hex => Self::Stdout(StdoutType::Hex),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Gameboy (DMG/CGB) emulator
|
/// Gameboy (DMG/CGB) emulator
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
||||||
#[command(group(ArgGroup::new("link").args(["ascii","hex"])))]
|
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Path to ROM
|
/// Path to ROM
|
||||||
rom: String,
|
#[arg(value_hint = clap::ValueHint::FilePath)]
|
||||||
|
rom: PathBuf,
|
||||||
|
|
||||||
/// Save path
|
/// Save path
|
||||||
#[arg(long)]
|
#[arg(long, value_hint = clap::ValueHint::FilePath)]
|
||||||
save: Option<String>,
|
save: Option<PathBuf>,
|
||||||
|
|
||||||
/// Skip save file
|
/// Skip save file
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
no_save: bool,
|
no_save: bool,
|
||||||
|
|
||||||
/// Output link port to stdout as ASCII
|
/// Output link port to stdout as either ASCII or hex
|
||||||
#[arg(long)]
|
#[arg(long, value_enum, default_value_t = SerialTargetOption::None)]
|
||||||
ascii: bool,
|
serial: SerialTargetOption,
|
||||||
|
|
||||||
/// Output link port to stdout as hex values
|
|
||||||
#[arg(long)]
|
|
||||||
hex: bool,
|
|
||||||
|
|
||||||
/// Show tile window
|
/// Show tile window
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
@ -131,7 +144,7 @@ fn run(args: Args) -> ! {
|
||||||
let config = config_manager.load_or_create_base_config();
|
let config = config_manager.load_or_create_base_config();
|
||||||
let standalone_config: StandaloneConfig = config_manager.load_or_create_config("standalone");
|
let standalone_config: StandaloneConfig = config_manager.load_or_create_config("standalone");
|
||||||
|
|
||||||
let rom_file = RomFile::Path(PathBuf::from(args.rom));
|
let rom_file = RomFile::Path(args.rom);
|
||||||
|
|
||||||
let (rom, camera) = rom_file
|
let (rom, camera) = rom_file
|
||||||
.load(
|
.load(
|
||||||
|
@ -203,13 +216,7 @@ fn run(args: Args) -> ! {
|
||||||
|
|
||||||
let options =
|
let options =
|
||||||
EmulatorOptions::new_with_config(config, config_manager.dir(), window, rom, output)
|
EmulatorOptions::new_with_config(config, config_manager.dir(), window, rom, output)
|
||||||
.with_serial_target(if args.ascii {
|
.with_serial_target(args.serial.into())
|
||||||
SerialTarget::Stdout(StdoutType::Ascii)
|
|
||||||
} else if args.hex {
|
|
||||||
SerialTarget::Stdout(StdoutType::Hex)
|
|
||||||
} else {
|
|
||||||
SerialTarget::None
|
|
||||||
})
|
|
||||||
.with_no_save(args.no_save)
|
.with_no_save(args.no_save)
|
||||||
.with_tile_window(tile_window)
|
.with_tile_window(tile_window)
|
||||||
.with_layer_window(layer_window);
|
.with_layer_window(layer_window);
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl RomFile {
|
||||||
match self {
|
match self {
|
||||||
RomFile::Path(path) => {
|
RomFile::Path(path) => {
|
||||||
let save_location = match save {
|
let save_location = match save {
|
||||||
SramType::File(path) => Some(SaveDataLocation::File(PathBuf::from(path))),
|
SramType::File(path) => Some(SaveDataLocation::File(path)),
|
||||||
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
|
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
|
||||||
SramType::Auto => Some(SaveDataLocation::File(path.with_extension("sav"))),
|
SramType::Auto => Some(SaveDataLocation::File(path.with_extension("sav"))),
|
||||||
SramType::None => None,
|
SramType::None => None,
|
||||||
|
@ -55,7 +55,7 @@ impl RomFile {
|
||||||
}
|
}
|
||||||
RomFile::Raw(data) => {
|
RomFile::Raw(data) => {
|
||||||
let save_location = match save {
|
let save_location = match save {
|
||||||
SramType::File(path) => Some(SaveDataLocation::File(PathBuf::from(path))),
|
SramType::File(path) => Some(SaveDataLocation::File(path)),
|
||||||
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
|
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
|
||||||
SramType::Auto => None,
|
SramType::Auto => None,
|
||||||
SramType::None => None,
|
SramType::None => None,
|
||||||
|
@ -213,7 +213,7 @@ where
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SramType {
|
pub enum SramType {
|
||||||
File(String),
|
File(PathBuf),
|
||||||
RawBuffer(Arc<RwLock<Vec<u8>>>),
|
RawBuffer(Arc<RwLock<Vec<u8>>>),
|
||||||
Auto,
|
Auto,
|
||||||
None,
|
None,
|
||||||
|
|
Loading…
Add table
Reference in a new issue