Skip to content

Commit

Permalink
Improved error reporting in vdp firmware loader
Browse files Browse the repository at this point in the history
  • Loading branch information
tomm committed Oct 5, 2024
1 parent a1e507f commit 3674759
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
34 changes: 20 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,42 @@ 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<std::path::PathBuf>, is_mos: bool) -> Vec<std::path::PathBuf> {
pub fn firmware_paths(
ver: parse_args::FirmwareVer,
explicit_path: Option<std::path::PathBuf>,
is_mos: bool,
) -> Vec<std::path::PathBuf> {
let mut paths: Vec<std::path::PathBuf> = vec![];

if let Some(ref p) = explicit_path {
paths.push(p.clone());
}

let base_path = match PREFIX {
None => 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
}

pub fn main() -> 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) }

Expand Down
15 changes: 10 additions & 5 deletions src/vdp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ pub fn init(firmware_paths: Vec<std::path::PathBuf>, 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);
}

Expand Down

0 comments on commit 3674759

Please sign in to comment.