diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-25 17:48:54 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-25 17:48:54 +0200 |
| commit | bf2b0122f20bb6ddc628b2b8f45de7e1943d139e (patch) | |
| tree | 4d01a98e8b21a0c9e76e8925621520bed38df959 /lib | |
| parent | 792c2a9fb532afa39de65261ec226fd4cebd7137 (diff) | |
| download | tools.nes-bf2b0122f20bb6ddc628b2b8f45de7e1943d139e.tar.gz tools.nes-bf2b0122f20bb6ddc628b2b8f45de7e1943d139e.zip | |
vnf: fix the accounting of cycles on branches
This was broken since the very beginning.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/vnf/src/lib.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 002c4da..4ba04c1 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -1012,11 +1012,19 @@ impl Machine { self.pc - val.wrapping_neg() as usize }; + // If the next PC results in crossing the page boundary compared to the + // old PC, then there is a page penalty to be accounted. That is, + // branch instructions are defined with a base 'cycles' count, and then + // needs to be increased either by 1 or 2 depending on whether there was + // a page penalty or not. We could have easily defined the base 'cycles' + // with an increased value of 1 and then only increase by one on page + // penalty, but the definition tries to be close to the 6502 + // specification, which is defined like so. Hence, we keep this quirk. if (next & 0xFF00) == (self.pc & 0xFF00) { + self.extra_cycles += 1; + } else { self.extra_cycles += 2; self.page_penalty += 1; - } else { - self.extra_cycles += 1; } self.pc = next; // TODO |
