How to load a full background?

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

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

Re: How to load a full background?

Post by lidnariq »

On the NES, you can only write to the screen ("nametable") or tiles when
1- The screen isn't drawing because you turned it off
or 2- The screen isn't drawing because it's the time between when the PPU has finished drawing the previous screen and before it's started drawing the next one.

This is why the PPU can signal the CPU at end of each drawing period ("NMI")
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How to load a full background?

Post by tepples »

1 is called "forced blanking".
2 is called "vertical blanking" (vblank), and it lasts for about 2270 CPU cycles. You can't update the whole screen in one vblank; you have to either do it in stages or use forced blanking.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a full background?

Post by tokumaru »

tales wrote:when I try to change my background screen in run time, the screen get's crazy, I don't undestand why...
This happens because the NES has to read from the video memory (name tables, attribute tables, pattern tables, etc.) in order to send images to the TV (which it does 60 times per second, even if the picture doesn't change), and if you try to write to this memory at the same time as the NES is reading from it, you get these crazy effects.

To avoid these, you should only write to the video memory when the NES is not using it. Between frames, there's a short interval called VBlank (vertical blank), during which the NES doesn't use the video memory. Most games use this time to update the name/attribute tables (for scrolling), the sprites and so on. This period is quite short though, so there's no time to update an entire screen. For a full update, you have to turn rendering off (both sprites and background must be off) though PPU register $2001. When you're done updating, turn rendering back on (don't forget to set the scroll!).
Post Reply