From cdb0f1d8d774417233811c77914e9e2efac0b9d3 Mon Sep 17 00:00:00 2001 From: pjht Date: Thu, 23 Mar 2023 10:34:01 -0500 Subject: [PATCH] Change run to not disassemble instruction when cpu is stopped and show stopped status --- src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 813d02c..3e67949 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,6 @@ fn main() -> Result<(), anyhow::Error> { last_peek_format: (peek::Format::Hex, peek::Size::Byte), }; if args.run { - let mut out = String::new(); while !state.cpu.stopped { match state.cpu.step() { Ok(()) => (), @@ -98,11 +97,7 @@ fn main() -> Result<(), anyhow::Error> { } } } - out += &format!("{}\n", state.cpu); - let pc = state.cpu.pc(); - out += &disas_fmt(&mut state.cpu, pc, &state.symbol_tables).0; - out.pop(); // Remove trailing newline - println!("{out}"); + println!("CPU stopped at PC {:#x}\n{}", state.cpu.pc(), state.cpu); return Ok(()); } Repl::<_, anyhow::Error>::new(state) @@ -239,9 +234,14 @@ fn main() -> Result<(), anyhow::Error> { } } } + if state.cpu.stopped { + out += &format!("CPU stopped at PC {:#x}\n", state.cpu.pc()); + } out += &format!("{}\n", state.cpu); - let pc = state.cpu.pc(); - out += &disas_fmt(&mut state.cpu, pc, &state.symbol_tables).0; + if !state.cpu.stopped { + let pc = state.cpu.pc(); + out += &disas_fmt(&mut state.cpu, pc, &state.symbol_tables).0; + } out.pop(); // Remove trailing newline Ok(Some(out)) },