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)) },