Jittering with horizontal scrolling on vertical nametables

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
team_disposable
Posts: 121
Joined: Sat Oct 15, 2016 8:52 am

Jittering with horizontal scrolling on vertical nametables

Post by team_disposable »

I've managed to get horizontal scrolling with vertical nametables very nearly working - I'm updating columns to the nametable during vblank, and it is displaying them fine, but it seems like the nametable jitters up by a single pixel every time I update a column.

Is there any obvious reason for this? Am I setting the PPU up incorrectly or something? I set the vertical scroll to 0 before updating the nametable every frame.

Here's the relevant code (in C), this all happens just after the NMI flag is switched to 1:

Code: Select all

	OAM_ADDRESS = 0;
	OAM_DMA = 2;
	PPU_CTRL = 0x94;	
	PPU_MASK = 0x1e;
	SCROLL = Horiz_scroll;	
	SCROLL = 0;
	if(PPU_BufferCounter > 0) {
				PPU_BufferCounter = 0;
				PPU_ADDRESS = 0x20;
				PPU_ADDRESS = 0x00 + (X_CurrentColumnCounter * 4) + X_CurrentSubColumnCounter;
			
				for(index = 0;index < 30; ++index){
					
					PPU_DATA = PPU_Buffer[index];
					
				}
				
				
				
			}
Let me know if I'm making some kind of rookie mistake.
russellsprouts
Posts: 53
Joined: Sun Jan 31, 2016 9:55 pm

Re: Jittering with horizontal scrolling on vertical nametabl

Post by russellsprouts »

I set the vertical scroll to 0 before updating the nametable every frame.
Writing data to the PPU will modify the scroll registers. In general, you should write the scroll AFTER performing PPU updates.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Jittering with horizontal scrolling on vertical nametabl

Post by tokumaru »

team_disposable wrote:I set the vertical scroll to 0 before updating the nametable every frame.
That's not necessary. Setting the scroll AFTER the updates is extremely necessary, though.

One thing that can cause this kind of jitter is if your updates are taking too long to finish, so you might end up enabling rendering after the frame has already started, causing the picture to be displayed below where it normally would for that frame. To test if this is your problem, you can try updating less tiles and see if the problem persists.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Jittering with horizontal scrolling on vertical nametabl

Post by rainwarrior »

Since the NMI timing is so limited, you may find it difficult to write something in C that can update enough of the PPU data before the screen starts rendering.

Depends on how much, really, but just a tip that you might need to write the NMI handler in assembly directly, or use a ready made one like shiru's.
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Jittering with horizontal scrolling on vertical nametabl

Post by koitsu »

Hope you know assembly. ;)
team_disposable
Posts: 121
Joined: Sat Oct 15, 2016 8:52 am

Re: Jittering with horizontal scrolling on vertical nametabl

Post by team_disposable »

Yep. moving writing to the scroll register fixed it. I can't believe it was so simple! Thanks everyone.

The final code was:

Code: Select all

   OAM_ADDRESS = 0;
   OAM_DMA = 2;
   PPU_CTRL = 0x94;   
   PPU_MASK = 0x1e;
   if(PPU_BufferCounter > 0) {
            PPU_BufferCounter = 0;
            PPU_ADDRESS = 0x20;
            PPU_ADDRESS = 0x00 + (X_CurrentColumnCounter * 4) + X_CurrentSubColumnCounter;
         
            for(index = 0;index < 30; ++index){
               
               PPU_DATA = PPU_Buffer[index];
               
            }
            
            
            
         }
   SCROLL = Horiz_scroll;   
   SCROLL = 0;
Post Reply