Page 1 of 1

Jittering with horizontal scrolling on vertical nametables

Posted: Tue Dec 06, 2016 5:56 pm
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.

Re: Jittering with horizontal scrolling on vertical nametabl

Posted: Tue Dec 06, 2016 6:19 pm
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.

Re: Jittering with horizontal scrolling on vertical nametabl

Posted: Tue Dec 06, 2016 7:10 pm
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.

Re: Jittering with horizontal scrolling on vertical nametabl

Posted: Tue Dec 06, 2016 8:22 pm
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.

Re: Jittering with horizontal scrolling on vertical nametabl

Posted: Tue Dec 06, 2016 9:33 pm
by koitsu
Hope you know assembly. ;)

Re: Jittering with horizontal scrolling on vertical nametabl

Posted: Wed Dec 07, 2016 12:58 am
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;