Hello all,
Today I finished implementing all the unofficial op-codes, and all of them pass blargg's CPU test roms, except for two. SHX and SHY ($9E and $9C respectively). I have searched around the internet for the expected behavior of these two codes, and documents varied but most agreed that they "take the high order byte from the address, add 1 then AND that with X or Y and store it at the address plus Y or X". But when I try implementing the instructions in this fashion, they don't pass the test roms. Here is my current implementation:
In that code, 'addrAddr' contains the address BEFORE adding X or Y for absolute indexed addressing (I do it this way to be able to check for page crossing). The method 'poke' is basically just an accessor for the memory write function, and always stores the data passed to it at the effective address of the last addressing mode.
So for example, SHX $8000 would take the value of (X & $81) and store it at $807F (Assuming Y contains $7F). Is this the correct behavior? Is this code known to not have a reliable behavior, or should I just stop worrying about this one?
Help greatly appreciated as always!
Today I finished implementing all the unofficial op-codes, and all of them pass blargg's CPU test roms, except for two. SHX and SHY ($9E and $9C respectively). I have searched around the internet for the expected behavior of these two codes, and documents varied but most agreed that they "take the high order byte from the address, add 1 then AND that with X or Y and store it at the address plus Y or X". But when I try implementing the instructions in this fashion, they don't pass the test roms. Here is my current implementation:
Code:
private void OpShx()
{
var data = ((this.addrAddr >> 8) + 1) & 0xFF;
this.poke(this.x & data);
}
private void OpShy()
{
var data = ((this.addrAddr >> 8) + 1) & 0xFF;
this.poke(this.y & data);
}
{
var data = ((this.addrAddr >> 8) + 1) & 0xFF;
this.poke(this.x & data);
}
private void OpShy()
{
var data = ((this.addrAddr >> 8) + 1) & 0xFF;
this.poke(this.y & data);
}
In that code, 'addrAddr' contains the address BEFORE adding X or Y for absolute indexed addressing (I do it this way to be able to check for page crossing). The method 'poke' is basically just an accessor for the memory write function, and always stores the data passed to it at the effective address of the last addressing mode.
So for example, SHX $8000 would take the value of (X & $81) and store it at $807F (Assuming Y contains $7F). Is this the correct behavior? Is this code known to not have a reliable behavior, or should I just stop worrying about this one?
Help greatly appreciated as always!