List of useful Atari BASIC commands

List of useful Atari BASIC commands

Atari specs | ASCII chart | conversions | online emulator

Program Flow

  • GOTO [line#] — jump to a new line
  • GOSUB [line#] — jump to a subroutine
  • RETURN — returns from a subroutine
  • ON [##] goto/gosub [line#1],[line#2],[line#3]… — jumps to a line# in the list (1,2,3…)
  • IF [expression] THEN [statement]//[GOTO/GOSUB] [line#] — logic check
    • e.g. IF x=5 then y=0 | IF a$=”abcd” then gosub 100
    • operators include: =, >, <, >=, <=, <>, and, or, not
  • FOR [variable#] = [##] TO [##] {STEP ##}optional — sets up a loop
  • NEXT [variable#] — returns to the top of the loop
    • e.g. for x = 1 to 5 : print x : next x — prints numbers 1 through 5
  • END — stops the program
  • STOP — stops the program displaying a line# error code | mostly for debugging

Variables

Apple uses two letter variables e.g. STored is the same as STopped
There some 2 letter variables you can NOT use:
AT, FN, GR, IF, ON, OR, TO

  • CLEAR — clears all of the variables
  • LET [##/$$] = [##/$$] — assigns a value to a number or string
    • e.g. LET x=0 | LET a$=”abc” | can also use: x=0 or a$=”abc”
  • DEF FN name=[formula] — sets up the function
    • e.g. DEF FN add(x,y)= x+y
  • FN name — calls the function & passes x & y & etc… to it
    • e.g. a= FN add (3,6) — passes 3 & 6 & executes the formula x+y | result is 9

Text

  • PRINT [xx,xx$] or [xx+yy] or [aa$+bb$] or [“abc”] {, or ;}optional [more items]
    • at the end of an item use the ; for close spacing or , for wide or nothing for new line
    • e.g. PRINT “x= “; x | PRINT “hello” | PRINT x*2 | PRINT “go “+”home”
  • INPUT {[“description”;] optional} [xx1,xx1$], [xx2,xx2$], etc…
    • e.g. INPUT x,y | INPUT “name=”; aa$
  • GET [xx,xx$] — waits for a single key-press & sets it to the variable
    • note: a numeric value (X vs X$) you will get an error if you don’t press a # key
  • HOME — clears the screen [some BASIC’s use CLS or CLEAR]
  • HTAB / VTAB [xx] — moves the cursor horizontally or vertically
  • FLASH — starts flashing text
  • INVERSE — starts inverse text
  • NORMAL — resets to normal text

Data Arrays

  • DIM name/name$,{more can be added}
    • e.g. DIM aa$(15) | 2 dimensional array= DIM xx(5,5) | 3D= DIM xx$(5,5,5)
  • DATA [xx,xx$],[xx2,xx2$],etc…
    • sets up the data for variables | can be numbers or text
    • no spaces between commas, quotes around text is not necessary
  • READ variable — loads data into variable (number) e.g. READ x$(2)
  • RESTORE — resets to the first variable in the list i.e. x$(1)

String/Conversion Functions

  • LEN(xx$ or “abc”) — outputs the length (# of characters) of a string
  • LEFT$(xx$ or “abc”],[x) — same, but left characters up to x
  • RIGHT$(xx$ or “abc”],[x) — same, but right characters back to x
  • MID$(xx$ or “abc”],[x],[y) — middle chars starting at x to length y
    • e.g. print mid$(“testing”,2,3) outputs: est
  • ASC(xx$) — gives the ASCII value of first character in xx$
  • CHR$(xx) — gives the character of ASCII # xx
  • STR$(xx) — converts numbers into strings
  • VAL(xx$) — converts numeric strings into numbers | stops if it hits a letter
    • e.g. ASC(“f”) outputs: 102 | CHR$(102) outputs f | VAL(“123a45”) outputs: 123

Math Functions

= , > , < , >= , <= , <>
equal,greater,less,greater or equal,lesser or equal, not equal
, – , * , / , ^
add,subtract,multiple,divide,power
AND , OR , NOT — boolean operators
note the plus(+) sign can be used to put strings together e.g. a$= “ab”+”cd”

  • ABS (xx) — absolute value of xx, always positive
  • ATN (xx) — arc-tangent of xx
  • COS (xx) — cosine of xx
  • EXP (xx) — raise e to xx | e is Euler’s Number = 2.71828
  • INT (xx) — integer part of xx, gets rid of decimals
  • LOG (xx) — natural log of xx
  • RND (xx) — generates a random number between 0 and 1
  • SGN (xx) — sign of xx : -1 for neg #, 0 for zero, 1 for positive #
  • SIN (xx) — sine of xx
  • SQR (xx) — square root of xx
  • TAN (xx) — tangent of xx

Miscellaneous

  • REM [comments] — treats all text after it as a comment (not executable)
  • TRACE / NOTRACE — shows/hides line numbers while running | used for debugging
  • ONERR GOTO [line number] — sends program to a line# if an error occurs
  • RESUME — tries the line that caused an error again (similar to gosub/return)

Atari | ASCII table | Converting


Thank you for stopping by.

home | my recipes | my photos | I’m high