I've written an emulator in Go. Yes, I'll release it as open source.
However, I'm now running Klaus Dormann's test file and I've already fixed a number of issues. Now I've run into one I can't wrap my head around. Maybe someone can help me figure this out.
I've used the files available from github, the corresponding listing to the binary I used can be found here:
https://github.com/Klaus2m5/6502_65C02_ ... .lst#L3932The issue seems that a CMP does not give the right result, but I don't know why.
The following is the debugging output starting a `0x0EDC`, which according to the listing tests "LDY / STY - zp,x / abs,x". It seems to run through this part a first time okay, but then does it a second time and fails.
Can someone point me into the right direction to finding the issue at hand? Thanks so much!
The `~~~` lines are instructions read in the format: `~~~ PC: OPCODE - OPCODE OPERAND [ADDRESS MODE] {CYCLES}`
Code:
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x11 0x00 0xFF 0xFF 0x0EDC 01111101
~~~ 0x0EDC: 0xA2 - LDX 0x03 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x11 0x03 0xFF 0xFF 0x0EDE 01111101
~~~ 0x0EDE: 0xA9 - LDA 0x00 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0xFF 0xFF 0x0EE0 01111111
~~~ 0x0EE0: 0x48 - PHA [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0xFF 0xFE 0x0EE1 01111111
~~~ 0x0EE1: 0x28 - PLP [implied] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0xFF 0xFF 0x0EE2 00100000
~~~ 0x0EE2: 0xB4 - LDY 0x13 [zeropageY] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFF 0x0EE4 00100010
~~~ 0x0EE4: 0x08 - PHP [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFE 0x0EE5 00100010
~~~ 0x0EE5: 0x98 - TYA [implied] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFE 0x0EE6 00100010
~~~ 0x0EE6: 0x49 - EOR 0xC3 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x03 0x00 0xFE 0x0EE8 10100000
~~~ 0x0EE8: 0x28 - PLP [implied] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x03 0x00 0xFF 0x0EE9 00110010
~~~ 0x0EE9: 0x9D - STA 0x0203 [absoluteX] {5}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x03 0x00 0xFF 0x0EEC 00110010
~~~ 0x0EEC: 0x08 - PHP [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x03 0x00 0xFE 0x0EED 00110010
~~~ 0x0EED: 0x49 - EOR 0xC3 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFE 0x0EEF 00110010
~~~ 0x0EEF: 0xDD - CMP 0x0208 [absoluteX] {4}
CMP A: 0x00 V: 0x00
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFE 0x0EF2 00110011
~~~ 0x0EF2: 0xD0 - BNE 0xFE [relative] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x03 0x00 0xFE 0x0EF4 00110011
~~~ 0x0EF4: 0x68 - PLA [implied] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x32 0x03 0x00 0xFF 0x0EF5 00110001
~~~ 0x0EF5: 0x49 - EOR 0x30 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x02 0x03 0x00 0xFF 0x0EF7 00110001
~~~ 0x0EF7: 0xDD - CMP 0x020D [absoluteX] {4}
CMP A: 0x02 V: 0x02
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x02 0x03 0x00 0xFF 0x0EFA 00110011
~~~ 0x0EFA: 0xD0 - BNE 0xFE [relative] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x02 0x03 0x00 0xFF 0x0EFC 00110011
~~~ 0x0EFC: 0xCA - DEX [implied] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x02 0x02 0x00 0xFF 0x0EFD 00110001
~~~ 0x0EFD: 0x10 - BPL 0xDF [relative] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x02 0x02 0x00 0xFF 0x0EDE 00110001
~~~ 0x0EDE: 0xA9 - LDA 0x00 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0x00 0xFF 0x0EE0 00110011
~~~ 0x0EE0: 0x48 - PHA [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0x00 0xFE 0x0EE1 00110011
~~~ 0x0EE1: 0x28 - PLP [implied] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0x00 0xFF 0x0EE2 00100000
~~~ 0x0EE2: 0xB4 - LDY 0x13 [zeropageY] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFF 0x0EE4 10100000
~~~ 0x0EE4: 0x08 - PHP [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFE 0x0EE5 10100000
~~~ 0x0EE5: 0x98 - TYA [implied] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x02 0xC3 0xFE 0x0EE6 10100000
~~~ 0x0EE6: 0x49 - EOR 0xC3 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFE 0x0EE8 00100010
~~~ 0x0EE8: 0x28 - PLP [implied] {4}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFF 0x0EE9 10110000
~~~ 0x0EE9: 0x9D - STA 0x0203 [absoluteX] {5}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFF 0x0EEC 10110000
~~~ 0x0EEC: 0x08 - PHP [implied] {3}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0x00 0x02 0xC3 0xFE 0x0EED 10110000
~~~ 0x0EED: 0x49 - EOR 0xC3 [immediate] {2}
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x02 0xC3 0xFE 0x0EEF 10110000
~~~ 0x0EEF: 0xDD - CMP 0x0208 [absoluteX] {4}
CMP A: 0xC3 V: 0x41
>>> CPU [ A ] [ X ] [ Y ] [ SP ] [ PC ] NVxBDIZC
>>> 0xC3 0x02 0xC3 0xFE 0x0EF2 10110001
~~~ 0x0EF2: 0xD0 - BNE 0xFE [relative] {2}
--- FAIL: TestKlausDormann6502
panic: Looping PC detected. We've hit a failing Klaus Dormann test.