Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tomm/fab-agon-emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
tomm committed Oct 16, 2023
2 parents 425aa94 + afd7428 commit 39dacf9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ Read about other command-line options with:

Read [make_win64_dist.sh](./make_win64_dist.sh).

### To build on Windows

TODO
### To build on Windows (mingw)

* Install rustup from https://rustup.rs/
* rustup toolchain install stable-x86_64-pc-windows-gnu
* rustup default stable-x86_64-pc-windows-gnu
* Install make winget install GnuWin32.Make
* add C:\Program Files (x86)\GnuWin32\bin to path
* Install mingw64 from https://github.com/brechtsanders/winlibs_mingw/releases/download/13.2.0mcf-16.0.6-11.0.1-ucrt-r2/winlibs-x86_64-mcf-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.1-r2.zip
* extract to C:\mingw64 and add C:\mingw64\bin to path
* get SDL2 from https://github.com/libsdl-org/SDL/releases/download/release-2.28.3/SDL2-devel-2.28.3-mingw.zip
* extract to C:\Users\<user>\.rustup\toolchains\stable-x86_64-pc-windows-gnu
* copy SDL2.dll to the root of the project
* run `cargo build --release` in the root of the project
* manually copy built vdp*.so files from userspace-vdp to the root of the project
* run `cargo run --release` in the root of the project
23 changes: 19 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use agon_cpu_emulator::{ AgonMachine, AgonMachineConfig, RamInit };
use agon_cpu_emulator::debugger::{ DebugCmd, DebugResp, DebuggerConnection };
use agon_cpu_emulator::debugger::{ DebugCmd, DebugResp, DebuggerConnection, Trigger };
use sdl2::event::Event;
use std::sync::mpsc;
use std::sync::mpsc::{Sender, Receiver};
Expand All @@ -23,22 +23,37 @@ pub fn main() -> Result<(), pico_args::Error> {
let (tx_cmd_debugger, rx_cmd_debugger): (Sender<DebugCmd>, Receiver<DebugCmd>) = mpsc::channel();
let (tx_resp_debugger, rx_resp_debugger): (Sender<DebugResp>, Receiver<DebugResp>) = mpsc::channel();

if let Some(breakpoint) = args.breakpoint {
if let Ok(breakpoint) = u32::from_str_radix(&breakpoint, 16) {
let trigger = Trigger{
address: breakpoint,
once: false,
actions: vec![DebugCmd::Pause, DebugCmd::Message("CPU paused at initial breakpoint".to_owned()), DebugCmd::GetState],
};
let debug_cmd = DebugCmd::AddTrigger(trigger);
_ = tx_cmd_debugger.send(debug_cmd);
_ = tx_cmd_debugger.send(DebugCmd::Continue);
} else {
println!("Cannot parse breakpoint as hexadecimal. Ignoring.")
}
}

let vsync_counter_vdp = std::sync::Arc::new(std::sync::atomic::AtomicU32::new(0));
let vsync_counter_ez80 = vsync_counter_vdp.clone();

let debugger_con = if args.debugger {
let _debugger_thread = thread::spawn(move || {
agon_light_emulator_debugger::start(tx_cmd_debugger, rx_resp_debugger);
});
Some(DebuggerConnection { tx: tx_resp_debugger, rx: rx_cmd_debugger })
Some(DebuggerConnection { tx: tx_resp_debugger, rx: rx_cmd_debugger})
} else {
None
};

let _cpu_thread = thread::spawn(move || {
// Prepare the device
let mut machine = AgonMachine::new(AgonMachineConfig {
ram_init: RamInit::Random,
ram_init: if args.zero { RamInit::Zero} else {RamInit::Random},
to_vdp: tx_ez80_to_vdp,
from_vdp: rx_vdp_to_ez80,
vsync_counter: vsync_counter_ez80,
Expand Down Expand Up @@ -130,7 +145,7 @@ pub fn main() -> Result<(), pico_args::Error> {
// deal with weird aspect ratios
match 10*mode_w / mode_h {
// 2.66 (640x240)
26 =>
26 =>
// scale & !1 keeps the scale divisible by 2, needed for the width scaling
((mode_w * (scale & !1)) >> 1, mode_h * (scale & !1)),
// 1.6 (320x200)
Expand Down
6 changes: 6 additions & 0 deletions src/parse_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ USAGE:
OPTIONS:
-d, --debugger Enable the eZ80 debugger
-b, --breakpoint Set a breakpoint before starting
-z, --zero Initialize ram with zeroes instead of random values
-f, --fullscreen Start in fullscreen mode
-h, --help Prints help information
-u, --unlimited-cpu Don't limit eZ80 CPU frequency
Expand All @@ -31,8 +33,10 @@ pub enum FirmwareVer {
pub struct AppArgs {
pub sdcard: Option<String>,
pub debugger: bool,
pub breakpoint: Option<String>,
pub unlimited_cpu: bool,
pub fullscreen: bool,
pub zero: bool,
pub mos_bin: Option<std::path::PathBuf>,
pub vdp_dll: Option<std::path::PathBuf>,
pub firmware: FirmwareVer,
Expand All @@ -52,8 +56,10 @@ pub fn parse_args() -> Result<AppArgs, pico_args::Error> {
let args = AppArgs {
sdcard: pargs.opt_value_from_str("--sdcard")?,
debugger: pargs.contains(["-d", "--debugger"]),
breakpoint: pargs.opt_value_from_str(["-b", "--breakpoint"])?,
unlimited_cpu: pargs.contains(["-u", "--unlimited_cpu"]),
fullscreen: pargs.contains(["-f", "--fullscreen"]),
zero: pargs.contains(["-z", "--zero"]),
perfect_scale: pargs.opt_value_from_str("--scale")?,
mos_bin: pargs.opt_value_from_str("--mos")?,
vdp_dll: pargs.opt_value_from_str("--vdp")?,
Expand Down

0 comments on commit 39dacf9

Please sign in to comment.