Skip to content

Commit

Permalink
Fix frame sync with debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte committed Dec 24, 2024
1 parent b5d890a commit ae0d26c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ pub struct Emulator {
rom: RomFile,

debug: bool,
debug_halt: bool,
state: EmulatorState,
// When true, the program will sync the time that passed, and the time that is emulated.
frame_limit: bool,
Expand Down Expand Up @@ -475,6 +476,7 @@ impl Emulator {
joypad,
rom,
debug: false,
debug_halt: false,
state: EmulatorState::Idle,
frame_limit: !config.frame_skip,
rewind: false,
Expand Down Expand Up @@ -590,6 +592,8 @@ impl Emulator {
RunFrame => {
if !self.debug {
self.set_state(EmulatorState::RunNoBreak);
} else if !self.debug_halt {
self.set_state(EmulatorState::Run);
}
}
FrameLimit(value) => {
Expand Down Expand Up @@ -628,6 +632,7 @@ impl Emulator {
return false;
}
self.debug = value;
self.debug_halt = value;
if self.debug {
self.debugger.lock().last_op_clock = None;
self.set_state(EmulatorState::Idle);
Expand All @@ -644,6 +649,7 @@ impl Emulator {
self.debugger.lock().step(gb);
}
self.set_state(EmulatorState::Idle);
self.debug_halt = true;
}
}
StepBack => {
Expand Down Expand Up @@ -684,6 +690,7 @@ impl Emulator {
Run => {
if self.debug {
self.set_state(EmulatorState::Run);
self.debug_halt = false;
// Run a single step, to ignore the current breakpoint
let gb = &mut *self.gb.lock();
self.debugger.lock().step(gb);
Expand Down Expand Up @@ -713,16 +720,18 @@ impl Emulator {
let mut gb = self.gb.lock();
let mut debugger = self.debugger.lock();
use RunResult::*;
match debugger.run_for(&mut gb, CLOCK_SPEED / 600) {
match debugger.run_for(&mut gb, CLOCK_SPEED / 180) {
ReachBreakpoint | ReachTargetAddress | ReachTargetClock => {
drop(gb);
drop(debugger);
self.set_state(EmulatorState::Idle);
self.debug_halt = true;
return Control::Wait;
}
TimeOut => {}
}
}
self.set_state(EmulatorState::WaitNextFrame);
return Control::Poll;
}
EmulatorState::RunNoBreak => {
Expand Down

0 comments on commit ae0d26c

Please sign in to comment.