Crash


The Colt

Publisher: HiSoft
Machine: Spectrum 48K

 
Published in Crash #20

The Colt

The Colt is a new Basic compiler from HiSoft, previously well-known for their Spectrum Pascal package. Colt is a fourth generation program, descended from ZX-GT, Mcoder 1 and Mcoder 2. Rather confusingly, Mcoder 3 (which we look at later) is an entirely new program.

Colt is more than just a Basic compiler - the package also contains The Executive, which contains a number of useful extensions to Basic, some of them quite unusual and others rather dull. You get a digital clock accurate to a tenth of a second (!), which you have to set using just two keys, like a tatty radio alarm. You can control the clock like a stopwatch, but it stops whenever you use cassettes or microdrives!

You get single-key commands, some of them programmable, but these use the Space key as an extra Shift. This interferes with key 'roll-over', so you have to be careful when typing text, or Space characters get lost. Command entry takes a lot of getting used to - you must press Space, then another key, then release Space, then release the other key. If we hadn't got used to Spectrum single-key entry, we'd say it was almost unusable...

HiSoft COLT Compiler

The Executive offers a full set of QL-style windowing commands and a sprite handler which can cope with up to 16 large sprites (32 by 24 pixels). These facilities allow smooth movement and scrolling, with automatic collision detection. Keen programmers may value commands for error-trapping, logging the parts of a program which take the most time, deleting groups of lines and base conversions - in the unlikely event that they haven't already got programs to do such things.

The Compiler

Colt itself occupies about 6K of memory, and The Executive requires another 7K. You can use the compiler on its own if you wish. Even this may not leave enough space to compile large programs, since Colt normally keeps the original 'source' and the compiled code together in memory. You can compile up to about 16K this way; otherwise you must tell Colt to overwrite the original program as it compiles it, allowing up to 32K to be compiled, but forcing you to save and load your program every time a change is needed.

Colt works blindingly fast, churning out code at a rate of about 1K a second! This makes it noticeably faster than Mcoder 2 and the Softek compilers, and much faster than all the others. If an error is found the line is listed with a flashing question mark, and the cursor is set so that the line pops up as soon as you press EDIT. In view of the speed of compilation, it hardly matters that Colt only finds one error at a time!

Unlike the other compilers reviewed this month, Colt is an integer-only compiler, which means that arithmetic is done using whole numbers, trading accuracy for speed. If you are writing a new game the lack of floating point arithmetic should not cause many problems, but it does make it very unlikely that you will be able to compile existing Basic programs without major changes.

Colt recognises the vast majority of ZX Basic commands, although user-defined functions and arrays of more than one dimension are prohibited. Calculations are not allowed in DATA statements, and there are minor limitations on the use of AND, OR, LEN, CLEAR, RND and FOR.

The benchmark timings show that Colt produces much faster code than Blast or Mcoder 3. Programs compiled with Colt run at roughly the same speed as those processed by Mcoder 2 or Softek's IS compiler; only Zip produces substantially faster code.

You can use commands from The Executive in compiled programs - window and sprite-handling is likely to be especially useful. Colt is the only fast compiler which recognises microdrive commands, and HiSoft claim that it can even cope with floppy disks and wafer drives so long as they use the Sinclair keywords. Of course, the compiler doesn't actually speed up these operations - it just calls the ROM like normal Basic.

Floating Point (Almost)

There is a 'trick' way of doing floating-point arithmetic in programs compiled using Colt. If the VAL, VAL$ or STR$ functions appear in a compiled program, the interpreter is used to work out the result, so decimal maths can be used inside the string being processed. You can put:

LET NUM=VAL(COS''(2)*255'')

in a compiled program; the calculation is performed using full floating-point maths (at the speed of normal ZX Basic) and then NUM is set to the whole number part of the result. If you use:

LET ST$=STR$ VAL(''7/2'')

the string ST$ is set to '3.5', the correct floating point result, although there's not much you can do with it except PRINT it or use it in another VAL expression.

This would be a powerful feature but for the fact that any variable names in VAL strings refer to BASIC variables, rather than to the variables in the compiled program. It is a useful way of passing values from Basic to machine code, but it is often just a source of irritation, as there is no way a compiled program can set BASIC variables. You can read Colt variables from BASIC, but that's not quite the same thing...

Documentation

We looked at the pre-release version of the compiler, so the documentation was not in its final form. What we received was plentiful and interesting, although much of it might be heavy going for someone unfamiliar with the intricacies of machine code and the Spectrum ROM.

The Colt package is good value at £12.95, but it is not very easy to use - it is rather idiosyncratic, like all the integer compilers, and various tricks and POKEs are needed to get the best from it. Colt is recommended to hardened hackers, especially if the Executive facilities fill a gap in their present armoury.