Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

6502 emulator testing: nestest

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:

enter image description here

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?

like image 785
HastatusXXI Avatar asked Jan 01 '23 23:01

HastatusXXI


1 Answers

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).

like image 190
Eight-Bit Guru Avatar answered Jan 07 '23 15:01

Eight-Bit Guru