It is currently Sun Apr 23, 2017 3:05 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Feb 21, 2017 12:17 am 
Offline

Joined: Mon Feb 20, 2017 1:39 pm
Posts: 3
I'm trying to figure out why my emulator and every other emulator I've tried behave differently during the first few instructions of Donkey Kong (Japan) being executed.

Code:
;Disable interrupts
C79E : 78         sei         ;
;Clear the CPU's decimal flag
C79F : D8         cld         ;
;Reset PPU control (including the disabling of VBL interrupts)
C7A0 : A9 10      lda   #$10      ;
C7A2 : 8D 00 20      sta   $2000      ;
;Init stack pointer
C7A5 : A2 FF      ldx   #$FF      ;
C7A7 : 9A         txs            ;
;Wait for VBL, looping until it happens
C7A8 : AD 02 20      lda   $2002      ;
C7AB : 29 80      and   #$80      ;
C7AD : F0 F9      beq   $C7A8      ;


Nintendulator initializes the PPU registers with 0xFF. When it does
Code:
C7A0 : A9 10      lda   #$10      ;
C7A2 : 8D 00 20      sta   $2000      ;

One would expect $2000 to have the value 0x10 in it. This isn't reflected in the CPU memory viewer.

Next, when it does
Code:
C7A8 : AD 02 20      lda   $2002      ;

I would expect 0xFF to be loaded into the accumulator (since $2002 is initialized with 0xFF in this emulator. That's not the case. It actually loads the value 0x10 into the accumulator. Where does this value come from?

In my emulator, my memory is initialized to 0x00, so when it does the load from $2002, I load the value 0x00 into the accumulator.


Top
 Profile  
 
PostPosted: Tue Feb 21, 2017 12:43 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 5555
Location: Seattle
In the NES, addresses from $2000-$5BFF are never random-access memory, but instead MMIO


Top
 Profile  
 
PostPosted: Tue Feb 21, 2017 10:31 am 
Offline

Joined: Mon Feb 20, 2017 1:39 pm
Posts: 3
lidnariq wrote:
In the NES, addresses from $2000-$5BFF are never random-access memory, but instead MMIO


That does make sense, although even FCEUX seems to show the last value written just to make it easier to see what's going on (as does my emulator).

I'm still unsure about how $2002 = 0x10. It never gets set to that, so how does it get that value?


Top
 Profile  
 
PostPosted: Tue Feb 21, 2017 10:47 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 18177
Location: NE Indiana, USA (NTSC)
Data bus capacitance inside the PPU has the effect of briefly storing the last value written to or read from any PPU port ($2000-$3FFF) in a dynamic latch. This dynamic latch, called _io_db in Visual 2C02 and PPUGenLatch in FCEUX, can be read through any of the nominally read-only ports ($2000, $2001, $2003, $2005, $2006) as well as the low 5 bits of $2002. For example, writing $69 to $2007 sets the value of this latch to $69 (%01101001), and then reading it back through $2002 may return $09, or $89 if vblank just started, or $49 after a sprite 0 hit, etc.

See also other posts mentioning PPUGenLatch: Riding the open bus; Can I use PPUGenLatch's value again?


Top
 Profile  
 
PostPosted: Thu Feb 23, 2017 10:51 pm 
Offline

Joined: Mon Feb 20, 2017 1:39 pm
Posts: 3
tepples wrote:
Data bus capacitance inside the PPU has the effect of briefly storing the last value written to or read from any PPU port ($2000-$3FFF) in a dynamic latch. This dynamic latch, called _io_db in Visual 2C02 and PPUGenLatch in FCEUX, can be read through any of the nominally read-only ports ($2000, $2001, $2003, $2005, $2006) as well as the low 5 bits of $2002. For example, writing $69 to $2007 sets the value of this latch to $69 (%01101001), and then reading it back through $2002 may return $09, or $89 if vblank just started, or $49 after a sprite 0 hit, etc.

See also other posts mentioning PPUGenLatch: Riding the open bus; Can I use PPUGenLatch's value again?



Thanks for this, I had no idea about this phenomena. Is this something I need to implement in my emulator to get something basic like Donkey Kong working?


Top
 Profile  
 
PostPosted: Fri Feb 24, 2017 5:49 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1354
blkhp19 wrote:
Thanks for this, I had no idea about this phenomena. Is this something I need to implement in my emulator to get something basic like Donkey Kong working?

For basic games? No - you just need to properly implement the PPU and its I/O interface to the CPU.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
PostPosted: Fri Feb 24, 2017 7:56 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9517
Location: Rio de Janeiro - Brazil
Very few games rely on open bus, AFAIK, but you should eventually implement it if accuracy is one of your goals.


Top
 Profile  
 
PostPosted: Fri Feb 24, 2017 8:06 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 2981
Location: Brazil
You need a decent CPU code in order to get the things working right, and a basic PPU rendering engine to see the outputs. PPU registers are VERY important - I'd say $2007 + loopy's logic is the second heart (first is the CPU).


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 3 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