It is currently Mon Nov 20, 2017 10:34 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sun Oct 25, 2015 7:12 pm 
Offline

Joined: Sun Oct 25, 2015 4:16 pm
Posts: 7
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?


Top
 Profile  
 
PostPosted: Sun Oct 25, 2015 7:46 pm 
Offline

Joined: Thu Aug 20, 2015 3:09 am
Posts: 288
The N and V flags are set according the memory value, prior to the AND operation. Reference.


Top
 Profile  
 
PostPosted: Sun Oct 25, 2015 7:52 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5822
Location: Canada
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.


Top
 Profile  
 
PostPosted: Mon Oct 26, 2015 6:06 pm 
Offline

Joined: Sun Oct 25, 2015 4:16 pm
Posts: 7
Thank you very much. That fixed it. I have been following this resource and it did not mention that at all.


Top
 Profile  
 
PostPosted: Mon Oct 26, 2015 7:04 pm 
Online
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
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

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Mon Oct 26, 2015 7:32 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3075
Location: Brazil
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.


Top
 Profile  
 
PostPosted: Tue Oct 27, 2015 2:55 am 
Online
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
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

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Tue Oct 27, 2015 4:08 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3075
Location: Brazil
...and what's "wrong" with this?


Top
 Profile  
 
PostPosted: Tue Oct 27, 2015 4:54 am 
Online
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
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.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Thu Oct 29, 2015 5:48 pm 
Online
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
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.)

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot], Donqustix and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group