Programming: BASIC
ZX Spectrum 48K

Rupert Goodwins
Chris Bourne

Is your Basic boring? Do your programs dawdle through data, and saunter through subroutines? Perhaps Hisoft has the answer with its Basic Compiler.

You know Basic. Great fun to dabble with, but a bit lacking in the speed department. Compared to the Ferrari of machine code, Basic is a 2CV. There's nothing you can do in the former you can't do in the latter, but boysoboys, what you do, you do faster. And with style.

Basic, as found on your Spectrum, is slow for a number of reasons. The biggest problem is the way in which the computer deals with the program. For each line of Basic, the machine laboriously works out its meaning, what memory to use and how it all links in with what's gone before. Then, and only then, the computer knows enough to obey the instructions on that line. If it ever goes back to that line, which in a program with Gotos, Gosubs and For... Nexts it will, it has to carry out all that work again, before it can produce a result.

So, short of diving into the horrors of hexadecimal, how do you speed things up? The answer is a compiler. A compiler goes through a Basic progam and does all the checking and translating. Instead of then running the results, it stores them as machine-code commands in an area of memory. When the time comes, the user (that's you) treats the compiled program like a pure machine-code program. As all the checking's been done once and for all, the program runs much faster.

There have been Spectrum compilers about for a while. Unfortunately, they've traditionally been restricted by their inability to cope with various commands, forcing the user to modify programs to take account of their limitations.

This HiSoft Basic compiler is (almost) innocent of such sins. You load it in, load or type in just about any Basic program, and utter the appropriate magic words '*C'. A few seconds later, you have a machine-code program that does everything your Basic did, but faster.

How much faster depends on a lot of things. If your program depends heavily on Rom-based graphics commands like Circle or Draw, then you can only expect a three-to ten-fold increase in speed. But if it spends a lot of time doing simple maths, or string handling, the acceleration can be breathtaking. HiSoft supply a set of demo programs, including one called 'Sieve'. This is a standard benchmark for compilers, as it works with simple numbers in a way which any compiler worth its salt should really go to town on. HiSoft Basic's compiled version goes more than 150 times faster than unaided Basic. That's fast.

There are commands which the compiler can't deal with. Mostly these are 'system' commands, like Save, Load, Clear and so on.

To tell the compiler to start compiling a section of your program, include a line Rem : Open #. The line Rem: Close # stops the compiler producing code. For every Open # - Close # pair a chunk of machine code is generated, and the compiler prints the start address of that section. Replace the Basic sections with Randomize Usrs of the appropriate address, and it all works.

The only serious omissions are some of the naughtier things you can do with arrays, and the ability to compile Val A$ (although Val A$ '2314' is OK). This function is very useful, and can be difficult to replace by other bits of Basic.

The manual is good. There's a short tutorial, which works with the example programs provided, and several reference sections covering commands, memory maps and errors.

The size of the compiled code is bigger than the Basic program which spawned it. This is because the code needs some support software (known as runtime routines) but HiSoft Basic does its level best to minimize the problem. Some compilers load in the complete set of routines for every program. HiSoft Basic Compiler just uses the relevant ones.

It allows you to select just the right way to deal with a variable, so if a variable will never be a number with a decimal point in it, then you can tell the compiler to store it in an efficient format. The compiler can look through a program while it runs, and tell you which variables are candidates for this treatment. Other things the compiler itself looks for include divide and multiply by two, as commands such as these can be coded into very fast machine language indeed.

The compiler takes three passes through the Basic program to produce its result. During each pass, it uses the screen memory to hold information and lists. This is quite a good idea, as after a while it's possible to judge what's going on by looking at the dots and colours whizz past, but to the uninitiated it does look horribly like a crash.

Does it work? I dug out my stock of Basic programs (on WH Smith C15 tapes!), and ran them through the mill. On average, it took about ten minutes to convert and produce an efficient compiled version, and nothing proved uncompilable.

Very impressive. The Breakout game on the old Spectrum Horizons tape ran far too fast to even see, let alone play...

You get two compilers on two tapes for your money in the videotape size pack. The 48K version is about 10K long (leaving room for roughly 30K of Basic), and uses direct commands prefixed by a *. The 128K+2 version is a bit more subtle.

It has about 500 bytes of program in the Basic area, but mostly lives in the silicon disc, thus leaving around 40K of room for your evil doings. It has a menu system for commands, brought into life by pressing True Video and Inv Video at the same time. These keys are also used as special shifts in conjunction with the cursor keys to duplicate the elusive keypad's editing functions. Don't try bringing up the compiler menu when the Basic's Option menu is up, as things can get confused! Both versions transfer to Microdrive with the minimum of fuss.

The only reason I can think of for you not buying this program is if your knowledge of Basic goes no further than Load "".

Even if you know Z80 machine-code backwards, the compiler lets you cook up a concept in Basic, debug it and then commit it to code fast enough to make dabbling a delight.

And for those who know Basic and type in the odd listing or two. this compiler must be nigh on invaluable.

Don't expect to rewrite Elite, but Basic is fun again.

Label: HiSoft
Author: In-house
Price: £15.95
Memory: 48K/128K
Reviewer: Rupert Goodwins


If you ever write anything in Basic or machine-code this program is a must. it works like magic. Buy it.


Screenshot Text

Pattern produced in 35 seconds in Basic. Cut down to under 10 seconds when the same program is compiled.