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")
How to load a full background?
Moderator: Moderators
Re: How to load a full background?
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.
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.
Re: How to load a full background?
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.tales wrote:when I try to change my background screen in run time, the screen get's crazy, I don't undestand why...
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!).