2005 or 2000 writes, how they affect 2006/2007

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

2005 or 2000 writes, how they affect 2006/2007

Post by dougeff »

As previously stated in another thread, I wasn't sure how an errant 2005 or 2000 write would affect a large block of writes to the PPU (ie, if the NMI interrupted the writes and wrote to 2000 and/or 2005). I tested this in FCEUX 2.2.3 and Nintendulator (but not on hardware, sorry). These were my results...they may be obvious to some of the regulars here.

all are writes, except where noted

(basic)
2006 2006 2007
-correct PPU address

(sta 2005 x1)

2005 2006 2006 2007
-!! sets wrong PPU address

2006 2005 2006 2007
-!! never sets an address

2006 2006 2005 2007
-correct PPU address

(sta 2005 x2)

2005 2005 2006 2006 2007
-correct PPU address

2006 2005 2005 2006 2007
-!! sets wrong PPU address

2006 2006 2005 2005 2007
-correct PPU address

2006 2006 2007 2005 2007 2005 2007
-correct PPU address

(lda 2002)

lda2002 2006 2006 2007
-correct PPU address

2006 lda2002 2006 2007
-!! never sets an address

2006 2006 lda2002 2007
-correct PPU address

(sta 2000)

*2000 of same nametable select
2000 2006 2006 2007
-correct PPU address

2006 2000 2006 2007
-correct PPU address

2006 2006 2000 2007
-correct PPU address

*2000 of different (wrong) nametable select
2000 2006 2006 2007
-correct PPU address

2006 2000 2006 2007
-!! WRONG PPU address (different nametable)

2006 2006 2000 2007
-correct PPU address

2006 2006 2007 2000 2007
-correct PPU address

(lda 2007)

lda2007 2006 2006 2007
-correct PPU address

2006 lda2007 2006 2007
-correct PPU address

2006 2006 lda2007 2007
-PPU address is 1 to the right

2006 2006 sta2007 lda2007 sta2007
-correct PPU address, 1 write, skip 1 spot, 1 write

(lda 2006)
(returns open bus, doesn't affect anything)

lda2006 2006 2006 2007
-correct PPU address

2006 lda2006 2006 2007
-correct PPU address

2006 2006 lda2006 2007
-correct PPU address
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: 2005 or 2000 writes, how they affect 2006/2007

Post by rainwarrior »

If you want to walk through why those !! things happen, the mechanics of it are explained here:
http://wiki.nesdev.com/w/index.php/PPU_scrolling

Of particular relevance is the write toggle (w in that article) which is shared by $2005 and $2006.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: 2005 or 2000 writes, how they affect 2006/2007

Post by Bregalad »

I could be mistaken, but the $2005 and $2000.0 writes are only copied to the scrolling counters at specific points in rendering (start of frame, start of scanline), and does not affect $2006/7 outside of those specific points. So if you wanted to, say, adress the PPU using $2005 instead of $2006 for VRAM updates, you can't do that.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: 2005 or 2000 writes, how they affect 2006/2007

Post by rainwarrior »

Well, a quick summary:


$2000 and $2005 write to a temporary register.

$2006 writes to the same temporary register, but the 2nd write also copies that temporary register into the PPU address immediately.

If rendering is on, this copy from temp to PPU address also happens at the end of vblank. (...and the X part is re-copied every scanline.)

$2007 immediately increments the PPU address by 1 or 32.

Reading $2002 resets the write pair order shared by $2005/2006, i.e. the next write will have "1st write" behaviour.
Post Reply