Why to I need to tell the PPU not to scroll?

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
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Why to I need to tell the PPU not to scroll?

Post by lazerbeat »

I am working on a little project where I enter text on a screen kind of like a high score entry. I am storing the letters as a variable (will use astring once I get it working) then updated the background to show what is displayed in the variable in a particular location.

Code: Select all

  	LDA #$20                ; set to beginning of first nametable
    	STA $2006
    	LDA #$e1
    	STA $2006
        LDA tempval
        STA $2007
This was causing a glitch where the screen would display off center. I eventually fixed is by using
LDA #00
STA $2005
LDA #00
STA $2005
Other than the above there isn't any scrolling at all involved in the code and I never write to $2005. So our of curiosity, why do I need to tell the PPU not to scroll even though I am not scrolling during the code?



at the end of the NMI. So the question is, why do I need to tell the PPU not to scroll at the end of the NMI even
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Why to I need to tell the PPU not to scroll?

Post by thefox »

$2006 writes also modify the scrolling, so you need to restore it at the end of you VBlank/NMI handler.

In addition to $2005 writes, you should also have a $2000 write at the end to completely set the scroll. Otherwise you might run into problems later.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Why to I need to tell the PPU not to scroll?

Post by tokumaru »

When you write to VRAM, the PPU has to tell an external memory chip what address it needs to write to. When rendering the picture, the PPU also has to tell an external chip what address it needs to read from. To save costs, the PPU uses the same address register in both of these cases. If you use $2006/$2007 to access VRAM, you're modifying this address register, so when the picture starts rendering, it will start roughly from the name table position you modified last (it's actually a bit more complicated than this, specially if you accessed things other than name tables), unless you reset the scroll and, consequently, the address register, to the actual position where you want rendering to start from.
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: Why to I need to tell the PPU not to scroll? (SOLVED)

Post by lazerbeat »

Thanks very much!
Post Reply