http://wiki.nesdev.com/w/index.php/Status_flags
This implies PHP always sets bit 5?
But then it goes on to say "When restoring the flags from memory, bits 4 and 5 are ignored"
And I've seen it implemented like so in another emulator
I'm confused because to me ignore doesn't meant set or unset, and it seems to me that the two sentences disagree with one another. The first sentence seems to be saying to set bit 4, the second is saying to ignore bit 4.
What I'm doing is going through nestest.nes and logging in the same format as the "golden log" for the test and then using vimdiff to identify where things have gone off the rails. I'm able to get the logs to agree if I implement PHP/PLP like so:
I'm just trying to understand why that's correct and the verbiage on the above page is a little confusing for me.
Can someone clear up the confusion for me?
Edit: fixed up labels for PHP/PLP code.
Quote:
On the 6502, bit 5 of the copy is always set, and bit 4 is set BRK or PHP, clear if an interrupt. When restoring the flags from memory, bits 4 and 5 are ignored, since again, there are only 6 status flags, and thus the extra 2 bits of the byte must be ignored.
This implies PHP always sets bit 5?
Code:
stack.push(cpu.P | 0x10)
But then it goes on to say "When restoring the flags from memory, bits 4 and 5 are ignored"
And I've seen it implemented like so in another emulator
Code:
cpu.P = (stack.pull()&0xEF) | 0x20
I'm confused because to me ignore doesn't meant set or unset, and it seems to me that the two sentences disagree with one another. The first sentence seems to be saying to set bit 4, the second is saying to ignore bit 4.
What I'm doing is going through nestest.nes and logging in the same format as the "golden log" for the test and then using vimdiff to identify where things have gone off the rails. I'm able to get the logs to agree if I implement PHP/PLP like so:
Code:
//PHP
stack.push(cpu.P | 0x10)
//PLP
cpu.P = (stack.pull()&0xEF) | 0x20
stack.push(cpu.P | 0x10)
//PLP
cpu.P = (stack.pull()&0xEF) | 0x20
I'm just trying to understand why that's correct and the verbiage on the above page is a little confusing for me.
Can someone clear up the confusion for me?
Edit: fixed up labels for PHP/PLP code.