It is currently Sun May 20, 2018 10:32 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Nov 02, 2010 3:03 am 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
Hello.
I did little speedcoding with an emulator last saturday (first time since 2002 or so), and I'm wondering if this works correctly on the real thing too.
So could someone with a PowerPak or some other dev system test it for me?

It's just an little birthday greeting intro with some music from Little Nemo.

Here's the rom: http://emdia.fi/~mankeli/synde.nes


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2010 5:05 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20055
Location: NE Indiana, USA (NTSC)
First I ran it on my PowerPak. There was a bit of garbage along the bottom, which appears to have been due to not having cleared out the whole nametable.

Nestopia didn't like those NES 2.0 flags (it showed alert("Corrupt File!") and didsn't load anything), so I converted it back to iNES format by zeroing them out, and then I doubled the CHR ROM. The garbage wasn't there in Nestopia.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2010 11:39 pm 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
Okay. Thank you Tepples.

I didn't realize that char converter didn't create whole 8k bank as emu didn't complain.
And how silly of me to forget the proper initialization of nametables too.

But I'm glad you spotted out those, as I was mainly wondering about the code running properly and if $0000 -> $2006 at the end of NMI is enough to keep the screen at right position.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2010 12:00 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10480
Location: Rio de Janeiro - Brazil
mankeli wrote:
...if $0000 -> $2006 at the end of NMI is enough to keep the screen at right position.

That might be working, but the correct way to set the scroll is to write twice to $2005 to define the pixel offsets and once to $2000 to select the name table. Writes to $2006 alone don't fully reset the scroll, since they don't affect the fine X scroll.

The only time $2006 is actually necessary for scrolling is when you need to modify the scroll when outside of VBank, something that happens when you enable rendering late (to gain more time for PPU transfers) or perform raster effects. If you are doing all PPU manipulations during VBlank (which is the norm), $2000 and $2005 should be used.

And remember, tepples tested it on a PowerPak, which has a boot ROM that modifies the state of the machine before your program runs, so you must make sure everything is initialized properly even though it appears to work OK on hardware. For example, if you don't reset the fine X scroll the screen might get shifted up to 7 pixels to the right, but that won't happen on the PowerPak because its boot ROM did initialize the X scroll.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2010 12:41 am 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
tokumaru wrote:
mankeli wrote:
...if $0000 -> $2006 at the end of NMI is enough to keep the screen at right position.

That might be working, but the correct way to set the scroll is to write twice to $2005 to define the pixel offsets and once to $2000 to select the name table. Writes to $2006 alone don't fully reset the scroll, since they don't affect the fine X scroll.


I see. Thanks for pointing that out.

