Skip to content
Snippets Groups Projects
Verified Commit 77f78d43 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial support for clap CLI arg parsing

Allows for more flexibility passing command line arguments.
parent bf30fa95
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2587 failed
......@@ -13,6 +13,10 @@ debug = ["boytacean/debug"]
pedantic = ["boytacean/pedantic"]
cpulog = ["boytacean/cpulog"]
[dependencies.clap]
version = "4"
features = ["derive"]
[dependencies.boytacean]
path = "../.."
......
......@@ -13,6 +13,7 @@ use boytacean::{
ppu::{PaletteInfo, PpuMode, DISPLAY_HEIGHT, DISPLAY_WIDTH},
};
use chrono::Utc;
use clap::Parser;
use graphics::{surface_from_bytes, Graphics};
use image::ColorType;
use sdl2::{event::Event, keyboard::Keycode, pixels::PixelFormatEnum, Sdl};
......@@ -455,8 +456,21 @@ impl Emulator {
}
}
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long, default_value_t = String::from("cgb"))]
mode: String,
#[arg(short, long, default_value_t = String::from("../../res/roms.prop/tetris_dx.gbc"))]
rom_path: String,
}
fn main() {
let mode = GameBoyMode::Cgb;
// parses the provided command line arguments and uses them to
// obtain structured values
let args = Args::parse();
let mode = GameBoyMode::from_str(&args.mode);
// prints the current version of the emulator (informational message)
println!("Boytacean v{} - {}", VERSION, mode);
......@@ -484,7 +498,7 @@ fn main() {
// ROM file and starts running it
let mut emulator = Emulator::new(game_boy);
emulator.start(SCREEN_SCALE);
emulator.load_rom(Some("../../res/roms.prop/tetris_dx.gbc"));
emulator.load_rom(Some(&args.rom_path));
//emulator.load_rom(Some("../../res/roms/demo/pocket.gb"));
emulator.toggle_palette();
emulator.run();
......
......@@ -56,6 +56,24 @@ impl GameBoyMode {
GameBoyMode::Sgb => "Super Game Boy (SGB)",
}
}
pub fn from_u8(value: u8) -> GameBoyMode {
match value {
1 => GameBoyMode::Dmg,
2 => GameBoyMode::Cgb,
3 => GameBoyMode::Sgb,
_ => panic!("Invalid mode value: {}", value),
}
}
pub fn from_str(value: &str) -> GameBoyMode {
match value {
"dmg" => GameBoyMode::Dmg,
"cgb" => GameBoyMode::Cgb,
"sgb" => GameBoyMode::Sgb,
_ => panic!("Invalid mode value: {}", value),
}
}
}
impl Display for GameBoyMode {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment