From 3687161b98c129394ef4dee214130f1cb55d79a7 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sun, 29 Dec 2019 23:37:23 +0200 Subject: [PATCH] Make the debugger into an optional build option. This module is written purely and always breaks when changes are being made into the 'core' module, so as long as I don't use it, I don't feel like maintaining it. Former-commit-id: f5b18ba54a27d22e8a195dd0912ec9c8f29fa830 --- src/core/mod.rs | 3 + src/lib.rs | 5 +- src/plat/sdl2/main.rs | 125 ++++++++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 53 deletions(-) diff --git a/src/core/mod.rs b/src/core/mod.rs index 4c10b16..ca351b5 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -18,6 +18,7 @@ pub use bus::*; pub use super::{AudioInterface, InputInterface, VideoInterface}; +#[cfg(rba_with_debugger)] use crate::debugger; use zip; @@ -26,6 +27,7 @@ use zip; pub enum GBAError { IO(::std::io::Error), CpuError(arm7tdmi::CpuError), + #[cfg(rba_with_debugger)] DebuggerError(debugger::DebuggerError), } @@ -43,6 +45,7 @@ impl From for GBAError { } } +#[cfg(rba_with_debugger)] impl From for GBAError { fn from(err: debugger::DebuggerError) -> GBAError { GBAError::DebuggerError(err) diff --git a/src/lib.rs b/src/lib.rs index 850cebe..33e4fed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,9 +30,11 @@ extern crate zip; #[macro_use] pub mod util; pub mod core; -pub mod debugger; pub mod disass; +#[cfg(rba_with_debugger)] +pub mod debugger; + pub trait VideoInterface { fn render(&mut self, buffer: &[u32]); } @@ -54,6 +56,7 @@ pub mod prelude { pub use super::core::arm7tdmi; pub use super::core::cartridge::Cartridge; pub use super::core::{GBAError, GBAResult, GameBoyAdvance}; + #[cfg(rba_with_debugger)] pub use super::debugger::Debugger; pub use super::util::read_bin_file; pub use super::{AudioInterface, InputInterface, VideoInterface}; diff --git a/src/plat/sdl2/main.rs b/src/plat/sdl2/main.rs index e967651..f829e76 100644 --- a/src/plat/sdl2/main.rs +++ b/src/plat/sdl2/main.rs @@ -31,6 +31,7 @@ fn main() { let matches = clap::App::from_yaml(yaml).get_matches(); let skip_bios = matches.occurrences_of("skip_bios") != 0; + let debug = matches.occurrences_of("debug") != 0; let bios_path = Path::new(matches.value_of("bios").unwrap_or_default()); @@ -63,64 +64,84 @@ fn main() { let mut event_pump = sdl_context.event_pump().unwrap(); if debug { - gba.cpu.set_verbose(true); - let mut debugger = Debugger::new(gba); - println!("starting debugger..."); - debugger.repl(matches.value_of("script_file")).unwrap(); - println!("ending debugger..."); - } else { - let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60); - loop { - let start_time = time::Instant::now(); + #[cfg(rba_with_debugger)] + { + gba.cpu.set_verbose(true); + let mut debugger = Debugger::new(gba); + println!("starting debugger..."); + debugger.repl(matches.value_of("script_file")).unwrap(); + println!("ending debugger..."); + return; + } + #[cfg(not(rba_with_debugger))] + { + panic!("Please compile me with cfg(rba_with_debugger)"); + } + } - for event in event_pump.poll_iter() { - match event { - Event::KeyDown { - keycode: Some(Keycode::Space), - .. - } => { - frame_limiter = false; - } - Event::KeyUp { - keycode: Some(Keycode::Space), - .. - } => { - frame_limiter = true; - } - Event::KeyDown { - keycode: Some(keycode), - .. - } => { - input.borrow_mut().on_keyboard_key_down(keycode); - } - Event::KeyUp { - keycode: Some(keycode), - .. - } => { - input.borrow_mut().on_keyboard_key_up(keycode); - } - Event::Quit { .. } => panic!("quit!"), - _ => {} + let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60); + loop { + let start_time = time::Instant::now(); + + for event in event_pump.poll_iter() { + match event { + Event::KeyDown { + keycode: Some(Keycode::Space), + .. + } => { + frame_limiter = false; } + Event::KeyUp { + keycode: Some(Keycode::Space), + .. + } => { + frame_limiter = true; + } + #[cfg(rba_with_debugger)] + Event::KeyUp { + keycode: Some(Keycode::F1), + .. + } => { + let mut debugger = Debugger::new(gba); + println!("starting debugger..."); + debugger.repl(matches.value_of("script_file")).unwrap(); + gba = debugger.gba; + println!("ending debugger..."); + break; + } + Event::KeyDown { + keycode: Some(keycode), + .. + } => { + input.borrow_mut().on_keyboard_key_down(keycode); + } + Event::KeyUp { + keycode: Some(keycode), + .. + } => { + input.borrow_mut().on_keyboard_key_up(keycode); + } + Event::Quit { .. } => panic!("quit!"), + _ => {} } + } - gba.frame(); + gba.frame(); - if let Some(fps) = fps_counter.tick() { - let title = format!("{} ({} fps)", rom_name, fps); - video.borrow_mut().set_window_title(&title); - } + if let Some(fps) = fps_counter.tick() { + let title = format!("{} ({} fps)", rom_name, fps); + video.borrow_mut().set_window_title(&title); + } - if frame_limiter { - let time_passed = start_time.elapsed(); - let delay = frame_time.checked_sub(time_passed); - match delay { - None => {} - Some(delay) => { - spin_sleep::sleep(delay); - } - }; - } + if frame_limiter { + let time_passed = start_time.elapsed(); + let delay = frame_time.checked_sub(time_passed); + match delay { + None => {} + Some(delay) => { + spin_sleep::sleep(delay); + } + }; } } }