ABC – A BASIC Compiler

Medium
Disk
Year
1983
Publisher
Monarch Data Systems
Type
Language
Category
Atari BASIC compiler (integer P-code)
Developer
Monarch Data Systems
Language
6502 machine language
Requirements
40K Atari 400/800 (later XL/XE) with disk drive and Atari DOS 2.0S; compiled programs run in as little as 16K without the BASIC cartridge
Cover of the ABC reference manual: Monarch Data Systems butterfly logo above the large letters ABC and the line 'A BASIC Compiler for Atari Computers'

Overview

ABC ("A BASIC Compiler") was the first BASIC compiler to reach Atari owners. Monarch Data Systems of Cochituate, Massachusetts sold it in 1983 for $69.95. It takes an ordinary program SAVEd from the Atari BASIC cartridge and produces a binary file that loads from DOS like any machine-language program. The finished program needs no cartridge, runs several times faster and is much harder to list or copy.

ABC is not a native-code compiler. It translates each BASIC line into a compact pseudo-code (P-code) and links it to a small run-time interpreter of about 4K. Monarch claimed speed-ups of four to twelve times. In ANALOG Computing #11 (1983), Brian Moriarty measured about 7.4 times on a screen-filling benchmark: 565 jiffies against 4,160 for the BASIC cartridge.

How it works

The trick is integer arithmetic. Atari BASIC stores every number as a six-byte BCD floating-point value, and converting those values to and from binary is a big part of why it is slow. ABC keeps all numbers as three-byte binary integers, which gives a range of roughly ±8 million. P-code numbers take three bytes instead of six, so compiled programs are often smaller than the tokenised BASIC as well as faster. Moriarty compared the P-code to a FORTH program: essentially a list of pointers into the interpreter, which cannot be LISTed or meaningfully disassembled.

Using it is simple:

  1. Debug the program in Atari BASIC, then SAVE "D1:GAME.BAS".
  2. Remove all cartridges and boot the ABC disk. The compiler is an AUTORUN.SYS file.
  3. Give the source file name (default extension .BAS) and an output name (default .CMP).
  4. ABC writes the interpreter to the output file, then compiles one line at a time. It prints every 25th line number and a dot for each line in between.
  5. Press SELECT to return to DOS and use L to load and run the result. Name it AUTORUN.SYS to make it boot automatically.

The output normally loads at $2600. Holding OPTION as the compiler starts lets you choose another interpreter file (INTERP.Xnn, where nn is the high byte of the load address), and the MKRELO utility compares two builds made at different addresses to produce a fully relocatable program. A separate product, Makeboot ($14.95), turned ABC programs into self-booting disks or cassettes that need no DOS.

What you must change in your BASIC

Because there is no floating point, ABC refuses ATN, CLOG, COS, EXP, LOG, RND, SIN, SQR and the ^ operator, and also the statements BYE, CLOAD, CONT, CSAVE, DEG, DOS, ENTER, LIST, LOAD, LPRINT, NEW, RAD, RUN and SAVE. The manual suggests workarounds:

  • Random numbers: read the POKEY random register, e.g. VALUE=INT(PEEK(53770)*10/256) for 0 to 9.
  • Fractions: scale everything, e.g. INT((7*100)/2) gives 350 for 3.50.
  • Trigonometry: build a table of INT(1000*SIN(X)) values in DATA statements.
  • Big constants: a literal over 65,535 won't compile, so write 250*1000 instead (or put it in DATA).
  • Division order: every division is truncated immediately, so INT(5/3*2) gives 2. Rewrite it as INT(5*2/3).
  • Leaving loops: use POP before jumping out of a FOR loop or a subroutine.
  • Delays: empty FOR loops become almost instant, so time with the jiffy clock at location 20 instead.

Strings and arrays are not laid out the way the cartridge lays them out. Tricks that rely on one DIMmed string following another (a common way to reserve player/missile memory) break, though ADR() still works. PEEKs and POKEs to the cartridge's zero-page area (128–255) are also unsafe.

Compared with the Datasoft compiler, ABC accepted far more programs unchanged, including variable GOTOs and DATA statements anywhere. Moriarty compiled his 99-sector adventure game Adventure in the 5th Dimension with ABC after one fix from Monarch's author, getting 129 sectors of P-code.

Versions

Version 1.0 shipped with a 20-page manual on a copy-protected disk. Monarch admitted that pirated copies of an early, buggy release were circulating. Release 1.03 (Software Report #2, 1 November 1983) fixed the known bugs, cut three bytes from every variable reference, raised the GOSUB/FOR stack from 64 to 127 entries, could be loaded from any drive (making it usable with other DOSes and double-density drives) and worked with the new 1050 drive, which 1.02 did not. Versions 1.02, 1.03 and 1.05 are known to exist.

No royalties were charged, provided the program displayed: "Produced using copyrighted software products of Monarch Data Systems".

Legacy and using it today

ABC was used in real products. Jerry White's Poker Solitaire type-in (Antic, March 1984) compiled perfectly with it, and COMPUTE!'s Second Book of Atari Graphics added lines to make its Fontbyter editor ABC-compatible. AtariAge members disassembling Sid Meier's MicroProse wargames found ABC-compiled BASIC front ends (files such as WAR.ABC and DRIVER.ABC), and a decompiler now exists that turns ABC files back into BASIC.

Today, boot the ABC disk in Altirra or atari800 with BASIC disabled and a DOS 2.x-compatible disk holding your program. Programs written for ABC also run unchanged under the cartridge, which makes it easy to test both. For new work, Turbo-BASIC XL's compiler handles floating point and is usually the more practical choice. ABC is still worth knowing, because it explains how many commercial "BASIC" programs of 1983–84 ran as fast as they did.

Credits