Quick reference guide to BASIC 1.0

Søren Roug

Abstract

BASIC 1.0 is the standard BASIC language for Thomson computers (MO5, TO7, etc.), which is the reference for the entire range. This is an implementation of Microsoft BASIC (BASIC-69). On the MO5, the instruction set is reduced and the double precision is not implemented, so that the interpreter fits in only 12 KB of ROM, instead of 16 KB on the TO7.


Table of Contents

Variable types

Type Name Range
Integer AB% -32768 to +32767
Real AB +/- 9.99999 E +38
String AB$ 0 to 255 characters

Where A must be a letter, B and following (up to 255) characters are optional and may be a letter or digit. Only the first 15 characters are significant.

Operators

Symbol Operation
( ) Grouping
- Negation
^ Exponentiation
* / Multiplication (*) and division (/)
@ MOD Integer division (@) and modulus (MOD)
+ - Addition and subtraction
> < = <> >= <= Relational operators
NOT AND EQV IMP OR XOR Logical operators

Logical operator truth table

A B A AND B A EQV B A IMP B A OR B A XOR B
0 0 0 -1 -1 0 0
0 -1 0 0 -1 -1 -1
-1 0 0 0 0 -1 -1
-1 -1 -1 -1 -1 -1 0

System commands

ATTRB X,Y

Defines the height and width of the characters. The possible values are 0 and 1.

CLEAR I[,J[,K]]

Erases all variables and reserves space for string storage, highest address for BASIC and graphical characters.

CLEAR 500
CLEAR 200,25000
CLS

Clears display

CONSOLE top,bottom

Reserves the lines between top and bottom for text.

CONSOLE 5,15
CONSOLE 0,24
DATA

Stores data in program for use by READ statement

DATA January, 31, "Martian History Month".
DEFINT/DEFSNG/DEFSTR A [,B...]

Declares the type of a variable as either integer, real or string.

DEFINT A-B,O-Q defines A,B,O,P and Q as integer
DIM VARNAME(SIZE 1[,SIZE2...])

Dimensions one or more arrays.

DIM X(40),A$(7,6),B(10,2)
END

Terminates program execution. This statement is not required at the end of a program because control flow will end automatically there.

ERL, ERR

When an error has occurred, the function ERR gives the code number and ERL gives the line number in which the error occurred.

ERROR N

Makes it possible to simulate error number N.

EXEC address

Transfers control to machine language programs at address.

FOR VARNAME = START TO END [STEP INCREMENT]

Creates a program loop which is executed, for specified range of values, STEP indicates the increment. If STEP omitted, one is used.

GOSUB

Calls subroutine beginning at specified line number.

GOTO

Causes immediate program branch to specified line number.

IF condition THEN action 1 ELSE action 2

Tests condition. If true performs action 1 and jumps to next line, if false performs action 2.

INPUT [PROMPT;] VAR1, VAR2

Causes program to halt for entry from keyboard. The optional prompt string is followed by a question mark and a space. The user may then enter a series of values separated by commas.

INPUT"ENTER NAME";N$
INPUT A,B,C,D
LET VAR = EXPR

Assigns value to variable. LET is not implemented. Use implied assignment.

A=42
Hw$="HELLO WORLD"
LINE INPUT

Allows input of line from keyboard, including commas. Line is terminated by [ENTER].

LOCATE I,J,K

Place the cursor at location I,J

NEXT [VARNAME]

Returns control to a FOR statement to determine whether the loop should be repeated. If the termination condition has not been met, control will proceed with the line following the FOR statement. If the termination condition has been met, control will proceed with the statement following the NEXT.

ON EXPR GOSUB LABEL1[,LABEL2...]

Multiway branch to specified lines. Upon encountering a RETURN statement, control will return to the statement following the ON GOSUB. The value of EXPR is rounded up or down to the nearest integer, and is used as an index into the list of labels, starting with 1. If the index is less than 1 or greater than the number of labels, control falls through to the next statement.

ON I GOSUB 100,200,300
ON EXPR GOTO LABEL1[,LABEL2...]

Multiway branch to specified lines. The value of EXPR is rounded up or down to the nearest integer, and is used as an index into the list of labels, starting with 1. If the index is less than 1 or greater than the number of labels, control falls through to the next statement.

ON K GOTO 245,187,310
ON ERROR GOTO

Directs control to the specified line if a subsequent error is detected.

