Unwanted scrolling after writing to background

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Posts: 9681
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Unwanted scrolling after writing to background

Post by lidnariq » Sat Jul 21, 2018 12:39 pm

mitch3a wrote:Is this just expected behavior?
You're kinda getting into the esoterica of how scrolling works on the NES. nesdevwiki:PPU scrolling.

But ... no, simply disabling then reenabling rendering wouldn't obviously cause a jump of a single scanline. Re-enabling rendering in the middle of a field should cause it to randomly start rendering with a random weird scroll, but I'd be surprised if it was consistently one scanline.

User avatar
Posts: 11861
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Unwanted scrolling after writing to background

Post by tokumaru » Sat Jul 21, 2018 1:21 pm

To avoid screen jumps of any kind, the recommendation is to only turn rendering on from the vblank handler, after having set the scroll, so that the first rendered frame starts correctly from the top of the screen and with the correct scroll settings.

If you enable rendering whenever, you'll most likely get a partial picture offset from the top of the screen. Turning rendering of should also be done during vblank, so you don't get a frame with the picture particularly cut off.

The approach many people use is to have the main code simply signal the intent to turn rendering on and off, and the NMI handler is responsible for committing those changes.

User avatar
Posts: 50
Joined: Mon Jan 23, 2017 8:08 pm
Location: Boston, MA

Re: Unwanted scrolling after writing to background

Post by mitch3a » Mon Jul 23, 2018 6:00 am

Thanks for all the help. I DEFINITELY plan on taking a lot of this feedback (especially rainwarrior's post) and building a better framework for my next game. In this case, it works and I don't want to do any major rewriting cos I want to move on, but I'll probably put a big disclaimer in the code and the readme so that others don't fall into the same issues.

Post Reply