Atari BASIC Essentials: A Practical Starter Guide
Atari BASIC is the language most Atari 8-bit owners met first: on a cartridge with the 400 and 800, and built into the ROM of the XL and XE machines. It is small (8K), friendly, checks your syntax the moment you press RETURN, and gives easy access to the machine's graphics, sound and controllers. This guide gets you from the READY prompt to a complete, working program.
You will learn: how the screen editor works, direct versus program mode, the core statements, variables and strings, loops and decisions, DATA, and the habits that will save you grief later.
You need: any Atari 8-bit computer with Atari BASIC — a 400/800 with the BASIC cartridge in the (left) slot, or an XL/XE with BASIC enabled. An emulator such as Altirra works just as well.
A little background
Atari contracted Shepardson Microsystems in October 1978 to write a BASIC for its upcoming computers. Paul Laughton was the main programmer and Kathleen O'Brien wrote the floating-point routines; Bill Wilkinson drafted the language specification. The floating-point package ended up in the operating system ROM so other programs could use it, which let BASIC itself fit in an 8K cartridge occupying addresses $A000–$BFFF.
Three revisions exist. Revision A shipped on cartridge with the 400 and 800. Revision B was built into early 600XL/800XL machines and has a nasty bug that makes programs grow by 16 bytes every time they are loaded. Revision C, the final version, is in later 800XLs and all XE machines and was also sold on cartridge. Type ? PEEK(43234) at the READY prompt: 162 means revision A, 96 means B and 234 means C.
On XL and XE computers BASIC is switched on automatically unless you hold down OPTION while powering on (which you do when loading many games or other languages).
1. The READY prompt and the screen editor
When BASIC starts you see READY and a cursor. Everything you type goes through Atari's screen editor, which is unusually capable for its time:
- Move the cursor anywhere with CTRL plus the arrow keys, type over what is there, and press RETURN — that line is re-entered as if you had just typed it. This is how you edit program lines:
LISTthem, cursor up, change, RETURN. - CTRL+INSERT / CTRL+DELETE insert or delete a character; SHIFT+INSERT / SHIFT+DELETE insert or delete a whole line; SHIFT+CLEAR clears the screen.
- One logical line can span up to three screen lines.
- Keywords must be in upper case. If you accidentally press CAPS/LOWR and start typing in lower case, BASIC will reject your lines; press SHIFT+CAPS to return to capitals.
BASIC checks each line as you press RETURN. If something is wrong it re-displays the line marked ERROR- (the rest of the line after the point where it gave up is kept as plain text), so typing mistakes are caught immediately rather than at run time.
2. Direct mode and program mode
Type a statement without a line number and it runs immediately:
PRINT 2+2
Put a number from 0 to 32767 in front and it is stored as part of the program instead:
10 PRINT "HELLO, ATARI"
20 GOTO 10
Now type RUN. Press BREAK to stop it; BASIC reports STOPPED AT LINE 10, and CONT carries on from the next line. Other essential commands:
| Command | What it does |
|---|---|
LIST / LIST 10,50 |
Show the whole program or a range of lines |
NEW |
Erase the program in memory |
RUN |
Run from the lowest line number |
CONT |
Continue after BREAK or STOP |
SAVE "D:NAME" / LOAD "D:NAME" |
Save or load to disk (see our saving guide) |
To delete a line, type just its number and press RETURN. Typing a line number that already exists replaces that line. Number your lines in steps of 10 so you have room to insert more later.
Many keywords can be abbreviated with a full stop — GR. for GRAPHICS, SE. for SETCOLOR — and ? is a shorthand for PRINT. Because BASIC stores your program as tokens rather than text, abbreviations are expanded to the full keyword when you LIST.
3. Numbers and variables
All numbers in Atari BASIC are floating-point (stored as six-byte BCD values), so X=10.5 and X=10 are the same kind of thing. Assign with = (the old LET keyword is optional):
10 SCORE=0
20 SCORE=SCORE+100:PRINT SCORE
Variable names may be long and descriptive, must start with a letter, and must not be a BASIC keyword. Names beginning with a keyword can also cause trouble — FORM starts with FOR. A program can use up to 128 different variable names.
Arithmetic uses + - * / and ^ for powers; useful functions include INT, ABS, SQR, SIN/COS (in radians unless you execute DEG) and RND(0), which returns a random number from 0 up to (but not including) 1. A random whole number from 1 to 6 is INT(RND(0)*6)+1.
4. Strings must be dimensioned
Text lives in string variables, whose names end in $. Unlike most BASICs, every string must be declared with DIM giving its maximum length:
10 DIM NAME$(20)
20 PRINT "WHAT IS YOUR NAME";:INPUT NAME$
30 PRINT "HELLO, ";NAME$
Pieces of a string are taken with subscripts — NAME$(1,3) is the first three characters — and LEN(NAME$) gives the current length. There is much more in our string-handling guide.
Numeric arrays also need DIM. DIM A(10) gives eleven elements, A(0) to A(10); DIM B(5,5) gives a two-dimensional table.
5. Printing
PRINT separates items with ; (no space) or , (jump to the next tab stop — every ten columns by default; the spacing is held in location 201, PTABW). A trailing ; keeps the cursor on the same line, which is how you put a prompt in front of INPUT. POSITION X,Y moves the cursor; PRINT CHR$(125) clears the screen.
6. Decisions and loops
IF ... THEN runs the rest of the line only when the condition is true. There is no ELSE: if the test fails, BASIC skips everything after THEN and drops to the next line. Combine tests with AND, OR and NOT; <> means "not equal".
10 PRINT "AGE";:INPUT AGE
20 IF AGE<13 THEN PRINT "CHILD":GOTO 50
30 IF AGE<20 THEN PRINT "TEENAGER":GOTO 50
40 PRINT "ADULT"
50 END
FOR ... NEXT repeats a block, optionally with a STEP (which may be fractional or negative):
10 FOR I=10 TO 1 STEP -1:PRINT I:NEXT I
20 PRINT "LIFT OFF!"
When the loop ends, the variable holds the first value outside the range — 0 in this example.
GOSUB jumps to a subroutine that ends with RETURN; ON N GOTO 100,200,300 and ON N GOSUB ... choose a destination by number.
7. DATA, READ and RESTORE
Fixed lists of numbers or words go in DATA statements and are picked up in order with READ. RESTORE starts again from the first DATA item (or RESTORE 500 from a given line).
10 DIM D$(9)
20 FOR I=1 TO 3:READ D$,T:PRINT D$;" ";T:NEXT I
30 DATA MONDAY,12,TUESDAY,15,WEDNESDAY,9
Most mysterious errors in typed-in programs come from DATA lines — a missing comma or a full stop instead of a comma shifts every value that follows. The error is usually reported on the READ line, not the faulty DATA line.
8. PEEK and POKE
PEEK(address) reads a byte of memory and POKE address,value writes one (0–255). They are your gateway to the hardware. Two harmless ones to try:
POKE 752,1
POKE 710,0
The first hides the cursor and the second turns the GRAPHICS 0 background black. A memory map such as Mapping the Atari lists what each location does.
9. A complete first program
10 REM NUMBER GUESSING GAME
20 DIM A$(1)
30 N=INT(RND(0)*100)+1:T=0
40 PRINT CHR$(125);"I'M THINKING OF A NUMBER FROM 1 TO 100"
50 PRINT "YOUR GUESS";:INPUT G
60 T=T+1
70 IF G<N THEN PRINT "TOO LOW!":GOTO 50
80 IF G>N THEN PRINT "TOO HIGH!":GOTO 50
90 PRINT "YOU GOT IT IN ";T;" TRIES."
100 PRINT "PLAY AGAIN (Y/N)";:INPUT A$
110 IF A$="Y" THEN 30
120 END
Note that the DIM is at line 20, outside the replay loop — DIMensioning the same string twice raises error 9. Also notice IF A$="Y" THEN 30: a line number straight after THEN is an implied GOTO.
Troubleshooting
- ERROR on a line you just typed: look for lower-case keywords, a missing quote, or a keyword used as a variable name.
- ERROR 9: a string or array used before DIM, or DIMmed twice.
- ERROR 8 at an INPUT: letters (or just RETURN) were entered where a number was expected.
- No READY prompt on an XL/XE, or a program complains it cannot find BASIC: check whether BASIC was disabled by holding OPTION at power-on, or whether a cartridge or boot disk took over.
- Program size creeps up between saves: you have revision B; use LIST/ENTER now and then (see our saving guide).
Further reading
- Atari BASIC — Bob Albrecht, LeRoy Finkel and Jerald R. Brown (John Wiley & Sons, 1979): the self-teaching guide packed with early 400/800 systems; revised as Atari BASIC, XL Edition (Wiley, 1985).
- Atari BASIC Tutorial — Robert A. Peck (Howard W. Sams, 1983).
- Inside Atari BASIC — Bill Carris (Reston Publishing Company, 1982).
- Antic's New Owners Column by David Plotkin, a monthly BASIC course that began in the March 1986 issue.
Credits
- comp.sys.atari.8bit FAQ (Michael Current) — 7.2.1 What is Atari BASIC? — Michael Current (comp.sys.atari.8bit FAQ)
- De Re Atari, Chapter 10 — Atari BASIC — Lane Winner (Section 10 of De Re Atari)
- Antic Vol. 5 No. 1 (May 1986) — New Owners Column, Lesson 3: Variables, IF/THEN (David Plotkin) — David Plotkin, 1986
- Antic Vol. 5 No. 9 (Jan 1987) — New Owners Column, Lesson 10: Strings — David Plotkin, 1987
- Atari BASIC Tutorial (Robert A. Peck, Howard W. Sams 1983) — Atari8bit.net, 1983
- Mapping the Atari — locations 201 (PTABW), 99 (LOGCOL) — AtariArchives.org
