diff --git a/reference.htm b/reference.htm index 95d716c..c251f7e 100644 --- a/reference.htm +++ b/reference.htm @@ -51,7 +51,7 @@ This is intended as a quick reference for the Applesoft BASI
CLEAR
Clear all variables
[LET] var = expr
Assign variable -
DIM var( size [ , size2 ...] ) [ , var2( size [ , size2 ...] ) ... ]
Allocate array +
DIM var( size [ , size2 ...] ) [ , var2( size [ , size2 ...] ) ...]
Allocate array(s) with given dimension(s)
DEF FN f(var ) = expr
Define function of a single variable [1]
@@ -59,16 +59,16 @@ This is intended as a quick reference for the Applesoft BASI

Flow Control

-
GOTO
Go to line number -
GOSUB line
Go to subroutine +
GOTO line
Jump to line number +
GOSUB line
Enter subroutine at line number
RETURN
Return from subroutine -
ON expr GOTO line [, line2 ... ]
Branch based on index (value = 1, 2, ...) -
ON expr GOSUB line [, line2 ... ]
Subroutine branch based on index (value = 1, 2, ...) -
POP
Convert last gosub into a goto +
ON expr GOTO line [, line2 ...]
Branch based on index (value = 1, 2, ...) +
ON expr GOSUB line [, line2 ...]
Subroutine branch based on index (value = 1, 2, ...) +
POP
Convert last GOSUB into a GOTO
FOR var = start TO end [ STEP incr ]
Loop with counter variable
NEXT [var [, var ...] ]
End of loop(s) -
IF expr THEN statement
IF expr GOTO line
Conditional; if expr is false, rest of line is skipped -
END
Terminate program +
IF expr THEN statement
IF expr GOTO line
Conditional; if expr is false, rest of line is skipped +
END
Terminate program cleanly
STOP
Break, as if an error occurred
@@ -77,19 +77,20 @@ This is intended as a quick reference for the
Applesoft BASI

Error Handling

ONERR GOTO line
Set error hook -
RESUME
Retry line that caused ONERR GOTO +
RESUME
Retry line that caused ONERR GOTO

Input/Output

-
PRINT expr [ [;,] expr2 ... ] [;]
Output text -
INPUT [string ;] var [, var2 ... ]
Read line of input +
PRINT expr [ [;,] expr2 ... ] [;]
Output text. ; concatenates, + , advances to next tab stop. A trailing ; suppresses line break. +
INPUT [string ;] var [, var2 ...]
Read line of comma-delimited input, with optional prompt
GET var
Read single key
HOME
Clear text display -
HTAB expr
Position text cursor horizontally -
VTAB expr
Position text cursor vertically +
HTAB expr
Position text cursor horizontally (1...40 or 1...80) +
VTAB expr
Position text cursor vertically (1...24)
INVERSE
Set output mode to black-on-white
FLASH
Set output mode to flashing
NORMAL
Set output mode to white-on-black @@ -100,7 +101,7 @@ This is intended as a quick reference for the Applesoft BASI

Miscellaneous

-
REM [ comment ]
Begin a comment; rest of line is skipped +
REM [comment]
Begin a comment; rest of line is skipped
TRACE
Turn on trace mode (line numbers printed)
NOTRACE
Turn off trace mode
@@ -109,8 +110,8 @@ This is intended as a quick reference for the
Applesoft BASI

Inline Data

-
DATA value [, value2 ... ]
Define inline data -
READ var [, var2 ... ]
Read the next DATA value +
DATA value [, value2 ...]
Define inline data +
READ var [, var2 ...]
Read the next DATA value
RESTORE
Restore the DATA pointer to the first value
@@ -118,7 +119,7 @@ This is intended as a quick reference for the
Applesoft BASI

Lo-Res Graphics

-
GR
Set display to lores mode, clear screen +
GR
Set display to mixed test/low resolution ("lores") graphics mode, clear screen to black
COLOR= expr
Set lores color (0...15)
PLOT expr, expr
Plot lores point (x = 0...39, y = 0...39/47)
HLIN expr, expr AT expr
Plot horizontal line (x1, x2 at y) @@ -129,8 +130,8 @@ This is intended as a quick reference for the Applesoft BASI

Hi-Res Graphics

