I am implementing my own MOS 6502 cpu emulator for a future NES emulator. I am using nestest in order to test the emulator correctness. Everything seems find until I reach this lines:
As you can see the status register is (6F) is pushed onto the stack. In the next instruction it is pulled from the stack in the acumulator. In the next fetch the log shows A: 7F. Does this make any sense? Should not A be 6F?
I am using this log: http://www.qmtpro.com/~nes/misc/nestest.log
Since it comes from Nintendulator it should be reliable, I guess.
Am I mistaken or is this log unreliable?
For reasons better explained here and here, PHP
always sets the Break flag when it pushes the Status Register to the Stack. However, there's a representational difference between how that flag is physically implemented vs. how we visualise it - it isn't actually held in the Status Register at all, but is presented as though it is.
When the 6502 executes a PHP
instruction, it sets bit 4 in the value of the Status Register that is written to the Stack, but this is not reflected as an actual change to the Status Register itself. Thus, your log shows the Status Register as unchanged after PHP
, but when you PLA
that byte it has bit 4 set. You can see this for yourself by using your monitor to break after the PHP
instruction and then take a look at the byte in the Stack memory area ($01xx).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With