diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-26 08:26:01 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-27 07:09:03 +0200 |
| commit | 1c4e8eff6849ce35c31f189f9a07519a89c48ef4 (patch) | |
| tree | 0bd0244e69da8a72b8f75e2179c5fd57f9b19c8d | |
| parent | 2df68007e5e3640c02ada107851c7b5bb96072da (diff) | |
| download | tools.nes-1c4e8eff6849ce35c31f189f9a07519a89c48ef4.tar.gz tools.nes-1c4e8eff6849ce35c31f189f9a07519a89c48ef4.zip | |
vnf: don't report stack push/pop twice in verbose
On situations like jsr or rts, we perform two pushes/pops, but this is
not to be reported in verbose mode as it's not that clear. Instead,
let's report the full address in a single stack line.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | lib/vnf/src/lib.rs | 22 | ||||
| -rw-r--r-- | tests/expected/runrom/misc-all.txt | 6 |
2 files changed, 14 insertions, 14 deletions
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 4ba04c1..f2524cd 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -613,8 +613,9 @@ impl Machine { println!(); } - // Push the given 'value' to the stack. - fn push_stack(&mut self, value: u8) -> Result<(), String> { + // Push the given 'value' to the stack. Set 'report' to true if you want the + // output from verbose mode. + fn push_stack(&mut self, value: u8, report: bool) -> Result<(), String> { // Write the given value onto the stack. let address = 0x200 + self.s as u16; self.write_memory(address, value)?; @@ -625,22 +626,23 @@ impl Machine { return Err("stack underflow!".to_string()); } - if self.verbose { + if self.verbose && report { self.put_stack(); } Ok(()) } - // Pop the stack once and return the value that was found. - fn pop_stack(&mut self, account_read: bool) -> Result<u8, String> { + // Pop the stack once and return the value that was found. Set 'report' to + // true if you want the output from verbose mode. + fn pop_stack(&mut self, account_read: bool, report: bool) -> Result<u8, String> { if self.s == self.initial_stack_value { return Err("stack overflow!".to_string()); } self.s += 1; - if self.verbose { + if self.verbose && report { self.put_stack(); } @@ -908,8 +910,8 @@ impl Machine { let low = (next_address as u16 & 0x00FF) as u8; let high = ((next_address as u16 & 0xFF00) >> 8) as u8; - self.push_stack(high)?; - self.push_stack(low)?; + self.push_stack(high, false)?; + self.push_stack(low, true)?; self.pc = address; self.skip_pc = true; @@ -969,8 +971,8 @@ impl Machine { // stack was the next instruction before the call, but the size // of the 'rts/rti' should also be accounted. Hence the + 1 to // the resulting PC. - let low = self.pop_stack(false)? as u16; - let high = (self.pop_stack(false)? as u16) << 8; + let low = self.pop_stack(false, false)? as u16; + let high = (self.pop_stack(false, true)? as u16) << 8; self.pc = (high + low) as usize + 1; self.skip_pc = true; } diff --git a/tests/expected/runrom/misc-all.txt b/tests/expected/runrom/misc-all.txt index f96325d..a0290f5 100644 --- a/tests/expected/runrom/misc-all.txt +++ b/tests/expected/runrom/misc-all.txt @@ -1,5 +1,4 @@ <start> PC: $8000, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- - [STACK]: 80 00 00 [STACK]: 02 80 00 00 jsr $8004 PC: $8004, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I-- ldx #$00 PC: $8006, cycles: 15, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- @@ -515,7 +514,6 @@ inx PC: $8007, cycles: 1287, registers: [a: $00, x: $FF, y: $00, sp: $FB], stat bne $FD PC: $8006, cycles: 1290, registers: [a: $00, x: $FF, y: $00, sp: $FB], status: N---I-- inx PC: $8007, cycles: 1292, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- bne $FD PC: $8009, cycles: 1294, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- - [STACK]: 80 00 00 [STACK]: 00 00 rts PC: $8003, cycles: 1300, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- rts PC: $8004, cycles: 1306, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- @@ -523,5 +521,5 @@ rts PC: $8004, cycles: 1306, registers: [a: $00, x: $00, y: $00, sp: $FD], stat == Memory dump == -[$2FC] = $02 [reads=0, writes=1] -[$2FD] = $80 [reads=0, writes=1] +[$2FC] = $02 [reads=1, writes=1] +[$2FD] = $80 [reads=1, writes=1] |
