MMG BASIC Compiler

Medium
Disk
Year
1984
Publisher
MMG Micro Software
Type
Language
Category
Atari BASIC to 6502 machine-code compiler
Developer
Special Software Systems
Language
6502 machine language
Requirements
48K Atari 400/800/XL/XE with disk drive (two drives or double density recommended); no cartridge (XL/XE: hold OPTION at boot)

Overview

The MMG BASIC Compiler is the 1984 MMG Micro Software edition of the compiler that Special Software Systems had written for Datasoft a year earlier (see Datasoft BASIC Compiler). The two are essentially the same program. It turns an ordinary Atari BASIC program into genuine 6502 machine code rather than P-code. You choose integer arithmetic for maximum speed or the Atari's own floating point for full compatibility. MMG's manual claims that several arcade-style games on the market had been written in BASIC and compiled with it. This edition was sold as version 2.0.

Along with ABC and the Turbo-BASIC XL compiler, it is one of the three Atari BASIC compilers enthusiasts still recommend. Some hobbyists still write in Atari BASIC and compile with MMG as a matter of routine.

Compiling a program

The disk holds DOS 2.0S, a title program, the compiler CMP.OBJ, the assembler ASM.OBJ, a system equates file SYSEQU.ABC and two run-time libraries, SYSLIB.INT and SYSLIB.FP.

  1. Remove cartridges (on an XL/XE hold OPTION while powering on) and boot the disk. Press C at the title page. You can also load CMP.OBJ from the DOS menu.
  2. Enter the BASIC file name and an object file name. The manual suggests .BAS and .OBJ extensions.
  3. Choose I (integer) or F (floating point).
  4. Pass 1 prints each line number as it converts BASIC into assembler files ASSEM.SGA, ASSEM.SGB, … ; Passes 2 and 3 assemble them into the final program. With two drives no disk swaps are needed: keep everything on drive 2 and leave drive 1 for the scratch files.
  5. Finally choose P to print a line-reference map (screen, printer or disk), R to run the program or D for DOS.

The scratch files need about five times the space of the BASIC source, which limits single-drive users to programs of roughly 120 sectors. A CHANGE program on the flip side of the master disk switches to true double density for larger programs (1050 "enhanced" density is not supported). One odd but useful convention: if your program contains a LIST statement anywhere, for example 32767 LIST, the assembler files are kept for you to study or modify. Without one, they are deleted during pass 3 to free space.

Integer or floating point?

The manual reckons integer code runs about 15 times faster than the cartridge and floating-point code about three times faster. Integer mode uses 16-bit values (−32,768 to 32,767). It cannot do COS, SIN, CLOG, LOG, EXP or ATN, and fractional constants are silently truncated. MMG made two thoughtful exceptions:

  • RND(n) takes an integer argument and returns a random whole number from 0 to n−1, so X=RND(126) gives 0–125.
  • Addresses above 32,767 still work in PEEK and POKE, so POKE 53248,XPOS and PEEK(53279) behave. PRINT 53279, however, prints −12257.

SQR returns the largest integer whose square does not exceed the argument.

Rules for your source code

  • Not allowed: CONT, CLOAD, CSAVE, ENTER, LOAD, NEW and SAVE.
  • GOTO, GOSUB and RESTORE need constant line numbers. Use ON X GOSUB … instead of GOSUB X.
  • Each FOR loop may have only one NEXT.
  • COM works like DIM, but COM variables survive a RUN "D:PROG2" into another compiled program. This is a handy way to chain modules.
  • Timing loops run far too fast once compiled. Wait on the jiffy clock at location 20 instead.

Programmers also passed around notes on smaller gotchas. Put ON (X+1) GOTO expressions into a variable first, read INPUT #1 fields one variable at a time, and don't rely on printing CHR$(155) inside a string to break lines.

Technical notes

At run time the library sits at $2400, which is also the entry point, and compiled code starts at $3200. The program is followed by DATA, constant, numeric and string storage. A pseudo line 99999 in the reference map gives the last address used, which is an easy way to see the final size. Integers are stored high byte first, the reverse of normal 6502 order, so the compiler can find the sign bit in the same place whichever arithmetic package is linked. The compiler favours speed over size: GOSUB costs nothing extra, but array references, substring expressions and variable STEP values bloat the output. Turning repeated code into subroutines is the main way to shrink a program.

No royalty is due on programs you sell, provided the documentation says they were compiled with the MMG BASIC Compiler for the Atari.

Using it today

In Altirra or atari800, boot the compiler disk with BASIC disabled and attach a second virtual drive holding your .BAS file. Large or double-density images remove the old disk-space worries. Test the program under the cartridge first, since the compiler faithfully compiles bugs too. For programs that lean on Turbo-BASIC features, use the Turbo-BASIC XL compiler instead. For plain Atari BASIC that needs floating point, MMG remains a good choice.

Credits