ABOUT "VERTICAL RASTER INTERRUPTS" by Erik from 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 a 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 rasterinterrupt"
is in fact a load of non-sense. Raster interrupts are executed by
the electronbeamposition 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 out good old ST to switch the background colors
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
simultaenously 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 linefrequency 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 color
(or any color) 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 colors for the source
and, the background color 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 the disk you'll
find a source of the super-duper program called VERTRAST.S,
contained in the folder PROGRAMS. A ready assembled programs
called VERTRAST.TOS is also included.
You might wonder why not all the 25 colors 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
colors 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 colors 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" color 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?
Goodbye,
ERIK from THE EXCEPTIONS ...
Disclaimer
The text of the articles is identical to the originals like they appeared
in old ST NEWS issues. Please take into consideration that the author(s)
was (were) a lot younger and less responsible back then. So bad jokes,
bad English, youthful arrogance, insults, bravura, over-crediting and
tastelessness should be taken with at least a grain of salt. Any contact
and/or payment information, as well as deadlines/release dates of any
kind should be regarded as outdated. Due to the fact that these pages are
not actually contained in an Atari executable here, references to scroll
texts, featured demo screens and hidden articles may also be irrelevant.