process messages outside of step loop

This commit is contained in:
Alex Janka 2023-03-03 11:20:47 +11:00
parent bb6ab69d66
commit cbc5a634e2

View file

@ -101,6 +101,7 @@ pub fn init(
verbose_println!("\n\n Begin execution...\n"); verbose_println!("\n\n Begin execution...\n");
match options.step_by { match options.step_by {
Some(step_size) => loop { Some(step_size) => loop {
process_messages(&receiver, &mut cpu);
for _ in 0..step_size { for _ in 0..step_size {
cycle_num += 1; cycle_num += 1;
if options.cycle_count { if options.cycle_count {
@ -113,14 +114,7 @@ pub fn init(
pause(); pause();
}, },
None => loop { None => loop {
while let Ok(msg) = receiver.try_recv() { process_messages(&receiver, &mut cpu);
match msg {
EmulatorMessage::Stop => {
cpu.memory.flush_rom();
exit(0);
}
}
}
cycle_num += 1; cycle_num += 1;
if options.cycle_count { if options.cycle_count {
print_cycles(&cycle_num); print_cycles(&cycle_num);
@ -130,6 +124,17 @@ pub fn init(
} }
} }
fn process_messages(receiver: &Receiver<EmulatorMessage>, cpu: &mut Cpu) {
while let Ok(msg) = receiver.try_recv() {
match msg {
EmulatorMessage::Stop => {
cpu.memory.flush_rom();
exit(0);
}
}
}
}
fn run_cycle(cpu: &mut Cpu) { fn run_cycle(cpu: &mut Cpu) {
let will_pause = unsafe { PAUSE_QUEUED }; let will_pause = unsafe { PAUSE_QUEUED };
let pause_enabled = unsafe { PAUSE_ENABLED }; let pause_enabled = unsafe { PAUSE_ENABLED };