lord_nes wrote:
2. wait 2 vblanks;
i know that you make "wait vblanks" when you wanna change frames.. but if it is only a frame.. what is the reason to wait vblanks?? newbie question but i am on learning...
The VBlank wait is not to "change frames". The frames will go by whether you want or not. To simplify: all frames are composed of 2 parts, the VBlank, followed by the actual screen that is rendered. The NES screen is rendered to the TV 60 times a second, whether you change the contents of it or not. If you don't change anything, the same image is drawn to the TV over and over.
The VBlank waits exist because we can't change the screen contents while the NES is rendering them to the TV. And the only times the NES is not rendering, is at VBlank, or when you have rendering turned off manually.
So, whenever we want to draw anything to the screen, we must wait for the VBlank to start, then draw all we want, inside the VBlank time. Then, when VBlank ends, the NES will render the image to the TV.
You can also turn the rendering off, in that case, the screen will go blank (with color 0 filling the whole screen) as long as it remains off, but you can write to the screen as much as you want, the only limit is how long your player/user will wait with a blank screen. But you'll hardly take so long to do anything.
So, in the steps I posted, the first 2 waits are there bacause the PPU needs some time to warm up and be ready for use, and 2 frames proved to be enough time for that. Then, with the screen off, you do what you need and draw what you want to the PPU. When everything is ready, you wait for VBlank just to not turn rendering on in the middle of a frame, so you wait for the proper time to turn it on.