ON ERROR GOTO 5000
POKE location,value

Places value in specified memory location. Value must be 0 - 255.

PRINT [EXPR1[;|,]EXPR2[;|,]...]

Prints content of following list on screen. Expressions can be ended with semicolons, commas or nothing. Comma causes tab to next 12 column print zone. Semicolon holds print head position. '?' is a synonym for PRINT.

PRINT"THE ANSWER"
PRINT A,B
PRINT "YOU'VE HAD";T;"TRIES"
PRINT TAB(X)

Moves the cursor to the position given in X. If the cursor is already past, then moves to next line first.

PRINT USING

Prints output in specified format.

# number field
$ dollar sign in front of number.
* fills leading spaces with asterisks.
^ prints in exponential format.
+ causes sign to be printed.
READ VAR1[,VAR2...]

Assigns the next item in a DATA statement to specified variable.

REM TEXT

Allows comments to be inserted in a program. Everything in a line following REM is ignored. The quote (') is a synonym for REM.

RESTORE [LABEL]

Resets the data pointer back to the first item in the first DATA statement or the statement at the specified line number.

RESTORE
RESTORE 200
RESUME

Return to the main program after execution of error subroutine.

RETURN

Returns the program from subroutine to the statement following GOSUB.

STOP

Halts execution of program at line containing STOP. Variables are not cleared, so that they can be inspected for debugging purpose. Use CONT to continue execution.

BEEP

Sounds a "beep".

PLAY string

Plays music string made of following:

DO, RE, MI, FA, SO, LA, SI - note
On - octave, n=1 to 5
An - attack, n=0 to 255
Ln - note length, n=1 to 96
Pn - pause, n=1 to 255
Tn - temp, n=1 to 255
Also allows sharps (#) or flats (b).
PC keyNORMALBASIC
Pause/Break STOP INSTR
Home BACK MERGE
Delete EFF SAVE
Insert INS  
Control CNT  
Escape RAZ CLS
SHIFT (left) SHIFT  
SHIFT (right) BASIC  
F11 ACC INKEY$
Number Code Explanation
1 NF NEXT without FOR. Usually occurs when NEXT statements are reversed in a nested loop.
2 SN Syntax Error. Usually caused by typing errors or incorrect punctuation.
3 RG RETURN without GOSUB. Program has most likely fallen through the end of the routine, (use END) or a branch has been made into the subroutine.
4 OD Out of Data. A READ statement has read all the DATA statements.
5 FC Illegal Function Call. Usually parameter is out of range or the wrong variable type.
6 OV Overflow. The number is too large for the computer to handle.
7 OM Out of Memory. All available memory is being used or has been reserved.
8 UL Undefined Line. A branching statement has been directed to a line that does not exist.
9 BS Bad Subscript. Usually because the value of subscript is greater than the declared dimension of the array.
10 DD Attempt to redimension an array. Arrays can only be dimensioned once in a program.
11 /0 Division by zero. Not possible.
12 ID Illegal Direct Statement. Attempt to use a statement which can only be used in a program e.g. INPUT.
13 TM Type Mismatch. Attempt to assign string data to numeric variable or vice versa.
14 OS Out of String Space. Use CLEAR to create more space if available.
15 LS String too long. Maximum is 255 characters.
16 ST String formula too complex. Break the operation into smaller steps.
17 CN Can't Continue. Trying to use CONT when at END of a program.
18 UF Undefined User Function.
19 NR No RESUME. The RESUME instruction is required if an ON ERROR GOTO is located in the program.
20 RE RESUME Without Error.
21 EC ERROR with illegal error code argument.
22 MO Missing Operand
23 FN For Without Next.
50 NU Not In Use.
51 FM Bad File Mode. Trying to INPUT from a file which is OPEN for output (O), or PRINT data to a file OPEN for input (I).
52 AO Attempt to open a file which is already open. Usually appears after pressing STOP to stop a program using files.
53 IO Input/Output Error. Cassette not adjusted correctly or bad tape.
54 IE Input Past End. Attempt to input past the end of a file. Use EOF function to check this does not happen.
55 FD Bad File Descriptor.
56 DS Direct Statement. Usually appears if you attempt to LOAD a data file.
57 NO File Not Open. Input and output to a data file can only take place after OPEN.
58 BD Bad Data. Caused by trying to read string data into numeric variable.
59 IU Device In Use.
60 DU Device Unavailable.
61 PP Protected Program.