Hey guys, I currently have my 6502 emulator passing all the nestest tests without any errors.
However, when I was fixing bugs I came across a problem with one of the BNE instructions in nestest. I figured out what was happening: When I was "jumping" I was adding the immediate directly to the program counter (PC += immediateByte).
I realized that it was wrong because the highest significant bit would wrap-around, so I fixed the bug this way:
And after that it worked all right... So I replicated that line in all the other Branches and removed the old (PC+=immediateByte) code.
But when I do this to all the other branches, nestest starts failing. :/ So I kept it only at the BNE. Today I loaded another NES ROM and it was also messing up with the jumps, so I also replaced the BPL to do the wrap-around.
Now, obvisouly there is something REALLY wrong here. :/ Do you guys have any ideas? Am I missing something about the branch instructions? Oh by the way, when I say "PC" I mean the PC at the beggining of the instruction.
Thank you guys!
However, when I was fixing bugs I came across a problem with one of the BNE instructions in nestest. I figured out what was happening: When I was "jumping" I was adding the immediate directly to the program counter (PC += immediateByte).
I realized that it was wrong because the highest significant bit would wrap-around, so I fixed the bug this way:
Code:
this.PC = (UInt16)((this.PC & 0xFF00) | ((this.PC + immediateByte) & 0xFF));
And after that it worked all right... So I replicated that line in all the other Branches and removed the old (PC+=immediateByte) code.
But when I do this to all the other branches, nestest starts failing. :/ So I kept it only at the BNE. Today I loaded another NES ROM and it was also messing up with the jumps, so I also replaced the BPL to do the wrap-around.
Now, obvisouly there is something REALLY wrong here. :/ Do you guys have any ideas? Am I missing something about the branch instructions? Oh by the way, when I say "PC" I mean the PC at the beggining of the instruction.
Thank you guys!