It is currently Mon Sep 01, 2014 4:17 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Jun 08, 2011 6:33 am 
Offline
User avatar

Joined: Sun Mar 19, 2006 3:06 am
Posts: 444
Location: Gothenburg/Sweden
I've been experimenting with the NESStress ROM for awhile but am a bit curious about this test:
"PPU First Read Then Write. - This tests if the PPU address is increased after a first read."

The code can be found below. Is the PPU Address increased even on dummy-reads (the first $2007 read below) or am I getting it wrong? If I implement this behaviour in my emu, I get very strange results (or if I have done something else wrong.. :)).

Code:
.PPUTest2
   lda   #$20
   sta   $2006
   lda   #$60
   sta   $2006
   lda   $2007                     ;Increments PPU address even if it's a dummy?

   ldx   #$30
.PPUWriteLoop2
   stx   $2007                     ;Writing starts at $2061
   inx
   cpx   #$3a
   bne   .PPUWriteLoop2


   lda   #$20
   sta   $2006
   lda   #$61
   sta   $2006


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2011 7:43 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 12327
Location: NE Indiana, USA (NTSC)
Reads from $2007 increase the address even on the first read after setting $2006. There's just a 1-byte delay between the PPU's read and what appears in $2007. A read during vertical or forced blanking performs these steps:
  1. The byte from the latch is put on the data bus to the CPU.
  2. The byte at the current VRAM address is read from video memory into the latch.
  3. The VRAM address is advanced by 1 or 32.
Let me guess the way you were trying to implement it. This gets some games working but not other games, and it's not what the NES does.
  • Writes to $2006 turn on a flag "dummy_read" that suppresses incrementing on the next $2007 read.
  • Reads from $2007 do this:
    1. A byte is read directly from video memory.
    2. If dummy_read is off, the VRAM address is advanced by 1 or 32.
    3. The flag dummy_read is turned off.

The difference between the two behaviors becomes apparent when a program intermixes reads from $2007 and writes to $2007 or intermixes $2007 accesses with changing the VRAM address stride in $2000 bit 2.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2011 11:22 am 
Offline
User avatar

Joined: Sun Mar 19, 2006 3:06 am
Posts: 444
Location: Gothenburg/Sweden
So is this correct behaviour (see comments in code below) ? I'm sorry if I am not using correct terminology but perhaps you get what I mean?

Code:
.PPUTest2
   lda   #$20
   sta   $2006
   lda   #$60
   sta   $2006
   lda   $2007     ;Return data that's stored in the latch (garbage at the moment) and load
                        ;the latch with the new value. Increment PPU address to $2061
 
   ldx   #$30
.PPUWriteLoop2
   stx   $2007
   inx
   cpx   #$3a
   bne   .PPUWriteLoop2


   lda   #$20
   sta   $2006
   lda   #$61
   sta   $2006      ;Latch is reset

   ldx   #$30
   stx   $04
   ldy   #9
   lda   $2007       ;Returns dummy-data, load contents of $2061 to latch, increase PPU-address to $2062

   lda   #$22
   sta   $02
   lda   #$3b
   sta   $03
.PPUReadLoop2
   lda   $2007       ;Returns latchdata ($2061+)
   cmp   $04
   bne   .PPUError2
   inc   $04
   dey

_________________
http://nes.goondocks.se/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2011 11:40 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 6023
Location: Jongny, VD, Switzerland
I think it will return dummy data only the very first time after booting.
All the other times I guess it will ALWAYS return the content in the latch which was the last adress read. So here :


Code:
   ldx   #$30
   stx   $04
   ldy   #9
   lda   $2007       ;Returns dummy-data, load contents of $2061 to latch, increase PPU-address to $2062


It will read what was stored in $2060. (Anyone please correct me if I'm wrong).

Another interesting note is that palette ($3F00 and so on) reads internally to the PPU (instead of reading from VRAM/VROM) so they are immediately returned.
In other words reading $0000-$3EFF returns content from the latch, and makes the read transferred to the PPU's bus on next cycle, while reads from $3F00 directly reads the palette and nothing is shown on bus (is the latch affected by this ??)

_________________
Life is complex: it has both real and imaginary components.


Last edited by Bregalad on Wed Jun 08, 2011 11:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2011 11:43 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 12327
Location: NE Indiana, USA (NTSC)
I'm not so sure that the value in the $2007 readback latch survives across a write to $2007 or across a period of rendering. Are there tests for these behaviors?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2011 11:45 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 6023
Location: Jongny, VD, Switzerland
You are right, I'm not so sure either...
But he seems to think that writing to $2006 will magically "erase" the latch with a dummy value, which I'm pretty sure is wrong.

_________________
Life is complex: it has both real and imaginary components.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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