Use these pages to get your images moving
By ALAN PLUME
AT the heart of the BBC Micro's graphics capability is a remarkable
device called a 6845 cathode ray tube controller (CRTC). This
device not only controls how the display memory is organised to
give a picture on your television or monitor, but is also constantly
refreshing the machine's RAM.
The 6845 has 18 registers, but this article is concerned with
only two of them, R12 and R13.
These registers are "write only" and hold a 14 bit
address which supplies the start address of the current display
memory.
In modes 0 to 6 this value is the start address of the screen
memory divided by eight. Thus in mode 4 the registers contain:
R12 (MSB) =( &5800 DIV 8) DIV 256
R13 (LSB) =( &5800 DIV 8) MOD 256
New values can be written to these registers by using the VDU
23 statement:
VDU 23;12,hibyte;0;0;0
VDU 23;13,lobyte;0;0;0
It doesn't take a lot of imagination to realise that writing
other values to these registers could generate useful effects.
Here are three major uses, and I'm sure that there are many
more:
• To allow fairly smooth animation of complex shapes.
• Fast sideways and up/down scrolling. Anyone who has played
Rocket Raid knows how effective sideways scrolling is.
• Displaying a micro slideshow with stored frames of text or
graphics on disc. While one frame is on display another can be
loaded into a spare section of memory and then switched in by
changing R12 and R13.
Obviously only modes 4 to 7 can be used for this, as the computer
doesn't have enough RAM to support two mode 1 screens.
This is how we use these techniques for animation.
The original drawing is made in the normal memory for the appropriate
mode.
While on display some pointers in the memory are altered and
the next frame is actually drawn in another section of memory.
The address of the top of the new memory is written to R12 and
R13 and the new frame seen. The old frame is deleted and the next
frame constructed. This is then switched in. The process can be
continued indefinitely.
Now let's see how all this is accomplished.
For this example mode 4 will be used. Normally the mode 4 screen
uses memory locations &5800 to &7FFF, so if we use another
page then that can be from &3000 to &57FF.
HIMEM must thus be established at &2FFF so that the program
workspace doesn't overwrite the second page.
We also need to be able to clear both graphics pages quickly
so we use a dedicated piece of assembler to do this. It's not
too elegant, but works fast enough. Either page can be cleared
by altering a single byte of the code.
Next we need to calculate the values of registers 12 and 13
of the 6845 to allow page changes. If we consider the area from
&5800 to be page 1 and that from &3000 to be page 2 then
we have:
R12 =(&5800 DIV 8) DIV 256 = 11
R13 =(&5800 DIV 8) MOD 256 = 0
R12 =(&3000 DIV 8) DIV 256 = 6
R13 =(&3000 DIV 8) MOD 256 = 0
When switching pages the operating system has to know what the
current high byte of the screen start is.
This value is stored in the VDU workspace at &34E. Thus
for page 2 we need to add:
?&34E=&30
and on switching back to page 1:
?&34E=&58
Now how do we tell the operating system that we want to draw
on page 2?
Locations &350 and &351 appear to contain the base address
that the plotting and printing routines use to place information
on the screen, so we also need:
Pagel ?&350=0:?&351=&58
Page2 ?&350=0:?&351=&30
All this poking around in memory is exactly what Acorn tell
you not to do, but if you want special effects you often have
to do this.
Program I is an example of this technique used to display a
wireframe cube rotating about two axes with perspective.
The program is written to allow you to put your own objects
in fairly easily by altering the DATA statements at lines 3000
and 3010.
The first set of data contains the number of points defining
the object and its x, y and z co-ordinates. The second data set
contains the number of lines and the linkages for these lines.
To illustrate this is a diagram of a three dimension diamond
shape and the associated data statements. (Note that the z-axis
is the axis coming out of the screen.)
3000 DATA 6, -500, 0, 500, -500, 0, -500, 500, 0, -500, 500,
0, 500, 0, 500, 0, 0, -500, 0
3010 DATA 12, 1, 2, 2, 3, 3, 4, 4, 1, 1, 5, 2, 5, 3, 5, 4, 5,
1, 6, 2, 6, 3, 6, 4, 6
The rotation procedure at lines 1500 to 1520 is also designed
to allow the user to alter the axes of rotation, and even the
angles of rotation. The parameters All to A33 are initialised
in PROCsetup. As an example, to rotate about the z-axis only:
1620 A11=C:A21=S:A31=0
1625 A12=-S:A22=C:A32=0
1630 A13=0:A23=0:A33=1
Figure
I