Altirra BASIC
- Medium
- Cartridge
- Year
- 2014
- Type
- Language
- Category
- Free Atari BASIC-compatible interpreter (8K ROM)
- Developer
- Avery Lee
- Language
- 6502 assembly
- Requirements
- Any Atari 400/800/XL/XE/XEGS. 8K cartridge/ROM image (atbasic.bin) or DOS executable (atbasicx.xex, needs 48K and a free $A000–$BFFF). Built into the Altirra emulator.
Overview
Altirra BASIC is an 8K BASIC interpreter written by Avery Lee, the author of the Altirra emulator. It is meant to be a drop-in replacement for Atari BASIC: it loads and runs Atari BASIC programs, sits in the same left-cartridge slot at $A000, and uses the same program format. But it was written from scratch, shares no code with Atari's BASIC, and may be freely distributed as source and binary. Altirra uses it as its built-in BASIC whenever no Atari BASIC ROM image is configured, which made it the BASIC many emulator users meet first. It also runs on real hardware.
On top of compatibility it adds speed and a selection of extensions, most of them borrowed with the same token values from OSS BASIC XL. A program written in Altirra BASIC's dialect can therefore be loaded by BASIC XL or BASIC XE.
Two ways to run it
- Cartridge ROM (
atbasic.bin). An 8K image that replaces the Atari BASIC cartridge or the XL/XE built-in BASIC. It can be burned to EPROM, written to a flash cartridge, or used by an emulator in place ofATARIBAS.ROM. It lets DOS boot first. - Executable (
atbasicx.xex). Runs from any DOS, including DOS 2.0S and SpartaDOS X (use theXcommand there), or asAUTORUN.SYS. It needs 48K and free RAM at$A000–$BFFF, disables XL/XE built-in BASIC automatically, and loadsD:AUTORUN.BASat startup or any program named on the command line. On a 400/800 it lowers MEMTOP by 4K to dodge an OS-A/B screen-editor bug that writes above MEMTOP.
At power-up it shows Altirra 8K BASIC 1.55 (in the 2018 manual) and the familiar Ready.
What it adds
- Hex constants (
$D000) and HEX$(), DPEEK/DPOKE for 16-bit values, and bitwise & ! % (AND, OR, XOR on 0–65535). - MOVE for fast memory block copies, and BGET/BPUT for binary I/O.
- A block IF … ELSE … ENDIF spanning several lines, alongside the classic IF … THEN.
- DOS from BASIC: DIR, ERASE, RENAME, PROTECT, UNPROTECT.
- ERR(), LOMEM, and joystick helpers HSTICK() and VSTICK().
- Player/missile graphics: PMGRAPHICS (single- or double-line), PMADR() to find each player's memory, PMCOLOR, PMMOVE (absolute horizontal, relative vertical), PMCLR, MISSILE and BUMP() for collisions.
- Unlimited FOR/GOSUB nesting (memory permitting), numeric arrays larger than Atari BASIC's 32K limit, multiple unary minus signs, and expressions as line numbers everywhere except
IF … THEN lineno.
10 SCR=DPEEK(88)
20 PRINT "SCREEN RAM AT $";HEX$(SCR)
30 FOR I=1 TO 4
40 IF I&1
50 PRINT I;" IS ODD"
60 ELSE
70 PRINT I;" IS EVEN"
80 ENDIF
90 NEXT I
Compatibility details
Programs SAVEd from Atari BASIC load without trouble. Programs saved from Altirra BASIC load back into Atari BASIC only if they avoid the new tokens; otherwise Atari BASIC may crash. Turbo-BASIC XL uses different token numbers even for shared commands such as MOVE, so move programs between the two by LISTing and ENTERing.
Lee deliberately reproduced some Atari BASIC quirks that real programs depend on: the FRE() off-by-one, shared buffers for CHR$() and STR$() in one expression, IOCB #16 acting as #0 (the INPUT #16 trick to suppress the ? prompt), and the need to RESTORE after editing before READ. Bugs that harm users were not kept. There is no revision A PRINT token bug and no revision B save bug that adds 16 bytes per SAVE; Altirra BASIC even repairs the revision B growth when such a program is re-saved. Zero-page use differs from Atari's except at documented locations, so programs that poke into BASIC's private variables may fail. Altirra 3.00 added a workaround for programs that read the current DATA line from locations 183–184.
The manual includes tips that apply to both interpreters. Combine lines and put hot code at low line numbers to speed up line searches, use X*X rather than X^2, and use string arrays or MOVE instead of PEEK/POKE loops. Note that Altirra BASIC searches forward from the current line, so a GOTO to a lower number can be slower than in Atari BASIC. There is also a recipe for recovering "unlistable" protected programs with a TRAP and an injected line 32750.
History
The interpreter appeared in Altirra 2.50, which made it the default when no BASIC ROM was supplied; the manual dates it to 2014. Altirra 2.60 (March 2015) brought a speed-up and most of the BASIC XL-style statements: DPOKE, BPUT, BGET, ERASE, PROTECT, UNPROTECT, DIR, RENAME, MOVE, HEX$(), DPEEK() and the bitwise and hex operators. Altirra 2.70 (December 2015) added LOMEM, ERR() and the player/missile set. Later releases fixed details such as closing IOCB #7 after I/O errors (4.01) and sideways printing (4.30). The source code ships in every Altirra source archive, and the Altirra BASIC Reference Manual (2018 edition) is a free download.
Using it today
In Altirra it is already there: choose an XL/XE system with BASIC enabled and no Atari BASIC ROM in the firmware list. For atari800 or a real machine, use atbasic.bin as the BASIC ROM, or run atbasicx.xex from DOS. It has no BLOAD command, so binary files must be read with BGET or a short USR routine. If you need your programs to run on stock Atari BASIC as well, stick to the compatible token set listed in the manual.
Credits
- Picture: Altirra BASIC extensions at work: DPEEK, HEX$, hex constants, a block IF and bitwise XOR. — Avery Lee (program); screenshot by the site
- Altirra BASIC Reference Manual, 2018-08-12 edition (Avery Lee) — Avery Lee (Altirra), 2018
- Altirra home page and change log (virtualdub.org) — Screenshot from Avery Lee's Altirra page, virtualdub.org
- Altirra — older change log (versions 2.50–2.70 ATBasic entries) — Avery Lee (Altirra)
- AtariAge forum — loading binary files in Altirra BASIC (no BLOAD) — AtariAge forum members
