Killer-Duck, on Sat Oct 16, 2010 3:21 PM, said:
Thank you! So when we turn on VBLANK we "turn off" the electron gun so it doesn't display anything while it repositions itself to the top-left corner(vertical blank), then we turn on the electron gun again when we want to draw to the screen?
Yes, exactly. Well, technically the three electron guns (one each for the R, G, and B phosphors) are still on, but during blanking they're set to a level that prevents the phosphors from being excited enough to light up. Of course, it's simpler to think of them as being "turned off."

But yes, VBLANK is turned on after the game screen's been drawn, and is kept on throughout what the "Stella Programmer's Guide" calls the "overscan" and "vertical blank." Then VBLANK is turned off again when it's time to start drawing the game screen on the next frame:
(1) Turn on VBLANK; draw the "overscan" lines.
(2) Turn on VSYNC; draw the vertical sync lines.
(3) Turn off VSYNC; draw the "vertical blank" lines.
(4) Turn off VBLANK; draw the game screen lines.
(5) Loop back to (1) and keep repeating.
The number of lines drawn is somewhat flexible, although you should keep the total number constant, and the number of lines between vertical syncs should also be constant from frame to frame. Also, PAL requires an even number of lines for the colors to display properly.
The Atari 2600's TV signal isn't as complicated as a normal TV signal, because normal TV signals have 4 types of lines, but the 2600 has only 3 types of lines:
TV signal:
- equalizing lines (pre-equalizing and post-equalizing)
- vertical sync lines
- normal vertical blanking lines
- active lines
Atari 2600:
- vertical sync lines
- vertical blanking lines
- active lines
The equalizing lines (or really half-lines) are vertical blank lines, but have two wide equalizing pulses per line (or one pulse per half-line). The Atari doesn't have equalizing lines; it just uses normal blanking lines.
In a normal NTSC/60 signal, there are
3 pre-equalizing lines (or 6 pre-equalizing pulses)
3 vertical sync lines
3 post-equalizing lines (or 6 post-equalizing pulses)
12 normal vertical blanking lines
241.3 active lines
These numbers are somewhat iffy, because some documents show only 9 normal blanking lines after the post-equalizing pulses. However, closed-captioning data is sent on line 21, which implies that there should be 12 normal blanking lines.
If we dispense with the extra half-line (since Atari 2600 screens normally aren't interlaced), we can draw the screen as follows:
3 vertical blanking lines
3 vertical sync lines
15 vertical blanking lines
241 active lines
However, most TV sets deliberately overscan the picture to prevent any blanking from being visible at the edges of the screen, whereas we want to be sure that everything on the game screen is visible. Therefore the Atari deliberately increases the length of the horizontal blanking (which is controlled automatically by the TIA chip), and the programmer deliberately increases the length of the vertical blanking, such that all of the game screen can be seen on most every TV, with a black border (the blanking) being visible around the four sides of the game screen. The following numbers are given by the "Stella Programmer's Guide":
30 vertical blanking lines (the "overscan")
3 vertical sync lines
37 vertical blanking lines (the "vertical blank")
192 active lines
Since the kernel is written in the form of a loop, we can enter the loop at any point that's convenient. Some programmers start the loop at the vertical sync lines, since those lines are at the top of the screen (or really between the bottom and top, since they trigger-- and occur during-- the vertical flyback of the electron guns). I prefer to start the loop at the so-called "overscan" lines, even though they're at the bottom of the screen, because it makes more sense to me that way, since that's when we turn on VBLANK, and we need to leave VBLANK turned on for the VSYNC lines and the so-called "vertical blank" lines. But it's just a matter of personal preference. For example, you could start your loop at the beginning of the active lines, and place the code for the overscan, VSYNC, and vertical blank lines at the end of your loop, then JMP back to the top to resume. However, the loop that draws the active lines generally needs to be kept as tight as possible, to maximize the amount of time you have for setting up the graphics on each line, so it's generally better to let the program just fall through from the vertical blank lines to the active lines without having to do a JMP to go from one to the other.
Since you're a beginner, I'll also point out that you need to learn about using the timer, because it's essential for letting you perform your between-frame game-keeping procedures (checking for and processing any collisions, reading the game controllers and console switches, updating the score, etc.). These procedures can take varying amounts of time, depending on which branches must be taken, so you want to set the timer at the beginning of the "overscan," then do your game-keeping stuff. When you're done with the game-keeping stuff, you fall into a little loop that checks the timer to wait until it runs out. Then you do the vertical sync lines, set the timer again for the "vertical blank," and do additional game-keeping stuff as needed. Then you fall into another little loop that checks the timer to wait until it runs out, after which you can turn off VBLANK and start drawing the active lines (game screen).
Michael