I am continuing my java emu but I have been struggling with the indirect indexed (Y) implementation.
It is a conceptual emu, I am not trying to do much more than emulating some NROM games and not being cycle accurate.
The code below works on nestest with the following words (MSB) on memory:
[3][0]
D922 B1 89 LDA A:00 X:65 Y:00 P:27 SP:FB CYC:8760
D924 F0 0C BEQ A:89 X:65 Y:00 P:A5 SP:FB CYC:8765
[F][F]
D940 B1 97 LDA A:FF X:65 Y:34 P:65 SP:FB CYC:8793
D942 C9 A3 CMP A:A3 X:65 Y:34 P:E5 SP:FB CYC:8799
But when I have [0][70] my code below is failing. I guess I am misunderstanding the computation, maybe on the carry or on the extra cycle. I have read the c64doc.txt, into the details of every cycle, and have not figured out how it works - maybe because I am not a native english speakers.
Source: D959 B1 FF LDA A:01 X:65 Y:FF P:E5 SP:FA CYC:8824 Target: D959 B1 FF LDA A:01 X:65 Y:FF P:E5 SP:FA CYC:8824
Source: D95B C9 12 CMP A:00 X:65 Y:FF P:67 SP:FA CYC:8830 Target: D95B C9 12 CMP A:12 X:65 Y:FF P:65 SP:FA CYC:8830 ***** MISMATCH, A SHOULD BE 12 ****
My code:
Code: Select all
int operand = peekByte(i); //get 0-page index
int[] hiloaddr = cpu.peekWord(1 + operand, cpu); // word as MSB
int lowcarry = ((hiloaddr[1] + cpu.Y_REG) > 0xFF? 1:0); //operate on low addr to check for carry (8 bit ALU)
int hicarry = ((hiloaddr[0] + lowcarry) > 0xFF? 1:0); //operate on high addr to check for carry (8 bit ALU)
int addr = (Util.arraytoInt(hiloaddr) + cpu.Y_REG + lowcarry);
int value = peekByte(addr); //when debugging, I get 326 (decimal) instead of 581 (to reach the data at MEM[580] = 0x12
int ecycle = 0; if(hicarry > 0 | lowcarry > 0) ecycle = 1;
return(new int[] {ecycle, value});