Skip to content

Commit

Permalink
Rainbow MOS firmware. --firmware rainbow option
Browse files Browse the repository at this point in the history
  • Loading branch information
tomm committed Oct 5, 2024
1 parent a044bee commit a1e507f
Show file tree
Hide file tree
Showing 7 changed files with 2,341 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["agon-light-emulator-debugger"]

[workspace.package]
version = "0.9.63"
version = "0.9.64"
edition = "2021"
authors = ["Tom Morton <[email protected]>"]
license = "GPL-3.0"
Expand Down
Binary file added firmware/mos_rainbow.bin
Binary file not shown.
2,291 changes: 2,291 additions & 0 deletions firmware/mos_rainbow.map

Large diffs are not rendered by default.

47 changes: 29 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,39 @@ mod vdp_interface;
const AUDIO_BUFLEN: u16 = 256;
const PREFIX: Option<&'static str> = option_env!("PREFIX");

pub fn firmware_path(ver: parse_args::FirmwareVer, is_mos: bool) -> std::path::PathBuf {
match PREFIX {
None => std::path::Path::new(".").join("firmware"),
Some(prefix) => std::path::Path::new(prefix)
.join("share")
.join("fab-agon-emulator"),
/**
* 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> {
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"),
};


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" }
)
)
);
}
.join(format!(
"{}_{:?}.{}",
if is_mos { "mos" } else { "vdp" },
ver,
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_path(args.firmware, false), &args);
let vdp_interface = vdp_interface::init(firmware_paths(args.firmware, args.vdp_dll, false), args.verbose);

unsafe { (*vdp_interface.setVdpDebugLogging)(args.verbose) }

Expand Down Expand Up @@ -111,11 +126,7 @@ pub fn main() -> Result<(), pico_args::Error> {
thread::Builder::new()
.name("ez80".to_string())
.spawn(move || {
let ez80_firmware = if let Some(mos_bin) = args.mos_bin {
mos_bin
} else {
firmware_path(args.firmware, true)
};
let ez80_firmware = firmware_paths(args.firmware, args.mos_bin, true).remove(0);

let sdcard_dir = if let Some(p) = args.sdcard {
std::path::PathBuf::from(p)
Expand Down
6 changes: 5 additions & 1 deletion src/parse_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OPTIONS:
--firmware 1.03 Use quark 1.03 firmware (default is console8)
--firmware quark Use quark 1.04 firmware (default is console8)
--firmware electron Use ElectronOS firmware (default is console8)
--firmware rainbow Use Rainbow firmware (default is console8)
--mode <n> Start in a specific screen mode
--osk Enable on-screen-keyboard input (requires OS osk)
--sdcard <path> Sets the path of the emulated SDCard
Expand Down Expand Up @@ -40,6 +41,7 @@ pub enum FirmwareVer {
quark103,
quark,
console8,
rainbow,
electron,
}

Expand Down Expand Up @@ -154,10 +156,12 @@ pub fn parse_args() -> Result<AppArgs, pico_args::Error> {
FirmwareVer::quark
} else if ver == "console8" {
FirmwareVer::console8
} else if ver == "rainbow" {
FirmwareVer::rainbow
} else if ver == "electron" {
FirmwareVer::electron
} else {
println!("Unknown --firmware value: {}. Valid values are: 1.03, quark, console8, electron", ver);
println!("Unknown --firmware value: {}. Valid values are: 1.03, quark, console8, rainbow, electron", ver);
std::process::exit(0);
}
} else {
Expand Down
26 changes: 13 additions & 13 deletions src/vdp_interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::Path;

#[allow(non_snake_case)]
pub struct VdpInterface {
pub vdp_setup: libloading::Symbol<'static, unsafe extern "C" fn() -> ()>,
Expand Down Expand Up @@ -48,21 +46,23 @@ impl VdpInterface {
}
}

pub fn init(default_vdp: std::path::PathBuf, args: &crate::parse_args::AppArgs) -> VdpInterface {
pub fn init(firmware_paths: Vec<std::path::PathBuf>, verbose: bool) -> VdpInterface {
assert!(unsafe { VDP_DLL == std::ptr::null() });

let vdp_dll_path = match args.vdp_dll {
Some(ref p) => Path::new(".").join(p),
None => default_vdp,
};

if args.verbose {
eprintln!("VDP firmware: {:?}", vdp_dll_path);
if verbose {
eprintln!("VDP firmware: {:?}", firmware_paths);
}

unsafe {
VDP_DLL = Box::leak(Box::new(libloading::Library::new(vdp_dll_path).unwrap()));
for p in &firmware_paths {
if let Ok(ref lib) = unsafe { libloading::Library::new(p) } {
unsafe {
VDP_DLL = lib;
}
return VdpInterface::new(unsafe { VDP_DLL.as_ref() }.unwrap());
}
}
VdpInterface::new(unsafe { VDP_DLL.as_ref() }.unwrap())
println!("Fatal error: Could not open VDP firmware. Tried {:?}", firmware_paths);
std::process::exit(-1);
}

static mut VDP_DLL: *const libloading::Library = std::ptr::null();

0 comments on commit a1e507f

Please sign in to comment.