-
HGR
Set display to hires mode, clear screen -
HGR2
Set display to hires mode (page 2), clear screen +
HGR
Set display to mixed/high resolution ("hires") graphics mode, clear screen to black +
HGR2
Set display to full hires mode (page 2), clear screen
HPLOT [TO] expr, expr [ TO expr, expr ] ...
Plot hires point/line (x=0...279, y=0...191)
HCOLOR= expr
Set hires color (0...7)
@@ -196,10 +197,10 @@ This is intended as a quick reference for the
Applesoft BASI
  • POKE 49200,0 - toggle speaker (no-op)
  • POKE 49232,0 - graphics mode
  • POKE 49233,0 - text mode -
  • POKE 49234,0 - full graphics -
  • POKE 49235,0 - split screen -
  • POKE 49238,0 - lores -
  • POKE 49239,0 - hires +
  • POKE 49234,0 - full graphics mode +
  • POKE 49235,0 - mixed text/graphics mode +
  • POKE 49238,0 - lores graphics mode +
  • POKE 49239,0 - hires graphics mode
    CALL expr
    Call native routine @@ -535,7 +536,8 @@ Statement = data-declaration | remark | Command | EmptyStatement Command = identifier /*...*/ | reserved /*...*/ -

    Statements ("commands" in the above grammar) are parsed with distinct cases for each statement type. +

    Due to the irregular structure of the BASIC language, statements ("commands" in the above grammar) +are parsed with distinct cases for each statement type. Most statements compile into a function call to a library of Applesoft routines. Expressions are parsed with a standard recursive descent parser. The parser generates JavaScript expressions for each expression, which are used as arguments for the library calls.

    @@ -544,23 +546,22 @@ which are used as arguments for the library calls.

    Expression = OrExpression OrExpression = AndExpression { 'OR' AndExpression } AndExpression = RelationalExpression { 'AND' RelationalExpression } -RelationalExpression = AdditiveExpression { RelOp AdditiveExpression } -RelOp = '=' | '<' | '>' | '<=' | '=<' | '>=' | '=>' | '<>' | '><' +RelationalExpression = AdditiveExpression { ('=' | '<' | '>' | '<=' | '=<' | '>=' | '=>' | '<>' | '><') AdditiveExpression } AdditiveExpression = MultiplicativeExpression { ( '+' | '-' ) MultiplicativeExpression } MultiplicativeExpression = PowerExpression { ( '*' | '/' ) PowerExpression } -PowerExpression = UnaryExpression [ '^' UnaryExpression ] +PowerExpression = UnaryExpression { '^' UnaryExpression } UnaryExpression = ( '+' | '-' | 'NOT' ) UnaryExpression - | FinalExpression + | FinalExpression FinalExpression = number-literal - | string-literal - | 'FN' user_function_name '(' Expression ')' - | reserved '(' Expression { ',' Expression } ')' - | identifier [ '(' Expression { ',' Expression } ')' ] - | '(' Expression ')' + | string-literal + | 'FN' user_function_name '(' Expression ')' + | reserved '(' Expression { ',' Expression } ')' + | identifier [ '(' Expression { ',' Expression } ')' ] + | '(' Expression ')'

    Since Applesoft supports re-entrant error handling and synchronous input, -the output of the compiler is an array of statement-functions plus a driver +the output of the compiler is an array of statement-functions plus an executor function which implements the logic for walking over the array.

  • @@ -568,19 +569,21 @@ function which implements the logic for walking over the array.

    Extensions beyond Standard Applesoft

    -
      +
      1. - [1] DEF FN supports string and integer functions + DEF FN supports string and integer functions e.g. DEF FN IN$(X$) = " " + X$ - (but return type must still match argument type) + - the return type must match the argument type, so string-to-number or number-to-string functions + can not be implemented.
      2. - [2] == is supported for equality comparisons, in addition to = + "Double equals" == is supported for equality comparisons, with the same meaning as "single equals" =
      3. - [3] When printing characters, CHR$() values greater than 255 generate glyphs that might be useful for certain maze games. + When printing characters, CHR$() values greater than 255 generate glyphs that might be useful for implementing certain maze games. (An earlier version of this page allowed arbitrary Unicode characters to be displayed, but the text is now displayed using bitmaps so that is not possible.)
      4. - [4] HSCRN(x,y) is added to allow reading the - hires screen. On a real Apple this required a machine-language routine (or a shape table and XDRAW). -
    + HSCRN(x,y) is added to allow reading the + hires screen. On a real Apple this required a machine-language routine (or a shape table and XDRAW) and + extensive knowledge of the Apple's color generation scheme. +