ZX81 DRAW
by David King
from Your Computer, Dec. 1983, pages 143 & 144

David King illustrates a draw and undraw routine for the ZX-81.  It is
similar to that provided on the Spectrum.

WHEN THE ZX-80 first came out in 1980 with its 4K Basic ROM, Sinclair announced
it would soon be producing an optional 8K drop-in replacement chip, which would
give moving graphics, trig functions, all keywords direct from the keyboard, 
plus inverse graphics, and 8 1/2 digit floating arithmetic. However it also 
would have Read, Restore and Data, plus Draw and Undraw, and a number of other 
features.

Very soon after Sinclair launched the new 8K ROM, it decided to delay introduc-
tion of these features and design a printer. The new printer routines neces-
sitated the space the extra facilities took up, and so when the 8K ROM finally 
came out Draw and Undraw were not there. ln addition, Sinclair designed a comp-
letely new computer to go around the 8K ROM,  which it called the ZX-81. It had
a steady display which was sadly lacking on the ZX-80 with 8K ROM. 

I decided it would not be all that difficult to give the ZX-81 Draw and Undraw 
facilities like those on the Spectrum. Useful routines which I might want to 
include in Basic programs l find easiest to place in Rem statements. This Draw 
routine draws as straight a line as possible in pixels from the last point 
plotted to a relative position indicated by the Vectors Poked into addresses 
16507 and 16508. There are onlv two USR addresses to remember, one for Draw and
one for Undraw, just as there are Plot and Unplot.

Notice that the numbers in a Draw statement can be negative, although those in 
a Plot statement cannot. lf x (16507) is negative the finishing place will be x
pixels to the left, instead of to the right. If it is zero the line will be 
vertical. If y (16508) is negative the finishing place will be y pixels down, 
instead of up. If y is zero the line will be horizontal - see figure 4.

One thing to ensure is that x and y are not both zero, this causes the Draw 
routine to get a bit muddled, however Break brings it out of its misery.

Try the short programs for a demonstration of the ease with which graphics
can be created. 

If you understand vector drawing, ignore this section. The statement Draw to
draw a straight line on the Spectrum takes the form:  DRAW x,y

Using this program you have to Poke x and y into memory locations, in addition
the Rand USR 16514 command does not set the Random seed. You could equally well
use Print USR 16514 or Let A=USR 16514, and neither a number would be printed 
nor a value assigned to A; control is passed to the next line.

The starting place of the line is where the last Plot or Draw statement left 
off -- this is called the Plot position; New resets it to the bottom left-hand
corner (0,0) - and the finishing place is x pixels to the right of that and y 
pixels up. Notice that Draw on its own determines the length and direction of 
the line, but not its starting point.

You can experiment with a few Plot and Draw commands - see figures 7 and 8.

Figures 9 and l0 make use of the interference patterns between the  pixels of 
lines to create interesting patterns.

Figure 11 draws a number of random direction lines, each leaving off from where
the last ended.

As l mentioned earlier, it ia also possible to Undraw as well as Draw lines.
To Undraw lines use Rand USR 16520. The program in figure 12 illustrates this.

