BASIC-G reference
Every command, function and operator in BASIC-G — the graphics BASIC Tesla shipped in the PMD 85-2's plug-in ROM module.
In this reference: Hardware · Escape codes · File formats · Argument notation
Notes and caveats
- BASIC-G is a Microsoft 8K BASIC derivative, so most of the vocabulary below will look familiar. Four differences will not:
- the user-defined-function keyword is
FNC, and the name is a separate word:DEF FNC A(X)=X*2is called asFNC A(3); ?is notPRINT. It stores the token whose spelling is_, which prints into the dialogue line and then waits for a key — so a?typed in lists back as_;- a hexadecimal literal is written with a leading apostrophe, as
'FF; - line numbers stop at 32767, not 65529.
- the user-defined-function keyword is
- Multiple statements per line are allowed with
:. Spaces are ignored outside strings,REMandDATA, soFORI=1TO10is valid — and the other side of that rule is that a keyword is recognised inside a name, so a variable calledMYVALcontainsVALand is rejected as a syntax error. - Only the first two characters of a variable name are significant, so
ABCDandABZZare one variable — but case matters:Aandaare two, which no other Microsoft BASIC in this IDE does.$is the only type suffix. ^is the power operator and it folds left to right, so2^3^2is64.AND,ORandNOTcombine their operands bit by bit, and a true comparison is-1.USR(addr)calls the address itself rather than a vector poked in beforehand, which is where BASIC-G parts company with the Microsoft BASICs it descends from.- The tape commands take a file number, not a name:
SAVE 1, andSAVE "A"answers with a type error. INKEYreads only the twelve function keysK0–K11, reporting 255 when none is held. Anything else has to come throughINPUT, a line at a time.
Command Function Operator
| Syntax & description | |
|---|---|
_? | _ [<expr>][;|,]…DISP, and then waits for a key. This is what a `?` typed into the editor stores - on this machine `?` is not PRINT, and a program using it lists back with `_`. |
- | <number> - <number>Subtracts, or negates a single operand. |
* | <number> * <number>Multiplies. |
/ | <number> / <number>Divides, in floating point: 7/2 is 3.5, and there is no integer division operator. |
^ | <number> ^ <number>Raises to a power. It folds left, as every Microsoft BASIC does: 2^3^2 is 64, not 512. |
+ | <expr> + <expr>Adds two numbers, or joins two strings end to end. |
< | <expr> < <expr>Less than. Combined with = and > it spells <=, >= and <>, which BASIC-G stores as two tokens rather than one. |
<= | <number> <= <number> | <string> <= <string>Less than or equal. BASIC-G stores it as the two operator tokens side by side rather than as one of its own, so =< is the same comparison. |
<> | <expr> <> <expr>Not equal, stored as two tokens like <=. |
= | <expr> = <expr>Equality inside an expression, and assignment at the head of a statement - one token doing both jobs. |
> | <expr> > <expr>Greater than, giving -1 for true and 0 for false. Strings compare by character code, left to right. |
>= | <number> >= <number> | <string> >= <string>Greater than or equal, stored as two tokens like <=. |
ABS | ABS(<number>)The absolute value: the argument with any sign removed. |
ADR | ADR(<var>)The address a variable’s value is stored at, so machine code can be handed something to work on. |
AND | <number> AND <number>Bitwise AND of two 16-bit two's complement values, which is also how conditions are combined: a true comparison is -1, all bits set. |
APEEK | APEEK(<addr>)PEEK for 16-bit words, reading low byte first - the counterpart of APOKE. |
APOKE | APOKE <addr>, <number>[, <number>]…POKE for 16-bit words: each value is written low byte first, as the 8080 stores an address. |
ASC | ASC(<string>)The character code of the first character. An empty string stops with an error. |
AT | PRINT AT <row>, <col>Inside a PRINT list, moves the print position to a text cell. The text area is 48 columns by 26 rows. The firmware lands AT one scanline below the row a plain PRINT uses, so text placed this way sits a pixel low against text that scrolled into place. |
ATN | ATN(<number>)The arctangent, giving an angle in the current unit between -pi/2 and pi/2. |
AUTO | AUTO [<line>[, <number>]]Numbers entered lines automatically from a starting line and step, until the STOP key ends it. |
AXES | AXES <x>, <y>Draws both axes crossing at a point, with tick marks at the given intervals, inside the current SCALE window. |
BEEP | BEEPA short tone on the motherboard speaker. It is the whole sound repertoire: there is no pitch or duration to give. |
BIT | BIT(<number>, <bit>)One bit of a value, as 0 or 1, counting from bit 0. BASIC-G has this where Microsoft 8K BASIC has an unused table slot. |
BMOVE | BMOVE <x>, <y>Sets the cursor BPLOT writes at, in screen memory rather than in SCALE coordinates. |
BPLOT | BPLOT <string>, <number>Writes the bytes of a string straight into video RAM from the BMOVE cursor - six pixels per byte, which is how a sprite is drawn here. |
CHECK | CHECK <tapefile>Reads a tape file back and compares it with what is in memory, without loading it - the verify pass after a SAVE. |
CHR$ | CHR$(<byte>)A one-character string of the given code. 7Fh is the solid cell, the one glyph outside ASCII the character generator holds. |
CLEAR | CLEARErases the variables and arrays and closes any open FOR and GOSUB, leaving the program itself alone. |
CODE | CODE <string>[, <string>]…Assembles machine code written as hexadecimal digits in a string, into a scratch area at 7F00h, and calls it. |
CONT | CONTResumes a program stopped by STOP or by the STOP key, from the statement after it. Editing any line first makes it impossible. |
CONTROL | CONTROL <channelno>, <number>, <byte>[, <byte>]…Writes bytes to a device’s control port, which is how a channel is configured before OUTPUT or ENTER uses it. |
COS | COS(<number>)The cosine. The angle is in radians unless DEG has been used. |
DATA | DATA <constant>[, <constant>]…Inline constants for READ to consume in program order. The rest of the statement is stored exactly as typed, spaces included. |
DEF | DEF FNC <name>(<param>) = <expr>Defines a one-line function. The keyword is FNC rather than the FN every other Microsoft BASIC uses, and the definition must run before the first call. |
DEG | DEGTakes the angle arguments of SIN, COS, TAN and ATN in degrees, until RAD switches back. |
DIM | DIM <var>(<number>[, <number>]…)Declares an array and its bounds. Subscripts start at 0, so DIM A(10) gives eleven elements; an array used without DIM is created with bounds of 10. |
DISP | DISP [<expr>][;|,]…Prints into the dialogue line at the foot of the screen rather than into the scrolling text area, leaving what is above it untouched. |
DLOAD | DLOAD <tapefile>;<numvar>(<number>)Loads an array back from tape, filling it from the named element on. The separator is a semicolon, not a comma. |
DSAVE | DSAVE <tapefile>;<numvar>(<number>)Records an array to tape from the named element on - data rather than program, which SAVE cannot carry. The separator is a semicolon, not a comma. |
END | ENDStops the program and returns to the OK prompt without a message; unlike STOP, the run cannot then be resumed with CONT. |
ENTER | ENTER <channelno>;<var>[, <var>]…Reads values in from an I/O channel, as INPUT does from the keyboard. |
ERR | ON ERR GOTO <line>Traps errors: after this, an error jumps to the given line instead of stopping the program. BASIC-G has this where Microsoft 8K BASIC has CONT. |
EXP | EXP(<number>)e raised to the given power, the inverse of LOG. |
FILL | FILL <x>, <y>;<byte>Plots a byte as an enlarged bit pattern at a point - the machine’s way of hatching an area or drawing a fat marker. |
FNC | FNC <name>(<arg>)Calls a function defined by DEF. The name is separate from the keyword, so a call reads FNC A(X) rather than the FNA of other Microsoft BASICs. |
FOR | FOR <numvar> = <number> TO <number> [STEP <number>]Opens a counting loop that runs up to the matching NEXT. STEP sets the increment (default 1, may be negative or fractional); the body always runs at least once. |
FRE | FRE(<number>)Bytes left between the end of the arrays and the stack. The argument is ignored; string space is a separate region and is not counted here. |
GCLEAR | GCLEARClears the whole screen - text and graphics alike, since they are the same bitmap - and homes the print position. |
GOSUB | GOSUB <line>Calls a subroutine, remembering where to come back to. RETURN comes back to the statement after this one. |
GOTO | GOTO <line>Jumps to a line number. BASIC-G reads it across a space as well, so GO TO 100 is the same statement. |
HEX$ | HEX$(<number>)A number as four hexadecimal digits. The matching input form is a literal written with a leading apostrophe, as in ’FF. |
IF | IF <number> THEN <line> | <statement>Runs the rest of the line, or jumps to a line number, when the condition is non-zero. There is no ELSE: invert the test and jump, or write a second IF. |
INK( | INK(<colour>)Inside a PRINT list, sets the same two attribute bits for the text that follows it. |
INKEY | INKEYWhich function key K0-K11 is held, or 255 when none is. This is the machine’s key-at-a-time read, and it sees only that row of keys. |
INP | INP(<port>)Reads a byte from an input port. |
INPUT | INPUT <var>[, <var>]…Prints ? into the dialogue line and waits for a whole typed line. Unlike other Microsoft BASICs it takes no prompt string - INPUT "SEED";S is a syntax error, so print the prompt first. For a key at a time, use INKEY or the K0-K11 function keys. |
INT | INT(<number>)The largest whole number not greater than the argument, so INT(-2.5) is -3 rather than -2. |
LABEL | LABEL <x>, <y>;<expr>Plots text at a point in the drawing coordinates, so a chart can be annotated where PRINT would only reach a text cell. |
LEFT$ | LEFT$(<string>, <length>)The leftmost characters of a string. |
LEN | LEN(<string>)How many characters a string holds. |
LET | LET <var> = <expr>Assigns a value. The keyword is optional - A=1 and LET A=1 are the same statement and store the same bytes. |
LIST | LIST [<line>]Lists the program, or one line of it, to the screen. Tokens come back as their full spellings, so a `?` typed in lists back as `_`. |
LLIST | LLIST [<line>]Lists a line into the dialogue line ready for editing, rather than to a printer as the same spelling does on a Microsoft machine. |
LOAD | LOAD [CODE] <tapefile>Loads a program from tape by number, or with CODE a block of machine code. The argument is a number, not a name: LOAD "A" answers with a type error. |
LOG | LOG(<number>)The natural logarithm - there is no LN, and no base-10 log: divide by LOG(10). |
MID$ | MID$(<string>, <start>[, <length>])A substring from the given position, counting from 1; without a length, everything to the end. It cannot be assigned to. |
MOVE | MOVE <x>, <y>Moves the drawing point without drawing anything - where a line should start rather than continue. |
NEW | NEWErases the program and all its variables. |
NEXT | NEXT [<numvar>[, <numvar>]…]Closes the innermost FOR loop and jumps back to it. Naming the variable closes that loop specifically, and several may be closed in one statement. |
NOT | NOT <number>Bitwise complement of a 16-bit two's complement value, so NOT 0 is -1 and NOT -1 is 0. |
NULL | NULL <number>How many null characters to send after each line ending - padding for a printer whose carriage needs the time. |
ON | ON <number> GOTO | GOSUB <line>[, <line>]…Jumps or calls the nth line in the list, counting from 1. A value of 0, or one past the end of the list, falls through to the next statement. |
OR | <number> OR <number>Bitwise OR, on the same terms as AND. |
OUT | OUT <port>, <byte>Writes a byte to an output port. |
OUTPUT | OUTPUT <channelno>;<expr>[;|,]…Prints down an I/O channel on the expansion board rather than to the screen - the printer or the serial line. |
PAUSE | PAUSE [<number>]Waits for roughly the given number of TENTHS of a second - the interpreter’s delay loop is about 0.1s per unit, so PAUSE 10 is a second and PAUSE 200 is over three minutes. The count runs to 255 and a larger one is a parameter error; PAUSE 0, and a bare PAUSE, mean 256 rather than none. Pressing STOP or SPACE cuts the wait short. This is the machine’s delay statement; WAIT is not one. |
PEEK | PEEK(<addr>)Reads one byte of memory. Video RAM starts at C000h and the Monitor ROM at 8000h. |
PEN | PEN <penmode>Sets what the drawing statements write into the two attribute bits of each cell: 0 plain, 1 blinking, 2 dim, 3 both. |
PLOT | PLOT <x>, <y>[, <penmode>][; <x>, <y>]…Draws a line from the last point to this one, then leaves the point there. Several coordinate pairs may follow on one statement, which is how a polyline is drawn. |
POKE | POKE <addr>, <byte>[, <byte>]…Writes bytes to consecutive addresses. The interpreter itself lives in RAM from 0, so a wrong address here can take BASIC-G down with it. |
POS | POS(<number>)The column the print position is in. The argument is ignored. |
PRINT | PRINT [<expr>][;|,]…Prints to the text screen. A trailing ; stays on the line and , moves to the next print zone; AT and INK( inside the list move the cursor and set the attribute. |
RAD | RADTakes the angle arguments of SIN, COS, TAN and ATN in radians. This is the state a cold start begins in; DEG switches to degrees. |
READ | READ <var>[, <var>]…Takes the next constants from the DATA statements, in program order, and assigns them. Running past the last one stops with an out-of-data error. |
REM | REM <comment>A comment. The rest of the line is stored verbatim and never executed, so a GOTO into it simply falls through to the next line. |
RESTORE | RESTOREPuts the READ pointer back at the first DATA constant in the program, so the same list can be read again. |
RETURN | RETURNReturns from the innermost GOSUB. Reaching one without a matching GOSUB stops with an error. |
RIGHT$ | RIGHT$(<string>, <length>)The rightmost characters of a string. |
RND | RND(<number>)A pseudo-random number below 1. A positive argument gives the next in the sequence, 0 repeats the last one, and a negative argument reseeds. |
ROM | ROM <number>Copies a numbered block out of the ROM module - the same 8255 that BASIC-G itself arrived through - to 7000h and calls it. |
RUN | RUN [<line>]Clears the variables and starts the program, from the given line if there is one. This is how the IDE starts a program: it types RUN at the emulated keyboard. |
SAVE | SAVE <tapefile>Records the program to tape under a number. |
SCALE | SCALE <x>, <x>, <y>, <y>Sets the coordinate window the drawing statements work in, as left, right, bottom and top. Everything plotted afterwards is mapped from it onto the 288x256 screen. |
SGN | SGN(<number>)The sign of a number: -1, 0 or 1. |
SIN | SIN(<number>)The sine, on the same terms as COS. |
SPC( | SPC(<number>)Inside a PRINT list, prints that many spaces - a relative move, where TAB( is an absolute one. |
SQR | SQR(<number>)The square root. A negative argument stops with an error. |
STATUS | STATUS(<channelno>, <number>)Reads one register of an I/O device, for a program that has to know whether the channel is ready. |
STEP | FOR <numvar> = <number> TO <number> STEP <number>The increment of a FOR loop. It may be negative or fractional, and is 1 when the loop does not say. |
STOP | STOPHalts the program with a message naming the line, leaving the variables intact so CONT can resume from the next statement. |
STR$ | STR$(<number>)A number formatted as BASIC-G would print it, leading space and all. |
TAB( | TAB(<col>)Inside a PRINT list, moves the print position to an absolute column. Going backwards has no effect - the position only ever moves right. |
TAN | TAN(<number>)The tangent, on the same terms as COS. |
THEN | IF <number> THEN <line> | <statement>Introduces what an IF does when its condition holds, and only ever part of one. |
TO | FOR <numvar> = <number> TO <number>The limit of a FOR loop, and only ever part of one. |
USR | USR(<addr>)Calls machine code at an address and returns what it leaves behind. The routine must end in RET, and runs as 8080 code. |
VAL | VAL(<string>)The number a string begins with, or 0 when it does not begin with one. |
WAIT | WAIT <port>[, <mask>], <number>Spins reading an input port until its masked value matches. Not a delay: with nothing on the port to change it, the program stops there for good. |
Argument notation
Anything in <angle brackets> is a value you supply; everything else is typed exactly as shown. [square brackets] mark an optional part, | separates alternatives, and … means the part before it can repeat. The arguments on this page are:
<number>- a numeric expression
<string>- a string expression
<expr>- a value of either type, where the keyword takes both
<byte>- a value from 0 to 255
<constant>- a literal number or string, not an expression
<var>- a variable of either type
<numvar>- a numeric variable
<line>- a line number
<statement>- one BASIC statement
<comment>- free text, to the end of the line
<name>- a name the program defines for a function or procedure
<param>- a parameter, where the definition introduces it
<arg>- a value, where the call passes it
<start>- the position something starts at, counting from 1
<length>- how many characters
<x>- a horizontal graphics coordinate
<y>- a vertical graphics coordinate
<col>- a text column
<row>- a text row
<colour>- a colour, by number
<addr>- a memory address
<port>- an input/output port, by number
<mask>- a bit mask, one bit per item
<bit>- a bit position, counting from 0
<penmode>- a drawing colour and mode, as PEN sets it
<tapefile>- a tape file, by the number it is recorded under
<channelno>- an input/output channel on the expansion board, by number
Showing 109 of 109 keywords