                          Display



               Richard Taylor points the way

            to better graphics display commands

               for the 16K and 48K Spectrum



The Spectrum has a distinct lack of commands to produce

graphic displays. Its PLOT, DRAW and CIRCLE commands are

very rudimentary and do nothing to exploit the full graphic

potential of this high resolution machine. To produce 

displays worthy of this machine's graphic capabilities

requires a complex and confusing assortment of the vague

statements that Sinclair Basic does possess. Other machines

often have commands to draw ellipses, rectangles and

triangles and the additional facility to paint specific

areas of the screen in different colours. In order to

partially remedy this fundamental problem, I present a

machine-code program for both the 16K and 48K machines.

  [At this point, the instructions followed for entering,

checking and saving the code, none of which is relevant

if you already have the TZX - which you should if you're

reading this. We return to the text at:]

  To load the program back into the machine use:

  For 48K owners

        CLEAR 64623: LOAD ""CODE

  For 16K owners

        CLEAR 31855: LOAD ""CODE

[which, reasonably, assumes that you only entered the code

for your own machine. The TZX contains both; take care to

load the correct one.]

  The commands are put in REM statements. Each REM state-

ment which contains the new commands must be preceded by a

        RANDOMIZE USR 64624

on 48K machines and

        RANDOMIZE USR 31856

on 16K machines. The REM statement must be the next command

after this machine-code call instruction, be it the next

statement on the same line or the first statement on the

following line. If this rule is neglected then the computer

will respond with error C - "Nonsense in BASIC".

  Whether you type the commands in upper or lower case or

a combination of the two, the new statements will be recog-

nised by the computer. If any sort of error occurs as a

result of incorrect syntax, it will be interpreted by the

computer as an error C.

  In normal Basic commands which print onto the display,

it is possible to put colour parameters just after the

keyword. This is not possible with the new commands, so you

must use a slightly different method. If you intend to use

the universal colours which have been set up using the INK,

PAPER, FLASH, BRIGHT, OVER and INVERSE commands as solitary

statements, then you must make the first command in the REM

statement a TEMPS. This merely indicates to the computer

that you wish to use the universal colours in all succeed-

ing commands in that REM statement.

  Conversely, if you wish to set up your own temporary

colours then you must place a dummy PRINT statement as the

statement preceding the RANDOMIZE USR instruction. This

PRINT statement contains the colour information. For

example:

        PRINT INK 3; PAPER 7;

will set the colours to magenta ink on yellow paper. The

PRINT statement does not actually affect the contents of

the screen, only the temporary colours. When using this

method, no TEMPS command is required as you are not using

the universal colours.

  There now follows a description of each of the six

commands:

  MOVE x,y: This command simply moves the plot position to

x,y. As Sinclair Basic stands, it has no facility to do

this unless you use

        PLOT INVERSE 1; OVER 1; INK 8; PAPER 8;

        BRIGHT 8; FLASH 8;x,y

but this is a little bit complicated. The command is espe-

cially useful for moving the plot position prior to using a

paint command.

  The two parameters, x and y, can be entered in one of a

couple of ways. Either you can put the number in directly -

i.e.

        MOVE 128,88

or you can use a variable name - i.e.

        MOVE a,b

The only stipulation when using variables is that it must

be a single letter simple numeric variable. If you use a

variable that is not defined then the computer will respond

with the usual error 2 - "Variable not found".

  The above notes apply to any of the other new commands

which have parameters. Please note that you are not allowed

to do any mathematics in the parameters, e.g.

        MOVE a-1,b-3

Instead you could do something like

        LET x=a-1: LET y=b-3

and then

        MOVE x,y

  LINE x,y or LINE (x1,y1)-(x2,y2): The LINE command has

two different possible formats. The first format has the

form

        LINE x,y

where x and y are the co-ordinates of a point on the

screen. The command draws a line from the last position

plotted to the point supplied. The advantage of this is

that it uses real screen points rather than the relative

displacements used on the Sinclair DRAW command. This

method is often more easy to use.

  The colour of the line is determined by a dummy PRINT

statement preceding the RANDOMIZE USR command if you are

using temporary colours or by a preceding TEMPS instruction

if you are using the universal colours.

  The second form of the command is slightly different and

is similar to the line command found on micro-computers

running Microsoft Basic. Its form is

        LINE (x1,y1)-(x2,y2)

It draws a line from the point x1,y1 to the point x2,y2.

This has the same effect as the rather more cumbersome

        MOVE x1,y1/LINE x2,y2

  BOX x,y: This command draws a rectangle on screen at the

current position with a length of x and a height of y. The

last plotted position is used as the bottom left hand

corner of the rectangle.

  Again, the colour of the box is determined in a similar

way to that in the previous command, LINE.

  CIRCLE x,y: Unlike the normal CIRCLE command, this one

allows you to draw ellipses as well as normal circles. The

circle's centre is determined by the last plotted position.

The first of the two parameters, x, is the radius of the

circle while the second parameter gives the height-width

ratio of the circle. This must be in the range of 1 to 255,

10 being the ratio for a normal circle.

  PAINT: This command allows you to paint a particular

area of the screen in a certain colour. The command paints

from the last plotted position in all directions until it

reaches an ink border. It is important that the start

position is not a point which has been plotted to an ink

colour - hence the need for a MOVE command - otherwise the

computer will think that that is an ink border and the

painting will not go as you would expect it to go. The

routine will not paint behind objects which are in the

start position's "shadow"; see figure 2.



  +--------------------------+

  |#################Unpainted|

  |#################area##|##|

  |#######+----------+    |  |

  |###o###|          |    v  |

  |###^###|          |       |

  |###|###+----------+       |

  |#Start####################|

  |#position#################|

  +--------------------------+

  Figure 2.



It is sometimes necessary to start from a couple of pouits

to completely paint an irregular area. The command will,

however, properly paint any rectangle where-ever the start

position is, as long as it is inside the rectangle's boun-

daries.

  WCLS a,b,c,d: This command allows you to clear part of

the screen, while leaving the remainder intact. This is

often a useful facility when you are using different parts

of the screen for different purposes. The parameters a and

b describe the column and line positions respectively of

the top left hand corner of the area to be cleared.

  Parameter c describes how many columns are to be cleared

while the final parameter, d, describes how many lines are

to be cleared. As you may have noticed, these line and

column numbers are given the opposite way around to the way

in which they are given for the PRINT AT instruction, which

has the line number first, followed by the column number.

The screen area cleared is described in a diagrammatic form

in figure 3.



  +--------------------------+

  |\_   -------- c ------->  |

  |  \_                      |

  | |  \_                    |

  | |                        |

  | d         Area           |

  | |         cleared        |

  | v                        |

  |                          |

  +--------------------------+

  Figure 3.



The colour of the cleared area is described in the normal

fashion for the new commands. Please note, however, when

using the TEMPS command the area is cleared with

        PAPER 8; FLASH 8; BRIGHT 8;

so that only the ink colour is actually altered. This

situation can be remedied by using an empty dummy print

statement instead of a TEMPS command - i.e.

        PRINT;

  Listing 4 to 7 give example uses of the new commands and

serve to clear up any misunderstandings you might have

concerning the syntax. [The magazine versions worked only

on a 48K machine, and had to be modified for the 16K; the

ones on the TZX adapt themselves to RAMTOP.]