Skip to content

Converting to FastBasic

Billy Charlton edited this page Apr 4, 2021 · 3 revisions

This documents how to convert older Basic programs to FastBasic on Atari 8-bit machines -- the 400/800/XL/XE/XEGS. This includes Basic versions such as Atari Basic, Turbo Basic XL, Basic XL, and Basic XE. Many programs that were written in original Atari Basic or other Basics from that era were written before the conventions of "structured programming" became widespread. For example, Atari Basic does not have ELSE, ELSEIF, ENDIF, DO LOOP, WHILE WEND, REPEAT UNTIL structures. And FastBasic doesn't include GOTO, ON GOTO/GOSUB etc.

These tips should help you convert those programs to FastBasic!

Extracting the program code.

Use the LIST (filename) command in Atari Basic to write files to disk in a separate ATR in the emulator. Then use an Atari Disk Utility to extract the files to your PC hard drive.

This is probably easiest with a good Text Editor on your PC. I have been using “PSPAD” and know people are using Visual Studio Code; there is a FastBasic extension for VS Code which does proper FastBasic syntax highlighting. It does help if your editor has a rectangle block text select as you need to remove line numbers at some point.

Line Numbers

Before deleting line numbers, you need to find any GOSUBs and their line number destinations. Easiest thing to do is just create a name for the new PROC, or just put a letter + underscore + line number. Line 1000 becomes PROC S_1000 and replace the return with ENDPROC. Also may need to use the editor’s find/replace function if there are many calls to the subroutine.

You can give the subroutine a more descriptive name after the program is working.

Variable Usage

A variable name must be unique and cannot use the same name for more than one variable type: you cannot have A$, A%, and A in the same program.

Variables should be set to their default value at the beginning of the program before any usage.

Data Tables and Arrays must be declared at the beginning of the program before any executable code.

Commands No Longer Supported and their equivalent constructs

The following constructs will need to be rewritten, since FastBasic only supports structured programming and the GOTOs and IFs of Atari Basic are no longer supported.


GOTO, GOSUB, RETURN, RESTORE, READ, ON (variable) (GOTO, GOSUB, EXEC). PAINT, TEXT, RAND

When GOTO is used for a loop, replace with DO-LOOP.

Replace:

10 ? “HELLO”
20 GOTO 10

With:

DO
  ? “HELLO”
LOOP

IF THEN followed by multiple statements separated with COLONs (:)

These need to placed on separate lines; remove THEN and COLONs and add an ENDIF after where the last statement was on the line. FastBasic only skips the first statement following the THEN if the condition is false.

Replace:

A = 0
IF X THEN A=1 : X = 0 : ? “TEST”

With:

IF X
  A = 1
  X = 0
  ? “TEST”
ELSE
  A = 0
ENDIF

IF THEN GOTO loops

If this creates a "loop until" condition, replace with REPEAT UNTIL (opposite condition) or WHILE WEND.

Replace:

10 A=10
20 ? "Line "; A
30 A=A-1
40 IF A > 0 THEN GOTO 20

With:

A=10
REPEAT
  ? “Line “;A
  A=A-1
UNTIL A<=0

IF THEN GOTO for skipping code

This bypasses a chunk of code. Instead test the opposite condition, and place an ENDIF when the GOTO destination was.

The program should be converted to the conventions of structured programming.

IF (Condition) THEN RETURN, or ENDPROC, Use, IF (Condition) THEN EXIT

Replace:

10 A=1
20 GOSUB 100
30 END
100 ? “Procedure “; A
110 IF A < 0 THEN RETURN
120 ? “OK”
130 RETURN

With:

A=1
EXEC Example
END
PROC Example
  ? “Procedure “; A
  IF A<0 THEN EXIT
  ? “OK”
ENDPROC

* IF (Condition) THEN GOTO pass RETURN with another RETURN...

Replace RETURN with EXIT and last RETURN with ENDPROC or use IF ELSE ELIF ENDIF structure.

Replace:

10 A=1 : GOSUB 100
20 A=2 : GOSUB 100
30 END
100 ? “Proc “;A
110 IF A=1 THEN 140
120 ? “A=”;A
130 RETURN
140 ? “SKIP”
150 RETURN

With:

A=1 : EXEC Tst
A=2 : EXEC Tst

PROC Tst
  ? “Proc “;A
  IF A<>1
    ? “A=”;A
    EXIT
  ENDIF
  ? “SKIP”
ENDPROC