Authors
Publication
Pub Details
Date
Pages
Deja vu! That was my first thought upon opening the large envelope from editor Tim Woods. Let’s take a trip via H.G. Well’s time machine by setting the controls to travel back in time one year. Exactly one year ago, I was asked to review a BASIC compiler for the T/S 2068 called ZIP (Sept/Oct ’85 issue of TDM). Back to the present! I now have the task of reviewing a new BASIC compiler for both the 2068 and Spectrum (two different versions on the same tape). It’s called TIMACHINE.
First, a short review. BASIC is the resident ROM language in the Sinclair machines. BASIC is a language we humans can easily use to make the computer and its processor perform a desired task, and is a fairly effortless language to learn and use. It is also a fairly forgiving language, especially with the help of Sinclair syntax and error checking. The trade-off for this simplicity is a lack of speed and flexibility.
The actual resident language of the Z80A CPU (the main brain of the Sinclair machines) is machine code, also known as assembly language. This “language” is composed of about 50 different instructions, though most have many variations. The advantages of machine code include fast execution, efficient use of memory, and freedom from the dictates of the Operating System.
The other side of this coin are the following disadvantages: programs are hard to understand and follow, a simple manipulation of data may involve many complicated steps, real-number calculations can be difficult and it can be very unforgiving. Programming in machine code can involve extensive study of the machine, books and tables, developing tools (assemblers and monitors), and, of course, patience.
Enter the BASIC compiler, which attempts to marry the advantages of both BASIC and machine code, while trying to avoid their drawbacks.
TIMACHINE is the best compiler I have seen to date for the Sinclair Z80 machines. Timachine will compile virtually all of the Sinclair BASIC commands into a much speedier program.
This compiler is quite different from others I have seen in both speed and versatility. Where many compilers only allow the use of integers (whole numbers from -32768 to 32767 or 0 to 65535), Timachine will allow the use of real numbers (decimals and numbers far larger or smaller than 16-bit numbers). There are also floating-point (or real number) compilers available for the Spectrum, but unlike Timachine, can not compile both integers and real numbers, and run only 3 to 5 times faster.
Timachine allows the user to specify which numbers are to be real or integers, thus greatly speeding up performance when doing integer mathematics. Unlike other compilers, Timachine also allows string arrays and defined functions and 2-dimensioned arrays, along with many other commonly used BASIC commands. Because it allows floating-point mathematics, one can also compile trigonometry functions (TAN, COS, ACS, SIN, ect.).
In fact, according to the manual, Timachine will support all but the following BASIC commands: CLEAR, CONTINUE, ERASE, FORMAT, LIST, LLIST, LOAD, MERGE, MOVE, NEW, RESET, RUN, SAVE, VERIFY, FREE, ON ERR, and VALS. A few other commands may have some limitations connected with them. (e.g.; RESTORE, GOTO, and GOSUB must be followed with a valid line number and not an expression or variable; an array can only be dimensioned to one set length; a defined string variable may not be later dimensioned; VAL A$ is not supported.)
Speaking of the manual, I must compliment Novelsoft and Cameron Hayne (the author of the manual and program) for providing an extensive and easy-to-follow manual. The manual contains 52 pages of excellent step-by-step tutorials (sample programs included on tape), thorough explanations of commands and directives (even explaining how to obtain certain Sinclair keywords), detailed notes on how the compiled code handles certain BASIC instructions, clear and helpful hints, definitions of Error Messages, a list of helpful POKEs, a memory map, and a list of the runtime routines.
Timachine is loaded into the memory location normally reserved for BASIC (right after the system variables) with the normal 2068/Spectrum memory map shifted upwards to allow for BASIC programs. There is approximately 27k available for a BASIC program (30k on the Spectrum). Once loaded into the computer, Timachine is completely transparent. One can LOAD or type in a BASIC program and RUN it as if Timachine was not in memory.
Timachine is accessed through direct commands prefaced by an asterisk, “*” (e.g.; [*] will compile a BASIC program). In fact, the only time Timachine makes itself apparent except for less available memory) is when the trace (an interrupt-driven program) is on. While running a BASIC program, the trace will log and type the program variables every 1/60th of a second (1/50th on the Spectrum) and provide a listing of the variables with their type (f.e.; real, integer or positive integer) and the length of string variables. This is a very helpful tool.
There is a limit of 255 simple numeric variables, whose name can be any length and the standard number of string variables.
Directives to the compiler (instructions) are included in the actual BASIC program in REM statements with an exclamation point, “!” , following the REM (e.g.; 10 REM ! OPEN # will start compiling at this point).
Some of these directives are instructions on where to halt or re-start compiling (allowing access to BASIC or ones own machine code routines), maximum length allotted to a string variable, and setting types of numeric variables (i.e.; real, integer, ect.).
One can direct a listing of the addresses for the runtime routines and the machine code variables used by the compiled program. Also, a listing of the execution addresses for individual compiled BASIC lines can obtained.
One can specify the address at which the compiled code will reside, giving flexibility in locating ones own machine code or BASIC routines.
Learning to use Timachine is simple, but practice and study is needed if one plans to master its uses. Simple BASIC programs are easily compiled into fast-running programs. An understanding of real numbers and integers is needed to obtain maximum and exact results. When real numbers interact with integers, interesting, but usually unintended, results can occur.
While testing Timachine, I used various BASIC programs I had already developed and debugged. During the first pass, Timachine checks the BASIC for any unsupported BASIC commands and provides clear Error Messages displaying the offending BASIC line, usually with a flashing “?” cursor marking the part in question.
The next pass is a dry run to fix the amount of memory needed for the final version and check for destination addresses for GOTO, G0SUB, ect. commands.
The last pass is the actual creation of the machine code. The user is provided with information on the length of the compiled code, amount of memory allocated for variables, length of the BASIC program, and instructions on how to SAVE, LOAD and run the compiled code.
This complete compilation process is quite speedy. Timachine compiled the demo program included with the ZIP compiler in 9 seconds compared to the 31 minutes taken by ZIP (see Sept/Oct ’85 TOM, pp. 18-19).
I was able to compile most of my test programs satisfactorily, with only minor modifications to the BASIC. However, the one larger and complicated of the BASIC programs proved to be too convoluted to simply modify. I did not have time to fully test this program, but feel ft would require a major reworking obtain proper results via Timachine. If the program had originally been written with Timachine in mind, I see no reason could not be easily compiled.
As the compiled code is in machine code, it can be unforgiving and provide undesired results.
In BASIC, “PRINT H$ (X)” will print H$(1) If x=.5, where the compiled version will attempt to print H$(0).
Another problem I encountered dealt with FOR/NEXT loops. In BASIC, one can leave a FOR/NEXT loop, jump into the middle of another FOR/NEXT loop using the same variable and upon execution of NEXT (X), resume operation at the start of the second loop. However, in machine code the continuation is at the start of the first loop.
There are many runtimes (machine code routines used by the compiled version to execute selected operations) which use extensive ROM routines. This allows for simple conversion and efficient use of memory, but can slow down performance. When these runtimes are used, the improvement in speed is slight, (e.g.; CIRCLE, DRAW, COS, ect.).
It is up to the user to develop a BASIC program that will utilize a more efficient compiled version. This will come with practice and experience, though knowledge of machine code will be helpful.
One can use Timachine as a tutor on how to write their own machine code utilizing ROM resident routines.
Timachine is the most comprehensive, flexible compiler I have seen for the Spectrum or TS 2068. It is always a pleasure to encounter a program of this class, and I must applaud Cameron Hayne for obtaining so much from our humble Sinclairs.
Depending on the programming skills of the user, one can compile fast and efficient machine code programs, though not necessarily using less memory. It is a program that will allow the novice BASIC programmer some degree of success, while allowing the more experienced programmer greater flexibility.
One should not expect to produce amazingly impossible feats from this product, as these usually come from direct manipulation of the processor via one’s own machine code. One will be able to produce effects that are available in BASIC, but at speeds that will greatly enhance them.
In last year’s review of ZIP, I stated that one should choose a compiler based on its limitations. Well, Timachine has few limitations and is a quick and comfortable program to use.
Will this be the “last word” in compilers? I don’t know. Let’s set our “time machine” for one year into the future.