Skip to content

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*2 is called as FNC A(3);
    • ? is not PRINT. 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.
  • Multiple statements per line are allowed with :. Spaces are ignored outside strings, REM and DATA, so FORI=1TO10 is valid — and the other side of that rule is that a keyword is recognised inside a name, so a variable called MYVAL contains VAL and is rejected as a syntax error.
  • Only the first two characters of a variable name are significant, so ABCD and ABZZ are one variable — but case matters: A and a are 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, so 2^3^2 is 64. AND, OR and NOT combine 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, and SAVE "A" answers with a type error.
  • INKEY reads only the twelve function keys K0–K11, reporting 255 when none is held. Anything else has to come through INPUT, 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 <=.
ABSABS(<number>)
The absolute value: the argument with any sign removed.
ADRADR(<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.
APEEKAPEEK(<addr>)
PEEK for 16-bit words, reading low byte first - the counterpart of APOKE.
APOKEAPOKE <addr>, <number>[, <number>]…
POKE for 16-bit words: each value is written low byte first, as the 8080 stores an address.
ASCASC(<string>)
The character code of the first character. An empty string stops with an error.
ATPRINT 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.
ATNATN(<number>)
The arctangent, giving an angle in the current unit between -pi/2 and pi/2.
AUTOAUTO [<line>[, <number>]]
Numbers entered lines automatically from a starting line and step, until the STOP key ends it.
AXESAXES <x>, <y>
Draws both axes crossing at a point, with tick marks at the given intervals, inside the current SCALE window.
BEEPBEEP
A short tone on the motherboard speaker. It is the whole sound repertoire: there is no pitch or duration to give.
BITBIT(<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.
BMOVEBMOVE <x>, <y>
Sets the cursor BPLOT writes at, in screen memory rather than in SCALE coordinates.
BPLOTBPLOT <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.
CHECKCHECK <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.
CLEARCLEAR
Erases the variables and arrays and closes any open FOR and GOSUB, leaving the program itself alone.
CODECODE <string>[, <string>]…
Assembles machine code written as hexadecimal digits in a string, into a scratch area at 7F00h, and calls it.
CONTCONT
Resumes a program stopped by STOP or by the STOP key, from the statement after it. Editing any line first makes it impossible.
CONTROLCONTROL <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.
COSCOS(<number>)
The cosine. The angle is in radians unless DEG has been used.
DATADATA <constant>[, <constant>]…
Inline constants for READ to consume in program order. The rest of the statement is stored exactly as typed, spaces included.
DEFDEF 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.
DEGDEG
Takes the angle arguments of SIN, COS, TAN and ATN in degrees, until RAD switches back.
DIMDIM <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.
DISPDISP [<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.
DLOADDLOAD <tapefile>;<numvar>(<number>)
Loads an array back from tape, filling it from the named element on. The separator is a semicolon, not a comma.
DSAVEDSAVE <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.
ENDEND
Stops the program and returns to the OK prompt without a message; unlike STOP, the run cannot then be resumed with CONT.
ENTERENTER <channelno>;<var>[, <var>]…
Reads values in from an I/O channel, as INPUT does from the keyboard.
ERRON 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.
EXPEXP(<number>)
e raised to the given power, the inverse of LOG.
FILLFILL <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.
FNCFNC <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.
FORFOR <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.
FREFRE(<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.
GCLEARGCLEAR
Clears the whole screen - text and graphics alike, since they are the same bitmap - and homes the print position.
GOSUBGOSUB <line>
Calls a subroutine, remembering where to come back to. RETURN comes back to the statement after this one.
GOTOGOTO <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.
IFIF <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.
INKEYINKEY
Which 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.
INPINP(<port>)
Reads a byte from an input port.
INPUTINPUT <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.
INTINT(<number>)
The largest whole number not greater than the argument, so INT(-2.5) is -3 rather than -2.
LABELLABEL <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.
LENLEN(<string>)
How many characters a string holds.
LETLET <var> = <expr>
Assigns a value. The keyword is optional - A=1 and LET A=1 are the same statement and store the same bytes.
LISTLIST [<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 `_`.
LLISTLLIST [<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.
LOADLOAD [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.
LOGLOG(<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.
MOVEMOVE <x>, <y>
Moves the drawing point without drawing anything - where a line should start rather than continue.
NEWNEW
Erases the program and all its variables.
NEXTNEXT [<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.
NOTNOT <number>
Bitwise complement of a 16-bit two's complement value, so NOT 0 is -1 and NOT -1 is 0.
NULLNULL <number>
How many null characters to send after each line ending - padding for a printer whose carriage needs the time.
ONON <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.
OUTOUT <port>, <byte>
Writes a byte to an output port.
OUTPUTOUTPUT <channelno>;<expr>[;|,]…
Prints down an I/O channel on the expansion board rather than to the screen - the printer or the serial line.
PAUSEPAUSE [<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.
PEEKPEEK(<addr>)
Reads one byte of memory. Video RAM starts at C000h and the Monitor ROM at 8000h.
PENPEN <penmode>
Sets what the drawing statements write into the two attribute bits of each cell: 0 plain, 1 blinking, 2 dim, 3 both.
PLOTPLOT <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.
POKEPOKE <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.
POSPOS(<number>)
The column the print position is in. The argument is ignored.
PRINTPRINT [<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.
RADRAD
Takes the angle arguments of SIN, COS, TAN and ATN in radians. This is the state a cold start begins in; DEG switches to degrees.
READREAD <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.
REMREM <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.
RESTORERESTORE
Puts the READ pointer back at the first DATA constant in the program, so the same list can be read again.
RETURNRETURN
Returns from the innermost GOSUB. Reaching one without a matching GOSUB stops with an error.
RIGHT$RIGHT$(<string>, <length>)
The rightmost characters of a string.
RNDRND(<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.
ROMROM <number>
Copies a numbered block out of the ROM module - the same 8255 that BASIC-G itself arrived through - to 7000h and calls it.
RUNRUN [<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.
SAVESAVE <tapefile>
Records the program to tape under a number.
SCALESCALE <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.
SGNSGN(<number>)
The sign of a number: -1, 0 or 1.
SINSIN(<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.
SQRSQR(<number>)
The square root. A negative argument stops with an error.
STATUSSTATUS(<channelno>, <number>)
Reads one register of an I/O device, for a program that has to know whether the channel is ready.
STEPFOR <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.
STOPSTOP
Halts 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.
TANTAN(<number>)
The tangent, on the same terms as COS.
THENIF <number> THEN <line> | <statement>
Introduces what an IF does when its condition holds, and only ever part of one.
TOFOR <numvar> = <number> TO <number>
The limit of a FOR loop, and only ever part of one.
USRUSR(<addr>)
Calls machine code at an address and returns what it leaves behind. The routine must end in RET, and runs as 8080 code.
VALVAL(<string>)
The number a string begins with, or 0 when it does not begin with one.
WAITWAIT <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

Released under GNU GPL v3.0. Some ROM images are third-party copyrighted works, separate to this project, strictly for personal/educational purposes.