From cbc5a634e25c84add5874829a37016b5b3de7d62 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Fri, 3 Mar 2023 11:20:47 +1100 Subject: [PATCH] process messages outside of step loop --- src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bdbce77..fb83bcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ pub fn init( verbose_println!("\n\n Begin execution...\n"); match options.step_by { Some(step_size) => loop { + process_messages(&receiver, &mut cpu); for _ in 0..step_size { cycle_num += 1; if options.cycle_count { @@ -113,14 +114,7 @@ pub fn init( pause(); }, None => loop { - while let Ok(msg) = receiver.try_recv() { - match msg { - EmulatorMessage::Stop => { - cpu.memory.flush_rom(); - exit(0); - } - } - } + process_messages(&receiver, &mut cpu); cycle_num += 1; if options.cycle_count { print_cycles(&cycle_num); @@ -130,6 +124,17 @@ pub fn init( } } +fn process_messages(receiver: &Receiver, 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) { let will_pause = unsafe { PAUSE_QUEUED }; let pause_enabled = unsafe { PAUSE_ENABLED };