PLP and nestest.log

PLP and nestest.log
by on (#128868)
So, nestest.log contains the following two PLPs:

Code:
C824  48        PHA                             A:FF X:00 Y:00 P:AD SP:FB CYC: 86 SL:243
C825  28        PLP                             A:FF X:00 Y:00 P:AD SP:FA CYC: 95 SL:243
C826  D0 09     BNE $C831                       A:FF X:00 Y:00 P:EF SP:FB CYC:107 SL:243


... and ...

Code:
C838  48        PHA                             A:04 X:00 Y:00 P:6D SP:FB CYC:152 SL:243
C839  28        PLP                             A:04 X:00 Y:00 P:6D SP:FA CYC:161 SL:243
C83A  F0 09     BEQ $C845                       A:04 X:00 Y:00 P:24 SP:FB CYC:173 SL:243


What exactly happens to the P regiser? In both cases the B bit is coming out as zero which from what I researched seems to be the right thing due to it not being really in the register and how it's used to signal hardware interrupts, etc.

But in the second case that 0x04 is turning into a 0x24... what about that bit 5? Where did it come from?
Re: PLP and nestest.log
by on (#128870)
Bits 5 and 4 of P do not exist in the 6502. They are created when /IRQ, /NMI, BRK, or PHP is executed. When comparing your emulator's behavior to that of Nintendulator, you can safely ignore differences in bits 5 and 4 of P.
Re: PLP and nestest.log
by on (#128876)
Bit 5 does exist, and its always set. Bit 4 only exists on the stack and only when IRQ or PHP are used.
Re: PLP and nestest.log
by on (#128887)
Your comment is confusing and wrong.

There are 6 bits of state in the physical hardware of the status register. Those are Z, C, N, V, D, and I.

I can point them out on Visual6502 (or Visual2A03) or the reverse engineered hardware-level schematics that preceeded the simulators.

But if you look for the $20s bit or $10s bit, you will find:
* One transistor that pulls down the $10s bit of the data bus when the current action is "push the flags register to the stack during an NMI or IRQ".

That's it. Nothing else. There is no $20s bit, there is no "B" bit. They simply do not exist outside of the expanded copy (from 6 to 8 bits) that has been made on the stack.
Re: PLP and nestest.log
by on (#128901)
WedNESday wrote:
Bit 5 does exist, and its always set.

To be fair this is one of those 'to each, his own' things. When the P register is displayed in some sort of debug mode it is entirely up to the author of the emulator whether you see for instance $24 on power-up or just $04. It doesn't of course make a difference but seeing as this bit is always set on the stack I personally always see $24 as it is better practice. Either way not confusing.

WedNESday wrote:
Bit 4 only exists on the stack and only when IRQ or PHP are used.

Correct and not confusing. I never said that this bit existed outside of the stack. In fact if you take the time to read my post you'll see that I said the opposite.

Edit: [I] tags.
Re: PLP and nestest.log
by on (#128908)
Then you could say that those bits are "created" by the debugger in the same way that they are "created" by the PHP and interrupt handling logic. Either way, your 6502 simulator's test harness SHOULD ignore differences in bits 5 and 4 when parsing a Nintendulator log.