diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index 0a1c689..c2d5914 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -2,7 +2,7 @@ #[cfg(feature = "camera")] use camera::Webcam; -use clap::{ArgGroup, Parser}; +use clap::{ArgGroup, Parser, ValueEnum}; use debug::Debugger; use gb_emu_lib::{ config::ConfigManager, @@ -32,30 +32,43 @@ compile_error!("select only one rendering backend!"); #[cfg(all(not(feature = "vulkan"), not(feature = "pixels")))] compile_error!("select one rendering backend!"); +#[derive(ValueEnum, Debug, Clone, Copy)] +enum SerialTargetOption { + None, + Ascii, + Hex, +} + +impl From 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 #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] #[command(group(ArgGroup::new("saves").args(["save","no_save"])))] -#[command(group(ArgGroup::new("link").args(["ascii","hex"])))] struct Args { /// Path to ROM - rom: String, + #[arg(value_hint = clap::ValueHint::FilePath)] + rom: PathBuf, /// Save path - #[arg(long)] - save: Option, + #[arg(long, value_hint = clap::ValueHint::FilePath)] + save: Option, /// Skip save file #[arg(long)] no_save: bool, - /// Output link port to stdout as ASCII - #[arg(long)] - ascii: bool, - - /// Output link port to stdout as hex values - #[arg(long)] - hex: bool, + /// Output link port to stdout as either ASCII or hex + #[arg(long, value_enum, default_value_t = SerialTargetOption::None)] + serial: SerialTargetOption, /// Show tile window #[arg(long)] @@ -131,7 +144,7 @@ fn run(args: Args) -> ! { let config = config_manager.load_or_create_base_config(); 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 .load( @@ -203,13 +216,7 @@ fn run(args: Args) -> ! { let options = EmulatorOptions::new_with_config(config, config_manager.dir(), window, rom, output) - .with_serial_target(if args.ascii { - SerialTarget::Stdout(StdoutType::Ascii) - } else if args.hex { - SerialTarget::Stdout(StdoutType::Hex) - } else { - SerialTarget::None - }) + .with_serial_target(args.serial.into()) .with_no_save(args.no_save) .with_tile_window(tile_window) .with_layer_window(layer_window); diff --git a/lib/src/connect/mod.rs b/lib/src/connect/mod.rs index 8d747d0..b064517 100644 --- a/lib/src/connect/mod.rs +++ b/lib/src/connect/mod.rs @@ -45,7 +45,7 @@ impl RomFile { match self { RomFile::Path(path) => { 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::Auto => Some(SaveDataLocation::File(path.with_extension("sav"))), SramType::None => None, @@ -55,7 +55,7 @@ impl RomFile { } RomFile::Raw(data) => { 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::Auto => None, SramType::None => None, @@ -213,7 +213,7 @@ where #[derive(Debug)] pub enum SramType { - File(String), + File(PathBuf), RawBuffer(Arc>>), Auto, None,