So Loopy_T is undefined at power-up, but $2006 writes do initialize it to right value (Loopy_V gets initialized too), and hence the screen will be at right position. (not counting fine x scroll, which is probably 0 in emu's and initialized to 0 by powerpak).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2010 10:52 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10480
Location: Rio de Janeiro - Brazil
mankeli wrote:
So Loopy_T is undefined at power-up, but $2006 writes do initialize it to right value (Loopy_V gets initialized too), and hence the screen will be at right position. (not counting fine x scroll, which is probably 0 in emu's and initialized to 0 by powerpak).

Yeah, this is most likely what happens. But you shouldn't really worry about things like loopy_t or loopy_v unless you are writing an emulator or doing scrolling tricks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 3:22 pm 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
Okay. Now I get it. I was wondering for a long time why $2005 writes weren't enough to make the screen stay still. (As all PPU writes happen during the vblank, and screen remained at wrong position even when there were no PPU writes during the current frame)
But this was because i didn't write to $2000 again, and hence writes to $2006 trashed D11-D10 of Loopy_T.

Nice to finally understand the magic behind this. Thanks Tokumaru. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 3:32 pm 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
And anyway, that's the point of coding for a platform like NES if you don't try to understand how it works?

_________________
So now the question is survival. is this the end of technological man?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 3:40 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7432
Location: Chexbres, VD, Switzerland
I don't know if this has already been said in the posts above (too lazy to read them it takes less effort to just write it), you have to do your $2006/7 updates in your VBlank, and THEN do two $2005 writes and one $2000 write.
This will set the scroll correctly.

Quote:
And anyway, that's the point of coding for a platform like NES if you don't try to understand how it works?

You got the spirit. We at nesdev take more time to figure how the sytem works than actually develop games for it (as the result of the poor library of public domain NES games).

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 3:47 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10480
Location: Rio de Janeiro - Brazil
mankeli wrote:
And anyway, that's the point of coding for a platform like NES if you don't try to understand how it works?

Sure, wanting to understand things better is never a bad thing. If you feel like learning more about how scrolling works internally, go ahead.

It's just that the way in which loopy's discoveries are presented ("the skinny on...") makes it seem like they are essential information for anyone wanting to code scrolling programs, when this is not the case. The only thing I have against it is that it causes newbies to get confused for nothing, because in 99% of the cases they don't even need that information in the first place.

Even in your case, since you decided to use $2006 to reset the scroll you ended up neglecting the registers that were actually designed for this purpose ($2000 and $2005), and should be used under normal circumstances. Using $2006 to affect the scroll is a trick, that even a good deal of commercial programmers back in the NES era didn't know about.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 5:28 pm 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
Yes, I concur that the internal workings are not necessary information for a beginner. But I didn't realize the importance of the $2000 write, so $2005 didn't work, and I settled on $2006 which at least stabilized the screen.

Maybe there's a need for a "simplified" explanation of what's in Loopy's doc, because I think it's absolutely necessary to explain why do you have to write registers in $2005 $2005 $2000 order. Maybe just something like "all those three writes must be done, and in this order, because PPU scrolling position will be trashed after $2006 writes". Then if that's not enough, coders could check out the Loopy's doc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2010 8:38 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10480
Location: Rio de Janeiro - Brazil
mankeli wrote:
Maybe there's a need for a "simplified" explanation of what's in Loopy's doc, because I think it's absolutely necessary to explain why do you have to write registers in $2005 $2005 $2000 order.

But you don't have to write in this order... as long as you keep track of the latch that selects between the first and second writes to $2005 (so that you know if the write will affect the horizontal or the vertical scroll) you can write to these registers in any order you want. The order is only important if you are using $2006 for scrolling purposes, something you shouldn't do under normal circumstances. The information contained in loopy's doc is of absolutely no use if you are setting the scroll still inside of VBlank.

Quote:
Maybe just something like "all those three writes must be done, and in this order, because PPU scrolling position will be trashed after $2006 writes".

The correct would be: "after you are done using $2006/$2007 for uploading data to the PPU, you must set the scroll using $2000 and $2005".

Quote:
Then if that's not enough, coders could check out the Loopy's doc.

"If you have the need to set the scroll while the screen is rendering (outside of VBlank), then look into loopy's doc, if not, there's nothing for you in there".


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2010 2:06 am 
Offline

Joined: Sat Dec 15, 2007 6:16 am
Posts: 10
Oh yes. You are correct. I was thinking for some reason that $2005 also thrashes D10-D11 of Loopy_T.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2010 11:08 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7432
Location: Chexbres, VD, Switzerland
To be honnest I never ever understood loopy's doc, and probably never will. Nevertheless, scrolling with $2005 and even "tricky" $2006 midframe is really simpler than it sounds as long as you're not trying to do something mid-scanline or anything. If you want to deal with midframe scrolling changes, I tried to make a "simpler" explaination here (along with a lot of other stuff), but I don't know how simpler it is in the eyes of a newbies.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2010 1:09 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4042
I think the top status bar scrolling demo is a bad example, since it is moving sprite 0 around. You can scroll to any arbitrary fine X and Y value by using a 2006 write, two 2005 writes, and a 2006 write. Only the first 2005 write and the last 2006 write will have visible effects, so try to make the last 2006 write happen before hblank ends.


So to do a scroll to an arbitrary position during rendering...
* Write anything with the correct name table bits to 2006. All other bits are overwritten later.
* Write the Y coordinate to 2005. Three lowest bits of Coarse Y are overwritten later.
* Write anything with the correct fine X to 2005. All bits of Coarse X are overwritten later.
* Write Coarse X (X >> 3) | Coarse Y (Y and #$38, << 2) to 2006.

Also, here's my reformatted version of Loopy's document.

Code:
"N" = nametable, "X" = coarse X, "Y" = coarse Y, "y" = fine y, "d" = written data
           Fine Y
              Nametable Y,X
                Coarse Y
                     Coarse X
         
          .yyyNNYYYYYXXXXX

2000 write:
        t:....NN..........=d:......xx
2005 first write:
        t:...........XXXXX=d:xxxxx...
        x=d:.....xxx  (fine X)
2005 second write:
        t:......YYYYY.....=d:xxxxx...
        t:.yyy............=d:.....xxx
2006 first write:
        t:..yyNNYY........=d:..xxxxxx
        t:.y..............=0
2006 second write:
        t:........YYYXXXXX=d:xxxxxxxx
        v=t
scanline start (if background and sprites are enabled):
        v:.....N.....XXXXX=t:.....N.....XXXXX
frame start (line 0, ppu clock 304) (if background and sprites are enabled):
        v=t


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 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