From 825331df39c18bdd2645bce0b636ca73a66807e0 Mon Sep 17 00:00:00 2001 From: transistor Date: Thu, 23 Dec 2021 19:32:15 -0800 Subject: [PATCH] Fixed occasional error with debug, and modified frame swapper --- src/host/gfx.rs | 6 ++++-- src/peripherals/genesis/ym7101.rs | 1 + src/system.rs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/host/gfx.rs b/src/host/gfx.rs index 2dabc80..b986063 100644 --- a/src/host/gfx.rs +++ b/src/host/gfx.rs @@ -92,6 +92,10 @@ impl FrameSwapper { pub fn to_boxed(swapper: FrameSwapper) -> Box { Box::new(swapper) } + + pub fn swap(&mut self) { + std::mem::swap(&mut self.current.lock().unwrap().bitmap, &mut self.previous.lock().unwrap().bitmap); + } } impl WindowUpdater for FrameSwapper { @@ -104,8 +108,6 @@ impl WindowUpdater for FrameSwapper { } fn update_frame(&mut self, width: u32, _height: u32, bitmap: &mut [u32]) { - std::mem::swap(&mut self.current.lock().unwrap().bitmap, &mut self.previous.lock().unwrap().bitmap); - if let Ok(frame) = self.previous.lock() { for y in 0..frame.height { for x in 0..frame.width { diff --git a/src/peripherals/genesis/ym7101.rs b/src/peripherals/genesis/ym7101.rs index ae9d1a2..54c444f 100644 --- a/src/peripherals/genesis/ym7101.rs +++ b/src/peripherals/genesis/ym7101.rs @@ -652,6 +652,7 @@ impl Steppable for Ym7101 { system.get_interrupt_controller().set(true, 6, 30)?; } + self.swapper.swap(); let mut frame = self.swapper.current.lock().unwrap(); self.state.draw_frame(&mut frame); diff --git a/src/system.rs b/src/system.rs index 034ace4..798d0a2 100644 --- a/src/system.rs +++ b/src/system.rs @@ -154,7 +154,9 @@ impl System { if self.debug_enabled.get() { let top = self.event_queue[self.event_queue.len() - 1].device.clone(); if top.borrow_mut().as_debuggable().map(|debug| debug.debugging_enabled()).unwrap_or(false) { - self.debugger.borrow_mut().run_debugger(&self, top.clone()).unwrap(); + if let Err(err) = self.debugger.borrow_mut().run_debugger(&self, top.clone()) { + println!("Error: {:?}", err); + } } } }