Vol 2 Issue 7
About "Vertical Raster
by Erik of TEX
Hi to all freaks, that rightly think that the 68000 is not just there to be programmed in C (urgh!) or Pascal (eeeeek!) that would be done just as fast in assembler on an 8-bit machine.
Here I would like to desribe a small yet extremely simple routine that, however, enables you to use more than 16 colours on one line. Everything you need to understand this trick is a pocket calculator and some knowledge of the hardware of both the computer and the monitor... But first I have to say that the name "vertical raster interrupt" is in fact a load of nonsense. Raster interrupts are executed by the electron beam position within the monitor and this beam moves (like everybody knows, I hope) in a horizontal direction. Refer to Udo's article elsewhere in this issue of ST NEWS for more details about that! Our little program has nothing to do with interrupts whatsoever - in fact it shuts them off completely!
So we want our good old ST to switch the background colours several times while the monitor is setting up one line on the screen. In fact this is no problem at all, but this has to happen simultanously on each line, thus creating "standing" beams on the screen. So we need a routine that needs exactly as much time as the monitor needs to write one line. To determine the time that the routine might thus take up before it (and the screen line) starts from the beginning, one needs to know the following:
The monitor (when using 50 Hz vertical frequency) writes 625 lines in one 25th of a second (2 halfscreens). This results in a horizontal line frequency of 15625 Hz. So one line takes 1 / 15625 = 64 Ás. So far, so good. The 68000 processor in the ST operates on an 8 MHz clock frequency and that means that one clock cycle takes 1 / 8000000 = 125 ns. The time (number of clock cycles) that the program is allowed to use in one loop is, quite clearly, the time that is needed for one line devided by the time needed for one clockcycle: 64 Ás / 125 ns = 512 clock cycles !
Now we have to write a program that changes the background colour (or any colour) in 512 clock cycles and then starts right from the beginning. When you have a look at a machine language programming book, you can see there that, for example a MOVE.W #$xxxx,$xxxxxx (move immediate to absolute adress) needs 20 clockcycles and a JMP $xxxxxxx (jump to absolute adress) needs 12 clock cycles. To stay within the 512 clock cycles, we need to use the command MOVE.W #$xxxx,$xxxxxx 25 times and the JMP one time to start again from the beginning. In our case, we take some good matching colours for the source and the background colour register as target (e.g. MOVE.W #$700, $ff8240). Before we start, all interrupts have to be switched off, because an interruption of the program will of course jam up our 512 clock cycle sum. We also switch the machine to 50 Hz, so that the calculations we made also happen to match. On this website you'll find a source of the super-duper program called VERTRAST.S. A ready assembled program called VERTRAST.TOS is also included. You might wonder why not all the 25 colours that are set in the program are actually visible on the screen. That's because the electron beam needs a little time to get back to the beginning. During this time, it is switched to dark, so that a part of the colours is invisible. A much more funny effect is achievable when you let the routine run in 60 Hz line frequency (does not work on all monitors, sometimes they start doing weird things, ED). This can be done by MOVE.W #$0,$FF820A.
It is evident that the trick, like it functions now, hasn't got much practical use because the computer doesn't do much more than switching colours at the right time now. However, it is possible to add number loops or keyboard checks to the program (just don't forget the 512 clock cycles!). That way, it can also be left on another way than just pressing Reset. If you jump through this routine at each VBL (Vertical Blank Interrupt, look at Udo's article elsewhere in this issue of ST NEWS), only a part of the screen is supplied with the familiar vertical beams. That way, time is left for normal procedures like a useful main program. A method much like the one I described here is used in the "Spectrum 512" colour demo.
That's it folks, a lot of text around a little program. It is just nice to know what you can get from the hardware with help of a little assembler code, don't you think?
Erik from The Exceptions...
|This text was published in the Atari ST diskmag "ST News" and is used by kind permission of Richard Karsmakers. Source for this article: http://www.st-news.com|