summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-12-16 13:42:21 +1300
committerBen Bridle <ben@derelict.engineering>2024-12-16 13:43:13 +1300
commit07fb107e2d0527545bcdbb47ace80551702a71b1 (patch)
tree2ec8c12928e317a8946f6270a4e8659271056b4d /src
parent583c961c0158fd44817695225e06d07caa18657e (diff)
downloadbedrock-pc-07fb107e2d0527545bcdbb47ace80551702a71b1.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/debug.rs5
1 files changed, 3 insertions, 2 deletions
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}");