From 07fb107e2d0527545bcdbb47ace80551702a71b1 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 16 Dec 2024 13:42:21 +1300 Subject: Fix reported address of debug instruction in debug output Because the program counter is incremented immediately after an instruction byte is loaded, the value of the program counter reported by a debug instruction was actually the address of the following byte. This made the SYM symbol name line in the debug output report the wrong symbol name in some situations. This was fixed by decrementing the value used. --- src/debug.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/debug.rs') diff --git a/src/debug.rs b/src/debug.rs index 17ed604..c01ee15 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -36,8 +36,9 @@ impl DebugState { pub fn debug_summary(&mut self, core: &BedrockCore) { if self.enabled { + let prev_pc = core.mem.pc.wrapping_sub(1); eprintln!("\n PC: 0x{:04x} Cycles: {} (+{} in {:.2?})", - core.mem.pc, core.cycle, + prev_pc, core.cycle, core.cycle.saturating_sub(self.last_cycle), self.last_mark.elapsed(), ); @@ -46,7 +47,7 @@ impl DebugState { eprint!("RST: "); debug_stack(&core.rst, 0x10); // Print information about the closest symbol. - if let Some(symbol) = self.symbols.for_address(core.mem.pc) { + if let Some(symbol) = self.symbols.for_address(prev_pc) { let name = &symbol.name; let address = &symbol.address; eprint!("SYM: {BLUE}@{name}{NORMAL} 0x{address:04x}"); -- cgit v1.2.3-70-g09d2