diff --git a/src/main.rs b/src/main.rs index e39f3c8..eb5564e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,11 @@ const PREFIX: Option<&'static str> = option_env!("PREFIX"); /** * Return firmware paths in priority order. */ -pub fn firmware_paths(ver: parse_args::FirmwareVer, explicit_path: Option, is_mos: bool) -> Vec { +pub fn firmware_paths( + ver: parse_args::FirmwareVer, + explicit_path: Option, + is_mos: bool, +) -> Vec { let mut paths: Vec = vec![]; if let Some(ref p) = explicit_path { @@ -28,20 +32,19 @@ pub fn firmware_paths(ver: parse_args::FirmwareVer, explicit_path: Option std::path::Path::new(".").join("firmware"), - Some(prefix) => std::path::Path::new(prefix) - .join("share") - .join("fab-agon-emulator"), - }; - + None => std::path::Path::new(".").join("firmware"), + Some(prefix) => std::path::Path::new(prefix) + .join("share") + .join("fab-agon-emulator"), + }; for v in [ver, parse_args::FirmwareVer::console8] { - paths.push( - base_path.join( - format!("{}_{:?}.{}", if is_mos { "mos" } else { "vdp" }, v, if is_mos { "bin" } else { "so" } - ) - ) - ); + paths.push(base_path.join(format!( + "{}_{:?}.{}", + if is_mos { "mos" } else { "vdp" }, + v, + if is_mos { "bin" } else { "so" } + ))); } paths @@ -49,7 +52,10 @@ pub fn firmware_paths(ver: parse_args::FirmwareVer, explicit_path: Option Result<(), pico_args::Error> { let args = parse_args()?; - let vdp_interface = vdp_interface::init(firmware_paths(args.firmware, args.vdp_dll, false), args.verbose); + let vdp_interface = vdp_interface::init( + firmware_paths(args.firmware, args.vdp_dll, false), + args.verbose, + ); unsafe { (*vdp_interface.setVdpDebugLogging)(args.verbose) } diff --git a/src/vdp_interface.rs b/src/vdp_interface.rs index 351ddcb..0eb2fe9 100644 --- a/src/vdp_interface.rs +++ b/src/vdp_interface.rs @@ -54,14 +54,19 @@ pub fn init(firmware_paths: Vec, verbose: bool) -> VdpInterf } for p in &firmware_paths { - if let Ok(ref lib) = unsafe { libloading::Library::new(p) } { - unsafe { - VDP_DLL = lib; + match unsafe { libloading::Library::new(p) } { + Ok(ref lib) => { + unsafe { + VDP_DLL = lib; + } + return VdpInterface::new(unsafe { VDP_DLL.as_ref() }.unwrap()); + } + Err(e) => { + eprintln!("Error loading VDP firmware: {:?}, {:?}", p, e); } - return VdpInterface::new(unsafe { VDP_DLL.as_ref() }.unwrap()); } } - println!("Fatal error: Could not open VDP firmware. Tried {:?}", firmware_paths); + println!("Fatal error: Could not find any VDP firmware."); std::process::exit(-1); }