Screen moving involuntary

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
Pennywise
Posts: 71
Joined: Tue Jul 14, 2009 11:04 am

Screen moving involuntary

Post by Pennywise »

ImageImageImage

I'm having an issue with the screen moving down when calling a menu in certain areas. I'm not entirely sure why this is happening, but I think it has something to do with the PPU register $2002. Through tracing the code, I've noticed this glitch happens when $2002 gets sets to #$00 and I don't know enough about the NES PPU to understand what exactly is happening. Would anyone have an idea of what the problem is?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Screen moving involuntary

Post by Dwedit »

Whenever you set the PPU address, you are also scrolling at the same time, since PPU address and PPU scroll use the same internal latches.
So always set scroll AFTER you do your PPU memory writes, and if you do PPU memory writes, always set scroll.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Screen moving involuntary

Post by tokumaru »

$2002 is a read-only register, so it doesn't really "get set" to anything. Like Dwedit said, any unintentional screen movement is most likely due to corruption of the scroll registers.

Scrolling on the NES is achieved via indirect manipulation of the VRAM addresses register (via $2000 and $2005) prior to the beginning of rendering, so when you change the VRAM addresses register directly (via $2006 and $2007) you're effectively messing up the scroll. ALWAYS set the scroll to the desired values once you're done with all PPU updates in your NMI handler, so that the new frame can begin rendering with the proper scroll values.

To properly set the scroll during vblank you need 3 PPU writes: one write to $2000 (lower 2 bits select the name table) and two writes to $2005 (first sets the X scroll, second sets the Y scroll).
Post Reply