Review:
Petspeed, An Optimizing Compiler For PET/CBM
Richard Mansfield
Assistant Editor
This program can transform any BASIC program into a compiled version that RUNs far faster. For any 4000 or 8000 series models, 4.0 BASIC, except the 8096. There is a version for the new Commodore 64 as well.
I have a version of the game "Othello," in BASIC, which is several years old. It's a good opponent, but I avoided playing it very often because it would take so long to figure out its move. After I made a move, a cursor would appear and slowly travel to each square on the board, in an infuriatingly leisurely way. It was like playing with someone who gently put a finger on each square before making a move in checkers.
After it was transformed with Petspeed, an optimizing compiler sold by Small Systems engineering, it became a far faster player. Now the cursor flies across the squares in a most computer-like fashion, making up its mind much more quickly than I ever could, as nature intended.
A compiler takes an ordinary BASIC program and creates a second, faster version. The new program is either in machine language or a special machine-language-like code. In either case, the goal is to create a highly efficient program that will RUN far more rapidly.
Petspeed succeeds. Depending on the nature of the program, Petspeed can RUN up to 40 times the speed of ordinary PET BASIC. The following simple benchmark took four minutes and one second to RUN in BASIC. The Petspeed version took one minute, 33 seconds.
10 TI$ = "000000" 20 FOR I = 1 To 50000 30 X = X + 1 40 NEXT I 50 PRINT TI$
In operation, Petspeed uses a dual disk drive with the target program on a disk (4000 or 8000 series, BASIC 4.0) in Drive One and the special Petspeed disk in Drive Zero. It takes over the computer and asks you just one question: what is the filename of your BASIC program? Then, for about 3 1/2 minutes it builds a new version on Drive One in a pseudo-code called "Speedcode" which, when RUN, is used by a pseudo machine. In essence, a compiled program is appended to a special "interpreter" program, 8K long, which is loaded into RAM with it. This pseudo machine takes control when you type RUN to use the compiled program.
The compiled program RUNs like a machine language program. If you LIST it, all you see is: "10 SYS (1040) COMPILED IN PETSPEED." The STOP key is disabled (though you can enable it by putting an Enable-Stop instruction in the BASIC program: 10 REM ! ES). You can't use DIM A(N). The N must be a number so the compiler can know in advance how much space to reserve. Since it's no longer BASIC, there is no point to the words RUN or LIST appearing within the program and they, too, are disallowed. These are the only restrictions, however.
Special Options
There are some additional programming techniques not allowed in BASIC. You can use DEF FN with mixed string and numeric arguments. In this way a quick PRINT USING function can be set up. You can declare that all characters in a variable name are significant, not just the customary first two. Integer FOR/NEXT loops are permitted. All numeric values are, whenever possible, translated into the faster "integer" type by the compiler anyway.
The "optimizing" feature of this compiler includes the floating point to integer conversion as well as many other improvements. REMs are, of course, dropped, GOTOs and GOSUBs are positioned for maximum efficiency, and all array references are resolved during compilation.
The 32 most frequently used variables in your program are given particular attention. They are set up to be accessed using a rapid addressing mode similar to machine language's zero page addressing. The one most frequently used variable is simply put into zero page.
BASIC programs with machine language patches added to them require special handling. For example, you might need to modify a line which changes the Limit Of Memory pointers to reserve space for machine language. BASIC and Petspeed use up different amounts of memory. If a machine language subroutine is required, it can be loaded into free RAM space during the program RUN. If the routine involves using BASIC's variables, it will have to be modified to reflect the way that Petspeed stores variables. Maps, tables, and descriptions are provided in the Petspeed manual to assist machine language programmers with this conversion.
To use the compiler, you must attach a small black plastic box, the "Speedkey," to the First Cassette Drive port on the back of your machine. However, any programs which are compiled into Petspeed can run on any machine and do not require the key. If you are interested in selling a program you've compiled with Petspeed, you are free to do so. The manufacturer makes no claim on the compiled software and no special keys, boxes, or security devices are necessary.
Petspeed
$350
Small Systems Engineering
222 B View Street
Mountain View, CA 94041
(415)964-8201