use anyhow::Result; use clap::Parser; use egui::{Color32, Vec2}; use serde::{Deserialize, Serialize}; use crate::{emulator::SimId, persistence::Persistence, window::DisplayMode}; use std::path::PathBuf; #[derive(Parser)] pub struct CliArgs { /// The path to a virtual boy ROM to run. pub rom: Option, /// Start a GDB/LLDB debug server on this port. #[arg(short, long)] pub debug_port: Option, /// Enable profiling a game #[arg(short, long)] pub profile: bool, /// Open character data window #[arg(short, long)] pub character_data: bool, /// Open bgmap data window #[arg(short, long)] pub bgmap_data: bool, /// Open object data window #[arg(short, long)] pub object_data: bool, /// Open worlds window #[arg(long)] pub worlds: bool, /// Open frame buffers window #[arg(short, long)] pub frame_buffers: bool, /// Open registers window #[arg(short, long)] pub registers: bool, /// Open terminal #[arg(short, long)] pub terminal: bool, /// Watch ROM files for changes, automatically reload #[arg(short, long)] pub watch: bool, } pub const COLOR_PRESETS: [[Color32; 2]; 3] = [ [ Color32::from_rgb(0xff, 0x00, 0x00), Color32::from_rgb(0x00, 0xc6, 0xf0), ], [ Color32::from_rgb(0x00, 0xb4, 0x00), Color32::from_rgb(0xc8, 0x00, 0xff), ], [ Color32::from_rgb(0xb4, 0x9b, 0x00), Color32::from_rgb(0x00, 0x00, 0xff), ], ]; const fn default_audio_enabled() -> bool { true } #[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct SimConfig { pub display_mode: DisplayMode, pub colors: [Color32; 2], pub dimensions: Vec2, #[serde(default = "default_audio_enabled")] pub audio_enabled: bool, } impl SimConfig { pub fn load(persistence: &Persistence, sim_id: SimId) -> Self { if let Ok(config) = persistence.load_config(config_filename(sim_id)) { return config; } Self { display_mode: DisplayMode::Anaglyph, colors: COLOR_PRESETS[0], dimensions: DisplayMode::Anaglyph.proportions() + Vec2::new(0.0, 22.0), audio_enabled: true, } } pub fn save(&self, persistence: &Persistence, sim_id: SimId) -> Result<()> { persistence.save_config(config_filename(sim_id), self) } } fn config_filename(sim_id: SimId) -> &'static str { match sim_id { SimId::Player1 => "config_p1", SimId::Player2 => "config_p2", } }