Variables A variable starts with a letter, has up to 32 significant characters, and can include numbers, letters. bob b12 Freemont3 Numeric Constants Numeric constants start with a digit (0-9) and contain any number of digits. The constants can be from 0 to 65535. 0 35 432 7730 String Constants Starting with a " and end with a newline, end of file or ". Strings can be at most 255 characters long. "Hello there" "134" "We all love you Reserved Words There are certain variable names that are reserved for future use: as call case chr close default else end esac for format gosub goto if in input lprint open out output peek poke print readblock return then when writeblock Labels and Line numbers For purposes of goto and gosub, lines can begin with a label or line number: goto Start Red: print "Hello Red." gosub 1000 end 1000: print "How's it going?" return Start: goto Red : -- either a label or line number end -- ends a program goto -- transfers control to the label or number gosub -- transfers control to the label or number until "return" return -- returns from a subroutine call
-- call a machine language subroutine Assigment and math Variables can be assigned constants, variables or the result of any valid expression. bob=5 fred=bob greg=bob+fred Supported operators + addition - subtraction and bitwise and or bitwise or xor bitwise exclusive or not boolean not (results in 1 or 0) = equal < less than >= greater than or equal > greater than <= less than or equal <> not equal (also != or ><) Built in functions chr$( ) -- creates a character from an ascii number input( ) -- reads 1 character from keyboard or file input( , ) -- reads a string from keyboard for file peek(
) -- reads memory in( ) -- reads IO Port Conditionals There are two types of conditional branching supported the IF-THEN-ELSE clause and the CASE-WHEN-DEFAULT-ESAC clause. IF THEN [ ELSE ] is the condition which is true when non-zero (the THEN clause is executed in this situation) If there is an else clause, it is executed when is 0. CASE WHEN : [ WHEN : ... WHEN : ] [DEFAULT: ] ESAC With CASE, the value in is compared with each of the to and the matching WHEN clause statements are executed. If there is no match, then the DEFAULT cluse is executed (if any). Examples if bob then print "Hello bob" if fred-5 then print "What's up?" else print "Hi fred" case greg when 3: print "Greg is 3" when 2: print "This is it my friend." if bob then print "What" when 1: greg=3:bob=2-greg:val=greg+bob+fred default: case val when 2: end when 4: goto Gotya esac esac Input/Output POKE
, -- Change memory OUT , -- System output port PRINT { { | } { ';' | ',' | } }* -- Screen output LPRINT { { | } { ';' | ',' | } }* -- Printer output INPUT var1 {, var2 {, ... , varn } } Disk I/O READBLOCK
, , WRITEBLOCK
, , File I/O OPEN FOR { INPUT | OUTPUT } AS PRINT # , { { | } { ; | , | } }* INPUT # , { , {, ... , } } CLOSE VDP WRITEVRAM ,, READVRAM ,, WRITEREG , Inline Assembly [ ] Example: print "Hello." [ LD HL,1024 LoopHere: DEC HL LD A,H OR L JR NZ,LoopHere ] print "There."