Beamhacking: Video Timing

Now that we know how to get in sync and count along with the Model 3 video beam we'll need some overall video timing details.

There are two parts to the story: the full extent of the beam's job and unit conversions. Normally one thinks of the TRS-80 screen as being 64 characters wide and 16 rows tall. But when the beam finishes drawing a line it can't get back to the start instantaneously. The time it takes to get back to the start of a line is called the horizontal blank which is equal to the time required to draw 16 characters. And as you might guess, the beam takes time to get from the bottom to the top of the screen. That's the vertical blank and is the same as the time required to draw 6 rows of characters. In a way the screen is really 80 characters wide and 22 rows tall but only 64 by 16 are visible due to timing considerations.

Characters themselves are composed of dots. 12 lines of 8 dots across, as a matter of fact. Thus we're more likely to say that the visible portion of the screen is 64 * 8 or 512 dots across by 16 * 12 or 192 lines tall. The horizontal blank is 128 dots and the vertical blank is 72 lines.

This is all well and fine for the video hardware you say. How does this relate to the Z-80 processor itself? You know, the one we're trying to sync up with the beam. OK, no need to get pushy. On the Model 3 one Z-80 T-state is the same as 5 dots. A complete line of video including horizontal blank is 640 dots or 128 T-states. The visible portion of the screen gets drawn in 192 * 128 T-states (24,576) and the vertical blank is 9,216 T-states (72 * 128). Here's a diagram that puts it all together:

Model 3 Video Timing

It should be noted that these figures are all for Model 3 in its North American 60 Hz configuration. There are jumpers to set the display for 50Hz but I have not investigated how that affects the timing. Since the Model 3 has a built-in monitor I'd guess the extra display time is added to the vertical blank.

I've only written a few beam synced programs for the Model 1 — the lack of an automatic way to get in beam sync makes them less attractive. I do have the detailed timings, though. No fancy diagrams, just the base units.

While the Model 1 timings reflect its slower CPU speed, I find it interesting that its percentage of time in horizontal blank is much greater than the Model 3's — 44% vs. 25%. The Model 1 has a modified TV for a display but its video timing parameters seem rather out of line with regards to NTSC. Nonetheless, I can confirm that those parameters are correct.

When it comes down to programming the two most important factors are 128 T-states per line and 72 lines of vertical blank. Modifying graphics on the fly means you're working to a 128 T-state beat. The vertical blank is free time when you're not busy with banging on the screen. The perfect time to do all those calculations to move things about. You can take extra time, of course, but now you're effectively reducing your vertical resolution.

Coming up we'll talk about the good and bad of what happens when the Z-80 and the video circuitry want to access video memory at the same time.

George Phillips, August 5, 2009, george -at-