nesdev.com
http://forums.nesdev.com/

Error in nestest log, or with my logic?
http://forums.nesdev.com/viewtopic.php?f=3&t=13403
Page 1 of 1

Author:  Fjotten [ Sun Oct 25, 2015 7:12 pm ]
Post subject:  Error in nestest log, or with my logic?

I have started working on my own NES emulator, and after finishing most, if not all, of my CPU core I have started testing it with the nestest but I found a weird error at the following instructions.

Code:
C8B9  18        CLC                             A:00 X:00 Y:00 P:2F SP:FB
C8BA  24 01     BIT $01 = FF                    A:00 X:00 Y:00 P:2E SP:FB
C8BC  A9 55     LDA #$55                        A:00 X:00 Y:00 P:EE SP:FB


Upon further inspection I see that my emulator have the correct values: A = 0, $01 = 0xFF and P = 0x2E. According to the nestest log P = 0xEE after executing BIT, but how is that possible when A = 0 and $01 = 0xFF? 0x00 & 0xFF = 0x00, which means that both the N and V flags should be false at this point. Following the same logic, I would assume that P = 0x2E after executing BIT.

Am I missing something, or is there some error with the nestest log?

Author:  Rahsennor [ Sun Oct 25, 2015 7:46 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

The N and V flags are set according the memory value, prior to the AND operation. Reference.

Author:  rainwarrior [ Sun Oct 25, 2015 7:52 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

With BIT only the Z flag is from the AND result. N and V are from the operand's fetched value, not the result of the AND.

Edit: Rahsennor already covered it. Sorry for duplicate answer.

Author:  Fjotten [ Mon Oct 26, 2015 6:06 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

Thank you very much. That fixed it. I have been following this resource and it did not mention that at all.

Author:  thefox [ Mon Oct 26, 2015 7:04 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

It's good to use multiple references.

This one is a decent high-level overview: http://www.obelisk.me.uk/6502/reference.html
This one details the cycle-by-cycle behavior (there are a few errors though, IIRC): http://nesdev.com/6502_cpu.txt

Author:  Zepper [ Mon Oct 26, 2015 7:32 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

thefox wrote:
This one details the cycle-by-cycle behavior (there are a few errors though, IIRC): http://nesdev.com/6502_cpu.txt


Do you mind to mention some of these errors? I used such doc to write my 6502 emulator.

Author:  thefox [ Tue Oct 27, 2015 2:55 am ]
Post subject:  Re: Error in nestest log, or with my logic?

I don't think there were any big errors that I found, more like mistakes/typos, like this one for BRK:

Code:
3  $0100,S  W  push PCH on stack (with B flag set), decrement S

Author:  Zepper [ Tue Oct 27, 2015 4:08 am ]
Post subject:  Re: Error in nestest log, or with my logic?

...and what's "wrong" with this?

Author:  thefox [ Tue Oct 27, 2015 4:54 am ]
Post subject:  Re: Error in nestest log, or with my logic?

PCH is the hibyte of PC, it doesn't have a "B flag". The note about B flag was supposed to be on another line.

Author:  thefox [ Thu Oct 29, 2015 5:48 pm ]
Post subject:  Re: Error in nestest log, or with my logic?

Another error I happened to notice:

Code:
IRQ and BRK both set the I flag, whereas the NMI does not affect its state.

(NMI does set the I flag.)

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/