Page 1 of 1

6502 PLA Test Problem

Posted: Sun Jan 13, 2013 5:44 pm
by miguelfsp
Hello guys, I'm working on a NES emulator. I'm now testing my implementation of the 6502 CPU and I'm using nestest (and the log from nintendulator) but I have a problem with the stack that I can't figure out. Please check this out guys:

Code: Select all

C7E5  78        SEI                             A:00 X:00 Y:00 P:67 SP:FB CYC:181 SL:242
C7E6  F8        SED                             A:00 X:00 Y:00 P:67 SP:FB CYC:187 SL:242
C7E7  08        PHP                             A:00 X:00 Y:00 P:6F SP:FB CYC:193 SL:242
C7E8  68        PLA                             A:00 X:00 Y:00 P:6F SP:FA CYC:202 SL:242
C7E9  29 EF     AND #$EF                        A:7F X:00 Y:00 P:6D SP:FB CYC:214 SL:242               7F  ?????????????
C7EB  C9 6F     CMP #$6F                        A:6F X:00 Y:00 P:6D SP:FB CYC:220 SL:242
What the hell? I can't figure out why the accumulator is at 7F. My emulator pulls out "6F".

With PHP, the cpu pushes the flag byte (6F) into the stack. With PLA the cpu pulls that byte "6F" from the stack... :/ Guys am I'm missing something? I tried to run some test code here: "http://skilldrick.github.com/easy6502/" to simulate my problem, and it also pulls 7F.

From where is the "7" comming from? I can't figure it out, really. :/

Thank you guys!

Re: 6502 PLA Test Problem

Posted: Sun Jan 13, 2013 5:54 pm
by tepples
One thing that BRK and PHP do that /IRQ and /NMI don't is that BRK and PHP push the value of P OR #$10. In fact, that's the only way a program can tell a BRK from /IRQ.

THIS ARTICLE WILL BE FLAGGED

Re: 6502 PLA Test Problem

Posted: Sun Jan 13, 2013 5:59 pm
by miguelfsp
Oh thank you so much! Couldn't find that info anywhere else, thanks a lot!! :)