they'll ask, "machine code will deal
with all that and more" - but no one
likes a smart-arse, and machine code
has a reputation for sending beginners
gibbering and whimpering back to the
comfort of Basic. It's not that it's
amazingly difficult - in fact, in some
ways it's extremely simple - but it's
not an easy subject to learn from books
and early attempts at understanding
often prove so off-putting that the whole
idea gets quietly shelved in the 'forget
There has to be an easier way, and there is - in fact there are several. One way out is to learn Forth - definitely the year's most fashionable language for home computer users - and later on in this article we'll be taking a look at the Abersoft Forth compiler for the Spectrum. Another alternative is to use compiled Basic instead of the built-in interpreted version and, as Softek has released new versions of its Basic compiler, it seems only right and proper to give these the once-over.
So, introductory waffle over, it's time now to move towards the highly laudable aim of making life easy for the user. Let's get down to some specifics ...
Of course, nothing is actually that simple. The manual for the Softek compilers claims that compiled programs will run 'up to' 200 times faster (in some circumstances even 500 faster is possible), but the important point to note is that 'up to' is apostrophised (if there is such a word). In practice you will find that the compiled code is rarely that efficient and your programs are unlikely to be any more than 10 times faster. But let's not be ungrateful, a speed increase of 1000 percent is certainly not to be sneezed at!
All Spectrum owners will have noticed
that their implementation of, say, Missile Command just doesn't have the
speed or the smooth, pixel-by-pixel
movement that a true arcade game
devotee has come to expect from a program. In fact, Basic is just about okay if
the display is kept simple - PRINT AT
is actually, relatively, quite fast if the
number of objects that need to be moved
is kept small - but once the number of
moving objects reaches four or five, the
movement slows down dramatically.|
Sinclair's highly individualistic - some might say bloody-minded - method of laying out the display file ensures that direct POKEs to the screen are more trouble than they're worth, so something different is needed. Another drawback is that anything that is moved a character square at a time is going to
look jerky when compared with the
single pixel steps achieved in professional programs.|
WHICH WAY OUTA recent innovation is the idea of a 'games design' package, Melbourne House has just marketed one of these, as has Quicksilva. But these are necessarily limited - the Quicksilva package, for example, while allowing the designer a fair amount of freedom in manipulation of sprites, insists that the resultant game is of one of four types, described as Space Invader, Asteroids, Scramble or Berserk. If you want a completely new format then, tough, you're out on your own, buster.
Pundits will pontificate patronisingly ... "Where's the problem?"
The other point to note is that there is
a trade-off of speed against ease of use
- the Softek 'FP' floating-point compiler offers many more features to the
user: it will handle almost all Basic commands and functions, including strings
and arrays (single dimension only) and
a full range of 'real' numbers. The 'IS'
integer compiler has many more restrictions on its use - no arrays, fewer
commands and integer numbers only, in the
range -32767 to 32767 (some functions will store a number in the range 0
to 65536 - for example, PEEK, POKE
and USR). Floating point numbers are
stored in five bytes, whereas integers
take up two only - so the IS compiler
produces much quicker code than does
the FP version; in some cases operation
can be speeded up by using the INT
function, but generally the FP compiler
will run two to ten times faster and in all
but optimum conditions the speed
increase will be at the lower end of
In most instances, the 'IS' model is perfectly satisfactory, despite its more limited range of facilities, and the speed factor more than makes up for the extra care that is needed to ensure that the Basic is compilable. The lack of floating point maths need not necessarily be a drawback - integer numbers are often quite sufficient and, indeed, most Forth implementations will not handle floating point numbers anyway.
As a demonstration of the comparative speeds of interpreted and compiled Basic, let's examine a very simple program that plots every point on the screen (Figure 1). A couple of FOR/NEXT loops do the job quite adequately and, as can be seen from the timings, the 'IS' compiled version is fastest by many orders of magnitude. In the segment of this review that looks at Abersoft Forth, I have included a Forth version of this routine and a timing for further comparison.
MINUS MASTER KEYBoth Softek compilers use the same memory addresses, and both take up approximately 6K of RAM. I had hoped to incorporate Softek's Master Key program, which defines the SPACE key as a further SHIFT and which then uses this in conjunction with the numeric keys to give user-definable function keys. Unfortunately Master Key, which worked a treat on my earlier Spectrum model, is another fine program that has fallen by the wayside now that Sinclair has started mucking about with the ULA (see Frontlines, Sinclairwatch). Your author's much-loved Issue 2 Spectrum gave up the ghost a few weeks ago and despite having now got a replacement - also categorised as an Issue 2 - affections for the new model are already strained by the number of programs that now fail to work. Sinclair Research may claim that it's all the fault of software manufacturers who have jumped to conclusions about specifications, but one program that resolutely
command needed both to compile and then
to run programs. I just hope that Softek
produces a revised version for later
Issue 2 and Issue 3 machines.|
Anyway, even without Master Key, Softek's compilers work well enough. The compiler is first loaded and the user is asked if RAMTOP is okay at 40000 (48K version). RAMTOP may be moved to allow many different short routines to be linked together. After typing in the Basic, all that is needed is to key in RAND USR 59300. The compiler makes two passes through the program, printing on-screen the start and end addresses and detailing any errors. Compilation stops at any mistake and the offending line may be pulled down and edited in usual Basic fashion. Once any errors have been dealt with, all that's needed is to make a note of the start address and use this in another RAND USR call to RUN the program. The Basic program remains in memory if desired, so both interpreted and compiled Basic programs may be run.
Initially, all but the simplest programs will probably refuse to compile when using the 'IS' version - but it's not too difficult to rewrite the offending sections to allow for the limitations (arrays will obviously take some thought - one solution is to POKE the required information into spare memory for later retrieval). Only skimpy, provisional documentation was available to work with while writing this review, but Softek assures us that full manuals will be available very shortly. The 'FP' compiler is much less finicky, although it did seem impossible to use a third parameter in a DRAW statement, despite the manual's claims to the contrary.
One particularly nice feature is the use of special REM statements to give commands and facilities not normally available in Sinclair Basic. These include such features as ON ERROR GOTO; ON n GOTO, where n must be a single-letter variable; and, most useful of all, REM S a,x,y which plots the character whose ASCII code is at PLOT position x,y. This REM statement allows some very smooth pixel-by- pixel movement (see Figure 2) and can be used with user-defined graphics to produce mini-sprites.
There were some slight problems with graphics when using the compilers - the Union Jack program from the Sinclair manual, for example, gained some extraneous black blobs when compiled - but there was certainly nothing that could not be put right after a little thought. Hopefully the final version of the manual will go into a little more detail than the preliminary effort - but even with just this, both Softek compilers proved easy to use and gave some impressive results
It's also nice to see that Softek has dropped its demand for royalty payments on programs that are produced with its compilers - all the company now asks is that the use of a compiler is acknowledged on packages and advertising.
The 'FP' Compiler costs £19.95, the
'IS' Compiler £9.95 and both together
the price is £24.95. You can get them
from Softek, xxxxx nn, nn/nn xxxxxxxxx
xxxxxx, xxxxxx xxn.|
The newcomer to the language will notice two major differences between Forth and Basic - Forth uses Reverse Polish Notation (ie. Basic's PRINT 2+2 is replaced by 2 2 + . ), and makes great use of the stack for virtually every operation.
There are now many versions of Forth available for the Spectrum - Abersoft's implementation is basically fig-FORTH (the modishly lower case 'fig' referring to the Forth Interest Group) with extensions to handle the machine-specific graphics and sound commands. Forth was originally designed for use on disk-based systems, and the Abersoft version emulates disk operation by setting aside an 11K chunk of memory and using this as a 'pretend' disk. Although 11K does not sound like an incredible amount of memory, the compactness of Forth allows some very complex programs to be developed.
The version looked at here has no provision for Microdrives, but it would be relatively simple to implement these, giving in effect a true (although slow) disk-based system. The 11K of 'RAM-disk' is organised into pages of 1K, each containing 16 lines of 64 characters. This is hardly ideal for the Spectrum's 32-character display but is a Forth standard and, in fact, gives rise to no real problems in use.
HOW IT OPERATESFor those who are totally unfamiliar with the language, it should be said that Forth is used by defining words, using the basic building-blocks of the standard words in the dictionary. Each new word is treated as a new dictionary entry, and further words may be defined by using these. Thus, eventually, a complex program may be defined and run by the typing of a single word.
The stack assumes paramount
importance, being used for almost every
operation - even to the extent of passing values from word to word and doing
the same job as a Basic variable. It is in
fact a surprisingly easy language to get
to grips with, once the user has grasped
Reverse Polish. Words may be defined
direct from the keyboard - in which
case the definitions go straight into the
dictionary; or by using the editor - in
which case they are not compiled
immediately but wait until the blocks of
text from the editor are LOADed.|
For most of the machine-specific extensions, Abersoft has stuck to the familiar Basic names, but Reverse Polish means that parameters go before, rather than after, the keyword - the Basic PLOT x,y becomes, for example, x y PLOT (note the absence of a comma). In some cases the familiar words have a slightly different meaning - the Basic DRAW, which uses relative coordinates (DRAW 50,50 would mean draw to a point 50 pixels horizontally and 50 pixels vertically away from the last plotted position) is replaced by absolute coordinates, with 50 50 DRAW meaning draw a line from the last point plotted to the screen coordinates 50,50. The CIRCLE routine in ROM could be called from Forth. The Basic BEEP command is omitted completely, which is a pity. However, the facility exists to insert machine code routines and so the CIRCLE becomes the Forth BLEEP, used in the format n1 n2 BLEEP to produce a tone of duration n1 and pitch n2. User- defined graphics are fully supported, and the manual contains a routine to define any character by using the word UDG.
In addition to the Spectrum graphics and sound extensions, Abersoft Forth supports the Pascal-like CASE structure for handling multiple decisions, and the word FREE which - surprise, surprise! - tells you how many bytes
remain free for use.|
The Abersoft documentation makes no claims about the use of Forth, instead concentrating on the Spectrum-specific extensions and giving a glossary - with a few omissions - of the words in the dictionary. Unfortunately the glossary contains some misprints, but as the novice user will need a proper Forth instruction book, these should not be too troublesome. It's a good idea to supplement the Abersoft manual, and whatever book is decided on for teaching purposes, with the fig-Forth installation documentation; this costs a fiver and is well worth shelling-out for (the contact address is given at the end of this article).
All in all, then, Abersoft Forth is highly recommended for the beginner who wishes to learn more about this fascinating language. With an increase in speed of up to 5000 percent over Basic, Forth provides a good alternative to machine code for fast-running programs and speedy graphics - and its use in arcade machines testifies to its success as a language for the programming of all-action games. It's impossible to give more than a rough idea of the language's capabilities in this short article - but hopefully, at least, your curiosity will provoke you into investigating Forth on your Spectrum.
Abersoft Forth costs £14.95 and is available from Abersoft, n xxxx xxxxxxx, xxx xxxxxx, xxxxx xxnn nxx.
GOOD READINGThe Complete Forth - Alan Winfield (Sigma Technical Press)
Discover Forth - Thom Hogan
Forth Programming - Leo Scanlon
Forth installation documentation is available from Forth Interest Group UK, nn xx xxxxxx xxxxxxx, xxxxxxxxxx xxxxx xxxxx, xxxxxx xn.
"I agree it's quite remarkable that we can run the whole of BL on a Sinclair Spectrum - but do we really need 17,340 people to operate it?"