HOME          ABOUT US          LINKS          GUESTBOOK        REGISTER

WWW.8BIT-MICRO.COM                           ONLINE VINTAGE COMPUTER MAGAZINE                                                                    

TRS80 Level I Basic Language Reference


The following is a chart outlining the basic commands and parameters used in the TRS-80 Level I Basic.  This is

an excerpt of a tutorial provided by Jeff Vavasour, who has included on his site an online Basic interpreter using

Java.. very clever.  Jeff is also a prolific programmer who has an excellent TRS-80 Model IV emulator, which I

bought commercially from Computer News 80 many years ago.  This excerpt is included here for your enjoyment,

with the hope that it inspires you to get our out TRS-80 and start writing code.  The commands for TRS-80 Level II

are similar but their are differences.  In time you will see those explanations here on 8bit-Micro.com.


Command Abbreviation Description
LIST [n] L. [n] List program lines starting with line n (or the first program line if n is omitted). Up to 12 lines are listed initially. If there are more than 12 lines from line n on, the list will pause. You may scroll through the remaining lines, one at a time, by pressing the Up Arrow or hitting "^" (that's the carat which is Shift+6 on most keyboards). Pressing ENTER or ESCAPE will end the list and return you to the READY prompt. If there are only 12 lines or less, you will go to the READY prompt automatically.
RUN [n] R. [n] Start running your program from line n. If n is omitted the program will start at the first line. Note: variables are not cleared when you run a program.
NEW N. Erase all lines of the current program from memory. Variables are not cleared.
CONT C. Continue a program that has been interrupted by pressing ESCAPE. The program resumes where it left off. You cannot continue a program if you have edited it. In that event, you'll have to restart your program by typing RUN.
CLOAD CL. In the original Level I BASIC, this loaded a program from casssette.
CSAVE CS. In the original Level I BASIC, this saved your program to a casssette.
Statement Abbreviation Description

Output and graphics commands

CLS none Clears the screen and moves the cursor back to the upper left hand corner.
PRINT [...] P. [...] Prints a message or the contents of a variable. Can also be used to position the cursor. Full syntax details are listed separately below.
SET(x,y) S.(x,y) Draws a pixel at the screen coordinate (x,y) where (0,0) is the upper-left corner, (127,0) is the upper-right corner, and (127,47) is the lower right corner.
RESET(x,y) R.(x,y)
Equivalent to SET, but clears the pixel at (x,y) (i.e. sets it to black). If used as an immediate command (i.e. at the READY prompt without being preceeded by a line number) you should use the RE. abbreviation instead of R. so as to avoid confusion with RUN.
Statement Abbreviation Description

Setting variables

LET v = x L. v = x
v = x
Set variable v (can be a numeric variable A-Z, an array element A(n) or a string A$ or B$) to the value or expression x. (e.g. "LET A=2:LET B=1/A:LET A$=DOG") With strings, quotes are not necessary if it is the last statement on a line and the string value does not contain a comma. The word LET may be omitted, as it is implicit when the = sign follows a variable name at the start of statement..
INPUT ["message";] v[, v2][, v3][...] I. ["message";] v[, v2][, v3][...] Optionally prints message, then prints a question mark ("?") and waits for the user to type a response (followed by ENTER). The user's input is then assigned to v. (The user can type a number, a string, or an expression. e.g. typing "1/2" in response to "INPUT A" will set A=.5.) If multiple variables are specified, then the user should enter multiple values, separated by commas. (e.g. responding "2,5" to " INPUT A, B" will set A=2 and B=5.)
READ v[, v2][, v3][...] none Starting at the top of the program, the READ statement scans the program for DATA statements. When a DATA value is found, it is assigned to v. The next one is assigned to v2 (if a second variable is specified), the third to v3 (again, if specified). Subsequent READs will pick up where the last one left off (even if it was in the middle of a single DATA statement). An error will occur if a READ is issued and all DATA has already been READ. Use RESTORE to start READ from the beginning of the program again.
DATA value1 [,value2] [,value3] D. value1 [,value2] [,value3] Specifies data for the READ statements. values can be numbers or strings. (If value is a string and the variable v in READ v is a numeric variable, the result will not be useful.) If the program reaches a line containing a DATA statement, execution continues on to the next line, passing harmlessly through the DATA statement. There can be no statements following a DATA statement on the same line (e.g. separated by a colon). Everything on a single line that comes after the DATA statement is interpreted as data.
RESTORE REST. Rewinds the internal pointer so that the next READ will start looking for the first DATA value from the beginning of the program.
Statement Abbreviation Description

Flow control

REM none Everything after the REM ("remark") statement on a given line is ignored. Execution continues on to the next line after the REM statement. This is useful if you want to insert comments, reminders or explanations into your program.
END E. Stops the program and returns to the READY prompt.
STOP ST. Makes BASIC act as if the ESCape key had been pressed (which halts the program and displays the command prompt). The user can manually resume execution at the next statement after the STOP by typing CONT at the READY prompt. Useful for debugging.
FOR v = a TO b [STEP c] F. v = a TO b [S. c] Indicates the start of a counting loop. Numeric variable v (which represents a variable A-Z or an array element A(n)) is set to the value a. When a NEXT statement is encountered, the value c is added to v and compared to b. If c is positive and the new v is less than or equal to b, execution returns to the first line following the matching FOR statement. (If c is negative, the program loops back if v is greater than or equal to b.) Note: there will always be at least one pass through the loop. Whether v is in range or not is not tested until the NEXT statement is encountered. Multiple FOR/NEXT statements may be nested (e.g. "FOR X=0 TO 127:FOR Y=0 TO 47:SET(X,Y):NEXT Y:NEXT X"). However, the variable NEXTs must name the variables in the reverse order to the FORs. (e.g. in the preceeding example, ending it with "NEXT X:NEXT Y" would lead to an error.)
NEXT v N. v See the FOR statement for details. Note: unlike some other versions of BASIC, the variable v cannot be omitted in the NEXT statement, and forms combining multiple variables in a single statement (e.g. "NEXT Y,X") are not valid. Also, NEXT cannot be used as an immediate command (i.e. typed at the READY prompt without a line number so that it will execute immediately). In fact, N. at the READY prompt means "NEW", not "NEXT".
IF expression [THEN] statement IF expression [T.] statement expression is evaluated. If it is true or non-zero, statement is executed. statement can be any statement or combination of statements separated by colons. e.g. IF A=21 PRINT"BLACKJACK!" or IF (R>5)*(A<=21) THEN PRINT"PUSH". (The latter example reads as "if R is greater than 5 and A is less than or equal to 21". Replacing the * with a + would replace the "and" with an "or".) As a shorthand, if statement is "GOTO l", you can simply write the line number alone (e.g. "IF A<=21 THEN 300" instead of "IF A<=21 THEN GOTO 300").
GOTO l G. l Go to line l. Sets the next statement to execute to be line l.
GOSUB l GOS. l Similar to GOTO, but when a RETURN is encountered, the program will resume at the next statement following the GOSUB. (e.g. '10 GOSUB 20:PRINT"THERE":END' followed by '20 PRINT"HELLO":RETURN' will print "HELLO" followed by "THERE".)
ON x GOTO l1[, l2][, l3][...] ON x G. l1[, l2][, l3][...] Evaluates the numeric expression x, truncating anything after the decimal. If the result is 1, the program goes to line l1. If it is 2, the program goes to l2, etc. If x is out of range (less than 1 or greater than the number of entries in the list), the statement is ignored.
ON x GOSUB l1[, l2][, l3][...] ON x GOS. l1[, l2][, l3][...] Same as ON ... GOTO except that a GOSUB l1 is executed if the result is 1, GOSUB l2 if the result is 2, etc.
Statement Abbreviation Description

File input/output

INPUT# v[, v2][, v3][...] I.# v[, v2][, v3][...] Same as INPUT except that instead of prompting the user, the data is read from a file.
PRINT# v [;","; v2] [;",";v3] [...] P.# v [;","; v2] [;",";v3] [...] PRINT# is used to write variables (strings, numeric variables and/or array elements) to a file which will then be read back by INPUT#. Note the format requires that multiple variables be separated by ;","; so that a comma is written between the elements.
Function Abbreviation Description
RND(x) R.(x) Returns a random whole number between 1 and x. If x is zero it returns a random decimal number between 0 and 1.
ABS(x) A.(x) Returns the absolute value of x (i.e. removes the negative sign if the number is negative).
INT(x) I.(x) Returns the integer portion of a value x (i.e. removes the fraction after the decimal).
MEM M. Returns a number indicating how many bytes of memory are still free. (i.e. not taken up by your program.) The largest array index n which may be used in the array variable A(n) is INT(MEM/4-1).
POINT(x,y) P.(x,y) If there is a pixel set at co-ordinate (x,y), this function returns a 1. If the pixel at (x,y) is off (black), this function returns a 0. Pixels are turned on or off via the SET or RESET statements, respectively.

Mathematical Operations Used in Level I Basic

Operation Description
x * y Multiplies x by y.
x / y Divides x by y.
x + y Returns the sum of x and y.
x - y Returns the difference x minus y.
x = y Returns a 1 if x equals y. Otherwise the result is 0.
x < y Returns a 1 if x is less than y. Otherwise the result is 0.
x > y Returns a 1 if x is greater than y. Otherwise the result is 0.
x <= y or x =< y Returns a 1 if x is less than or equal to y. Otherwise the result is 0.
x >= y or x => y Returns a 1 if x is greater than or equal to y. Otherwise the result is 0.
x <> y or x >< y Returns a 1 if x does not equal y. Otherwise the result is 0.


Where x and y must be either a numeric variable or an array element.  Testing of a string's equality is not supported

Level I BASIC.


Multiplication and division are evaluated prior to addition and subtraction. And, all four of these math operations are

evaluated before the <, =, and > comparisons. Parantheses can be used to override this order of operations.

  For example:

The expression Evaluates as
1-3/4 0.25
(1-3)/4 -0.5
1<4 1
0.5>=0.7 0
(1<4)*(0.5>=0.7) 0


Note for programmers from other languages: The IF statement will execute the statement that follows the THEN only

if the expression evaluated is non-zero. Since a*b will be non-zero only if a and b are both non-zero, "*" works like a

logical AND. Similarly, since comparisons return an unsigned number a+b will be non-zero when either of a or b are

non-zero. So, "+" can be used as a logical OR. 


Using the PRINT statement:


PRINT is a very flexible command. At its basic level it can output a message or the contents of a variable. For



Statement What you see on display
PRINT 27*6/9-40 -22


If you end your PRINT statement with a semicolon, the next PRINT statement (or INPUT statement) will continue on

the same line, rather than starting on the next line. e.g. PRINT"HELLO ";:PRINT"THERE" will print the message

"HELLO THERE" on a single line.


You can also combine PRINT statements with the semicolon. For example A=3:PRINT"A=";A will print the message

"A= 3 ". (There is a space between the equal sign and the 3 as that is where the sign would go if the number were



TABs: You can also include the function TAB(x) which will position the cursor to column x of the current line before it

prints anything. For example, PRINT TAB(29);"CENTRE" will print the word CENTRE in the centre of the line. (Each

line is 64 characters wide and x can be in the range 0-63. If the cursor is already to the right of the requested

column, the text will print at the cursor position. Remember, if you don't end your PRINT statement with a ";",

subsequent PRINTs start at the beginning of a new line).


Positioning the cursor anywhere: There are 16 lines in the Simulator window, each 64 characters wide. You can

use the statement PRINT AT x;... to position the cursor anywhere on the screen prior to printing. In this case x is a

number from 0 to 1023. 0 represents the upper-left corner, 64 the beginning of the second line, 128 the beginning of

the third line, etc. down to 1023 which is the lower-right corner. (Note: if you position near the bottom there may not

be enough room for what you wish to print. If this happens the screen will scroll.) The general formula is x = 64*r + c

where r is the row (from 0-15) and c is the column (from 0-63). PRINT AT 541;"MIDDLE" will print the word MIDDLE

starting 8 rows down from the top, 29 columns from the left. You can also use PRINT AT to position where the

INPUT prompt is printed (e.g. "PRINT AT 541;:INPUT A$"). 


Colour Chart:

Below is a chart of the colour values used by the COL. command and returned by the CPOINT(x,y) function. The

colours follow a pattern analogous to the CGA graphics palette.


0 black* 4 dark red 8 dark grey 12 light red
1 dark blue 5 dark magenta 9 light blue 13 light magenta
2 dark green 6 brown 10 light green 14 yellow
3 dark cyan 7 light grey 11 light cyan 15 white


*Colour 0 (black) is a valid return value for CPOINT(x,y) but it may not be used as a parameter for the COL.

command. If you want to draw pixels in black, use RESET instead of SET. If you want to draw text in black on

another colour background, use INVERSE. If you want to draw black text on a black background, use spaces

instead and pretend.



(c) 2004, 2005, Brian K. Hahn

 All Rights Reserved.