Testing emulator with nestest - i don't understand part of logs

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Darek554
Posts: 7
Joined: Tue Apr 13, 2021 11:03 pm

Testing emulator with nestest - i don't understand part of logs

Post by Darek554 »

Hi.

I'm testing my 6502 implementation with "nestest" rom and comparing my emulator behavior with "nestest" logs, but there is a strange fragment in tthis "nestest" logs:

Code: Select all

C836  A9 04     LDA #$04                  A:FF X:00 Y:00 P:EF SP:FB CYC:146 SL:243
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
C836 is loading number 4 into accumulator, then this number is stored onto the stack, next PLP pulls byte from stack and place it in the status register so status value should be 4, but as You can see on C83A P value it is 24.
I don't understand this behaviour, can someone explain this to me?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Testing emulator with nestest - i don't understand part of logs

Post by tepples »

Bit 5 (place value $20) and 4 (place value $10) do not exist in CPU register P (status flags). Their value is calculated when the flags are pushed through PHP, BRK, or an interrupt. For the sake of convention, logs from Nintendulator show P with bit 5 set to 1 and bit 4 clear to 0. See also "Status flags" on the wiki.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Testing emulator with nestest - i don't understand part of logs

Post by Quietust »

Darek554 wrote: Wed Apr 14, 2021 6:03 am I'm testing my 6502 implementation with "nestest" rom and comparing my emulator behavior with "nestest" logs, but there is a strange fragment in tthis "nestest" logs:

Code: Select all

C836  A9 04     LDA #$04                  A:FF X:00 Y:00 P:EF SP:FB CYC:146 SL:243
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
Out of curiosity, where exactly did you get that logfile from?
I ask because the wiki has a newer version of that logfile which adjusts the formatting and fixes a few minor errors in how certain instructions were represented.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Darek554
Posts: 7
Joined: Tue Apr 13, 2021 11:03 pm

Re: Testing emulator with nestest - i don't understand part of logs

Post by Darek554 »

tepples wrote: Wed Apr 14, 2021 6:35 am Bit 5 (place value $20) and 4 (place value $10) do not exist in CPU register P (status flags). Their value is calculated when the flags are pushed through PHP, BRK, or an interrupt. For the sake of convention, logs from Nintendulator show P with bit 5 set to 1 and bit 4 clear to 0. See also "Status flags" on the wiki.
Ok, so when PHP is executed Bit 5 is set to 1 and Bit 4 is set to 1, then it's pushed,
and when PLP is executed, status is pulled and Bit 4 flag is set to 0?

@Quietust
https://github.com/christopherpow/nes-t ... estest.log
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Testing emulator with nestest - i don't understand part of logs

Post by tepples »

When instruction PLP is executed:
Bit 7 is sent to the N flag
Bit 6 is sent to the V flag
The CPU disregards bit 5
The CPU disregards bit 4
Bit 3 is sent to the D flag (which the ADC and SBC instructions ignore but which can still be set to 1 or 0)
Bit 2 is sent to the I flag
Bit 1 is sent to the Z flag
Bit 0 is sent to the C flag

When comparing the results of your emulator to the results from Nintendulator, disregard bits 5 and 4 in the "P after this instruction" field in the comparison.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Testing emulator with nestest - i don't understand part of logs

Post by Quietust »

Darek554 wrote: Wed Apr 14, 2021 9:23 am @Quietust
https://github.com/christopherpow/nes-t ... estest.log
I'll need to contact the owner of that repository, then - the log there is quite old and has at least one error in it (specifically, the indirect JMP test at $DBB5 suggests that it's going to jump to $A900 when it actually goes to $0300).
tepples wrote: Wed Apr 14, 2021 10:53 am When comparing the results of your emulator to the results from Nintendulator, disregard bits 5 and 4 in the "P after this instruction" field in the comparison.
The register values shown are actually from before the instruction has been executed.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Darek554
Posts: 7
Joined: Tue Apr 13, 2021 11:03 pm

Re: Testing emulator with nestest - i don't understand part of logs

Post by Darek554 »

tepples wrote: Wed Apr 14, 2021 10:53 am When instruction PLP is executed:
Bit 7 is sent to the N flag
Bit 6 is sent to the V flag
The CPU disregards bit 5
The CPU disregards bit 4
Bit 3 is sent to the D flag (which the ADC and SBC instructions ignore but which can still be set to 1 or 0)
Bit 2 is sent to the I flag
Bit 1 is sent to the Z flag
Bit 0 is sent to the C flag

When comparing the results of your emulator to the results from Nintendulator, disregard bits 5 and 4 in the "P after this instruction" field in the comparison.
Thanks!

Can You explain me one more thing?

When CPU is powered-up then it's status is set to 0x34 so Bit 5 is set to 1 Bit 4 and Bit 3 also, remaining bits are 0's.
But when reset happens Bit 3 is set to 1 and remaining bits doesn't change or they are set to 0's?

Edit:
Actually i have one more question, if you can answer it will be great.

In nestest txt file, author writes that test results are stored in specific locations, but i dont understand what does he mean by saying, that all tests results are stored in 03h, and then listing addresses where 03h address is taken by BCC or SBC test result.
I hope You understand what i want to tell xd
Can You tell me where this results are stored?

https://github.com/christopherpow/nes-t ... estest.txt

Line 66, 95 and 371
Post Reply