diff --git a/src/main.rs b/src/main.rs index efa686b..36feec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ fn main() -> Result<()> { println!(); println!("Usage:"); #[cfg(any(feature = "native", feature = "browser"))] - println!(" uw8 run [-t/--timeout ] [--b/--browser] [-w/--watch] [-p/--pack] [-u/--uncompressed] [-l/--level] [-o/--output ] "); + println!(" uw8 run [-t/--timeout ] [--no-gpu] [--b/--browser] [-w/--watch] [-p/--pack] [-u/--uncompressed] [-l/--level] [-o/--output ] "); println!(" uw8 pack [-u/--uncompressed] [-l/--level] "); println!(" uw8 unpack "); println!(" uw8 compile [-d/--debug] "); @@ -54,6 +54,8 @@ fn run(mut args: Arguments) -> Result<()> { let watch_mode = args.contains(["-w", "--watch"]); #[allow(unused)] let timeout: Option = args.opt_value_from_str(["-t", "--timeout"])?; + #[allow(unused)] + let gpu = !args.contains("--no-gpu"); let mut config = Config::default(); if args.contains(["-p", "--pack"]) { @@ -93,7 +95,7 @@ fn run(mut args: Arguments) -> Result<()> { unimplemented!(); #[cfg(feature = "native")] { - let mut microw8 = MicroW8::new(timeout)?; + let mut microw8 = MicroW8::new(timeout, gpu)?; if disable_audio { microw8.disable_audio(); } diff --git a/src/run_native.rs b/src/run_native.rs index 7b95f8b..058c5a3 100644 --- a/src/run_native.rs +++ b/src/run_native.rs @@ -48,7 +48,7 @@ struct UW8WatchDog { } impl MicroW8 { - pub fn new(timeout: Option) -> Result { + pub fn new(timeout: Option, gpu: bool) -> Result { let mut config = wasmtime::Config::new(); config.cranelift_opt_level(wasmtime::OptLevel::Speed); if timeout.is_some() { @@ -68,7 +68,7 @@ impl MicroW8 { timeout: timeout.unwrap_or(0), }; - uw8_window::run(move |framebuffer, gamepad, reset| { + uw8_window::run(gpu, move |framebuffer, gamepad, reset| { while let Ok(instance) = to_ui_rx.try_recv() { state.instance = instance; } @@ -245,10 +245,10 @@ impl State { let mut sound_regs = [0u8; 32]; sound_regs.copy_from_slice(&memory[80..112]); if let Some(ref sound_tx) = instance.sound_tx { - sound_tx.send(RegisterUpdate { + let _ = sound_tx.send(RegisterUpdate { time, data: sound_regs, - })?; + }); } let framebuffer_mem = &memory[120..(120 + 320 * 240)]; diff --git a/uw8-window/src/cpu.rs b/uw8-window/src/cpu.rs index 6c997b0..044a91f 100644 --- a/uw8-window/src/cpu.rs +++ b/uw8-window/src/cpu.rs @@ -35,12 +35,25 @@ pub fn run(mut update: Box Instant if let Some(sleep) = next_frame.checked_duration_since(Instant::now()) { std::thread::sleep(sleep); } + + let mut gamepad = 0; + for key in window.get_keys() { + if let Some(index) = GAMEPAD_KEYS + .iter() + .enumerate() + .find(|(_, &k)| k == key) + .map(|(i, _)| i) + { + gamepad |= 1 << index; + } + } + next_frame = update( &mut CpuFramebuffer { buffer: &mut buffer, }, - 0, - false, + gamepad, + window.is_key_pressed(Key::R, minifb::KeyRepeat::No), ); window.update_with_buffer(&buffer, 320, 240).unwrap(); } diff --git a/uw8-window/src/lib.rs b/uw8-window/src/lib.rs index befc8d8..cc113a5 100644 --- a/uw8-window/src/lib.rs +++ b/uw8-window/src/lib.rs @@ -3,13 +3,18 @@ use std::time::Instant; mod cpu; mod gpu; -pub fn run Instant>(update: F) -> ! { - match gpu::Window::new() { - Ok(window) => window.run(Box::new(update)), - Err(err) => eprintln!( - "Failed to create gpu window: {}\nFalling back to cpu window", - err - ), +pub fn run Instant>( + gpu: bool, + update: F, +) -> ! { + if gpu { + match gpu::Window::new() { + Ok(window) => window.run(Box::new(update)), + Err(err) => eprintln!( + "Failed to create gpu window: {}\nFalling back to cpu window", + err + ), + } } cpu::run(Box::new(update)); }