AFTER THE GAMES
from ZX Computing, October/November 1985

Regular contributor and sage, John Wase, muses on some practical ways of
answering the perennial question, "But what does it DO?"


All right, I know that there are some superb Spectrum games to play, and
it's even more fun hacking into them to find the infinite lives POKE. But
just POKEing games can be like tinkering with a car to see how it works; I
prefer driving it to get somewhere. After all, the Spectrum is more than
just a games machine, it is an extremely well designed and powerful 8-bit
micro, with bags of memory, although, regrettably, the famous rubber
buttons have resulted in a certain lack of credibility. Nonetheless, people
out there are actually applying it to everyday jobs, so I set out to
discover what some of my friends were using it for. The uses ranged from
the prosaic to the exotic. Here's a couple ...

Number crunching
Chemical engineers often have to solve complicated algebraic equations
which do not have analytical solutions. Our Bill McManamey wrote a simple
program (Fig.1) involving a search method of solution to do this.

Decreasing increments
For equations of the type f(x)=0, the solution is obtained by putting f(x)
equal to d and changing x until d is acceptably near to zero. At first,
relatively large increments of x are used, then, nearer the answer, the
increment is reduced. In other words, you are asking the computer to guess
the answer, and then see how good the guess is so that it can make a better
one. There are sufficient REMarks to make most of the program self
explanatory, but, as the diagrams show (Fig.2), adding increments of a
can cause d to change sign as zero is crossed; either from positive to
negative, or vice versa. Line 80 enables the program to deal with d either
increasing or decreasing as x increases. As it is a comparatively
straightforward program, it stops as soon as it has a solution. If more
solutions are suspected (Fig.3) then it has to be restarted.

If you are not sure about it, just think of the equation 2x^0.8 - LN(3x) - 1.7 = 0.
Type in the listing, RUN it and ENTER the sample values for x, a, b and
the equation, provided in the REM statement in line 600. Sometimes it will
take a bit of time, but in this case it will take only four seconds to come
up with the solution x = 2.0107. Try doing that by hand!

----------

This method is described in Jenson, V.G. & Jeffreys, G.V., "Mathematical
Methods in Chemical Engineering", 2nd edition, Academic Press, London,
1977, p.406. It is for finding x in equations of the type f(x)=0. The
solution is obtained by putting f(x)=d and changing x until d is acceptably
near to 0. At first, relatively large increments of x are used, then,
nearer the answer, the increment is reduced. In some cases a program using
linear interpolation in the interval a (or Newton's method) can be quicker;
this is discussed in Jenson & Jeffreys.


Storing shapes
The next example, by Susan Laflin of our Computer Studies Department (of
Birmingham University) is much more unusual; moreover the principles upon
which it is based are of very wide application. Using her program, she can
INPUT a two-dimensional shape, DRAW it on the screen, then smooth the data
as required before SAVEing on microdrive. Data for many shapes can
therefore be stored.

Shaping up the program
This program (Fig.4) is one of a suite of three (the others will be
mentioned later) and is written in BASIC. This is slow to run, but then
one operation of the tracer with which it is used is even slower, so that
is of little consequence. Moreover, it allows the user to alter the SAVE
routines without too much difficulty.

The hardware
Susan finds an ordinary rubber-keyed Spectrum quite satisfactory. Profiles
are drawn on paper and the data digitised. Whilst, in theory, profiles
could be drawn on graph paper, allowing one to read off the coordinates and
type them in, in practice this is slow and tedious, and accuracy rapidly
diminishes as one becomes tired. Of the three digitisers available, the
RD-Tracer, the Grafpad and the Touchmaster, the latter two use a stylus to
indicate the position and cost around  150 for A4 versions. The A4
RD-Tracer is only around 60, (70 for an A3 version), so the A4 RD-Tracer
was chosen. Whilst RD Laboratories are unfortunately no longer with us, the
tracer is still sold by Kane-May and advertised by most journals.

It is convenient to attach the tracer to a small cork notice board by its
clamp; for each INPUT session a profile is pinned to the board. The area
used is about A4 in size. The paper is always attached to roughly the same
place, but this is never, of course, exactly the same, so the first section
of the program reads in the four corners of the profile area and calculates
the scaling factors to map the rectangle onto the screen used by the
Spectrum. This is done once for each session.

In goes the profile
This part of the program starts at LINE 180. The cross-wires are placed
over each point to be INPUT and any letter on the keyboard is pressed. One
hand is used to move the tracer whilst the other is on the keyboard. As the
profile is INPUT, values are stored in the array c and a copy is displayed
on the screen. INPUT is stopped automatically when 200 points have been
entered, and can be stopped before this by pressing a number instead of a
letter.

The RD-Tracer inputs information via port 31; the software provided used
an average of five readings to calculate the x and y coordinates. She
tested this by INPUTting the same pair of coordinates a dozen times; the
result was a large black patch displayed on the screen. This, she deduced,
was the correct value, plus an error of two or three pixel positions in any
direction. Changing the program to take the average of twenty readings
reduced the error to plus or minus one pixel position, but this still left
a three by three square instead of a single point. Increasing the number of
readings still further improved the accuracy but slowed down the rate of
recording. For instance, taking one hundred readings reduced the error to
half a pixel position, (a two by two square, but increased the time to an
intolerably slow five seconds per reading. She finally settled on fifty
readings which gave similar accuracy (two by two pixel square maximum
error), but which took only two seconds per reading. This revised software
is incorporated in the subroutine starting at LINE 1000.

Smooth routine
Once sufficient data has been INPUT, the routine staring at LINE 300 is
used to smooth the data by taking a five point moving average. The result
is displayed on the screen and the user is asked if it is satisfactory; if
not, then the choices of smoothing again or of re-INPUTting the data are
offered. You will have no doubt noticed that although I mentioned earlier
that 200 points were INPUT, the routine appears to use more. The first
point is input three times and the last two to allow the smoothing routine
to work properly. Duplicate points are subsequently discarded.

For SAVEing data, a choice of cassette, microdrive or wafadrive was
available. Most profiles require between a hundred and two hundred
coordinate pairs and for this purpose cassette was unacceptably slow. The
Wafadrive has potentially a larger capacity than microdrive, but uses the
same port on the edge connector as the RD-Tracer. The routine is therefore
set up for microdrive. Each microdrive cartridge has room for about 40
complete profiles and about ten times as many fitted curves (see later).

The SAVE routine is located at LINE 500 onwards, and could easily be
changed to accommodate, for instance, a floppy disc system provided that it
is compatible with the RD-Tracer.

Applications
Susan's program is used, surprisingly, in an archaeological application.
Pottery profiles are read in, smoothed and stored for later comparisons.
Later programs deal with the fitting of a B-Spline curve to the data; (thus
many profiles can be stored as relatively small amounts of data), and then
comparison of the profiles using the parameters of the fitted curves. Thus
pieces of pottery which match are readily identified, as are similarites in
overall shapes. However, I am sure that this is not the only application
for this principle. What could you use it for?
