SingleStepTests / ProcessorTests

A language-agnostic JSON-encoded instruction-by-instruction test suite for the 8088, 68000, 65816, 65[c]02 and SPC700 that includes bus activity.
188 stars 13 forks source link

6502 - Bad final PC value for test `20 55 13` #49

Closed macmade closed 1 year ago

macmade commented 1 year ago

First of all, thank you so much for providing these tests.
I'm currently using them to unit-test my 6502 emulator.

While running your tests, I encountered a failed test in 20.json, for the 20 55 13 test.

Instruction translates to: JSR $#0x1355

JSR is unconditional, so the expected value for PC after the instruction is 0x1355 or 4949.
The test case has a final PC value of 0x155 or 341.

Or am I missing something?

TomHarte commented 1 year ago

No, I think this is correct; cf. #36. When performing a JSR the 6502 performs the following process:

1    PC     R  fetch opcode, increment PC
2    PC     R  fetch low address byte, increment PC
3  $0100,S  R  internal operation (predecrement S?)
4  $0100,S  W  push PCH on stack, decrement S
5  $0100,S  W  push PCL on stack, decrement S
6    PC     R  copy low address byte to PCL, fetch high address
               byte to PCH

And in that particular test case step 4 has overwritten part of the opcode such that when PCH is fetched in step 6 it's the same PCH that was just pushed.

macmade commented 1 year ago

Wow...
I haven't even tought about searching a similar issue for what I thought was a no-brainer...

Thank you so much for the fast reply.
And thank you for the absolute mind-blow!