Keywords and Tokens

This is an exhaustive list of keywords and instructions in Tomy BASIC, including undocumented keywords (discovered by mistake and poking around :-). Many, many thanks are due to James Host, the Wizard Kludgefinder, for patiently compiling much of this list and the entire list of token values during his forays through the Tomy OS. Also grateful acknowledgement made to Dave Brain, who made some new discoveries on his unit. Updates and corrections are gratefully accepted.

Last modify 17 September 2017.

Back to "Programming the Tomy Tutor" | Back to the main page

Tutti BASIC.
Two keywords at work in the original Tutti.

All tokens have byte values of hex $80 or higher.

Several things become apparent when examining the inner workings of Tomy BASIC. Many tokens seem grouped by function; $BA-$BD, logical operators; $BE-$C5, binary operators; $9C-$AA (except RUN, $A9), program output and screen display; $CB-$DC, function calls. There are several large gaps in the keyword table; $DD-$FB (except $E7, see below) is unoccupied, but TAB and # occupy $FC and $FD. There is also a gap between $AB-$AF (except $AD, see below).

There is a significant number of "crash" tokens that when inserted into memory cause the system to lock up when LISTed (and presumably don't execute either). These tokens are $99, $9F, $AD, $B9 and $E7. Avoid!


Direct Mode Only

Attempting to enter these statements in as program lines results in an ERR 14.

Curiously, some direct mode keywords have tokens, which may indicate Tomy once considered allowing such instructions to be programmatically executable, and some keywords that you may think should be direct-only, like TRACE, can be used in a program as well (see that section).

Keyword Token Description
AUTO a,b none Initiates automatic line numbering. Arguments a and b are optional; a specifies starting number and b the increment. Defaults to 100 and 10, respectively.
CLRSTP a,b $8F Clears a breakpoint from lines a and b.
CONT none Standard BASIC.
LIST a-b none Standard BASIC; a and b are optional.
LLIST a-b none Same as LIST, but sends to the printer. If you have one, that is, or are using the printer interface (or a Pyuuta with a BASIC-1 cartridge).
LOAD file none Loads a file from tape. file must be a literal (can't be a variable).
MENU none Exits to the Tomy menu.
NEW none Clears the current program. In reality, completely resets the BASIC interpreter (as if you'd exited by typing MENU and selected BASIC again).
RENUM a,b none Renumbers previously entered lines. Arguments a and b are optional; a specifies starting number and b the increment. Defaults to 100 and 10, respectively.
RUN a $A9 Standard BASIC; a is optional.
SAVE file none Saves a file to tape. file must be a literal (can't be a variable).
STOP a,b $8E Sets a breakpoint at lines a and b; execution is continued with CONT. STOP by itself can be used in a program, as in any standard BASIC, but STOP with parameters as shown here can only be used in direct mode.
VERIFY file none Checks the integrity of tape file file. file must be a literal (can't be a variable).

Program and Direct Mode

There are a number of undocumented keywords, but that only relates to their American documentation. The Japanese BASIC-1 manual is much more comprehensive and includes almost all of the keywords in the list below.

Keyword Token Description
ABS(a) $CB Standard BASIC.
AND, OR, XOR, NOT $BB, $BA, $BC, $BD Standard BASIC. Work as both logical and bitmask operators, though this behaviour is not documented in either manual.
ASC(a$) $DC Standard BASIC.
ATN(a) $CC Standard BASIC. a must be in radians.
CHR$(a) $D6 Standard BASIC, but undocumented.
CLS $A0 Clears the screen. No arguments.
COLOR(a,b,c) $A1 Sets the colour screen elements. a is the character set, usually 0; b is the foreground colour and c is the background colour. Although the Japanese manual claims it cannot be used in direct mode, this is merely because BASIC will set everything back to the default colours immediately after it executes; no error is actually generated.

The Japanese BASIC-1 manual explains the character set parameter, where character refers to the MCELL/SCELL number:

0: characters 30-127
1: characters 128-135
2: characters 136-143
3: character 144

By using sets 1, 2 or 3, you can set only certain characters' colours instead of the entire Latin character set (0).

COS(a) $CD Standard BASIC. a must be in radians.
DATA, READ $93, $97 Standard BASIC. You may specify multiple variables to READ.
DEF fun(lambda)=expression $89 Allows function definition. Example: DEF MINE(A)=1+A
DIM v(a[,b...]) $8A Standard BASIC.
END, STOP $8B, $8E Standard BASIC.
EXP(a) $CE Standard BASIC. Raises e to the ath power.
FOR, TO, STEP, NEXT $8C, $B1, $B2, $96 Standard BASIC.
GCELL(a,b,c) $A5 Get a screen cell into a variable. a is the vertical coordinate (1-24), b is the horizontal (1-32), and c is the name of the variable to save it to. The screen code is the same as that used for SCELL and MCELL.
GOSUB, RETURN $87, $88 Standard BASIC. Computed GOSUBs are not allowed.
GOTO $86 Standard BASIC. Computed GOTOs are not allowed.
IF, THEN, ELSE $84, $B0, $81 Standard BASIC. THEN and ELSE may only be followed by line numbers, not statements. There is no colon between THEN and ELSE (example: IF Q=1 THEN 200 ELSE 300). Computed THENs and ELSEs are not allowed.
INPUT b$:a $92 Standard BASIC. The prompt and the variable are separated by a colon instead of a semicolon or comma. BASIC whines with ERR 16 if you do a type mismatch (the equivalent of the 64's ?REDO FROM START complaint).
INT(a) $CF Standard BASIC.
JKEY1, JKEY2 $A7, $A8 Undocumented. Despite having defined tokens, both generate an ERR 2 as functions or statements. Neither keyword appears in the Japanese BASIC-1 manual either, suggesting they were never implemented.
KEY(a,b) $A6 Reads the joystick/joy controller and keyboard. a is 0 for the keyboard, 1 for controller #1, and 2 for controller #2; b is the name of the variable to store the ASCII value (for keyboard) or stick value (for joystick/controller) in. On the joystick and controllers, bit 0 (1) is right, bit 1 (2) is up, bit 2 (4) is left, bit 3 (8) is down, bit 4 (16) is select-right fire button, and bit 5 (32) is select-left fire button, and combinations of them (SL+left+up = 32+4+2 = 38) are valid.

When querying the joyport there is a bug in Tomy BASIC where the value can overflow, causing weirdness with printing. The solution is to AND it with 127 before any further manipulation, like so:

10 KEY (1,J) :: J=J AND 127
20 KEY (2,K) :: K=K AND 127
30 PRINT J;K :: GOTO 10

With a single joystick, the same value is read on both #1 and #2.

LEN(a$) $D5 Standard BASIC.
LET $8D Standard BASIC. LET is not required for assignment.
LOG(a) $D0 Standard BASIC, but undocumented.
LPRINT $9C Identical to PRINT, but sends to the printer which was never manufactured, or to your own printer if you're using the printer interface (or a Pyuuta with a BASIC-1 cartridge).
MCELL(a,b$) $A3 Loads bit pattern b$ into programmable character a (128-159 are available for use, but actually any valid byte is acceptable). This value is shifted to generate the actual offset into the character set. The bit pattern is constructed identically to the TI's CALL CHAR statement, basically eight hex bytes corresponding to the set bits. Example from the manual:
00000000 00
01100110 66
11111111 FF
11111111 FF
11111111 FF
01111110 7E 
00111100 3C
00011000 18
So, MCELL(128, "0066FFFFFF7E3C18") turns character 128 into a heart. MCELL can be used to manipulate most VDP memory locations below VDP $0800. See the Memory Map and the SCELL command.
ON, GOTO, GOSUB $9B, $86, $87 Standard BASIC.
PRINT $9C Standard BASIC. Similar to the TI, single colons (:) embedded in a PRINT statement, like PRINT "X":"Y", insert carriage returns.
RANDOMIZE $95 Re-seeds the random number generator, presumably off the internal clock or some other "independent" source.
REM $9A Standard BASIC. The comment may not exceed 112 characters.
RESTORE a $94 Standard BASIC; optional parameter a sets READ pointer to that line.
RND $D7 Returns a random number between 0 and 1. Unlike many BASICs, RND takes no arguments.
SCELL(a,b,c,d) $A4 Puts a character at a screen position. a is the vertical coordinate (1-24), b is the horizontal coordinate (1-32), c is the character number (32-159 officially, but actually any valid byte; this is actually based on MCELL number and not the real offset into the character set) and n is the number of times to print that character.

SCELL is the only BASIC command that allows direct access to all of VDP RAM since it has no bounds-checking. Refer to the Tomy Memory Map, and also the MCELL command.

SCREEN(a) $A2 Sets the background colour to colour a (1-16).
SEG$(a$,b,c) $D8 Takes a substring of string a$. Undocumented; the American manual incorrectly lists this keyword as MID$. The Japanese BASIC-1 manual does properly list SEG$.
SGN(a) $D1 Standard BASIC.
SIN(a) $D2 Causes your computer to lust madly and ravenously after tender young ... ahem. Standard BASIC. a must be in radians.
SOUND(a,b,c,d,e,f,g) $AA Plays a tone on voice 1 of frequency b for a clock cycles (the Japanese manual says roughly "1/200th of a second") at amplitude c. Optional parameters d and f specify frequency for voices 2 and 3, and e and g the corresponding amplitudes. The supported frequency range is 110 to 1975 Hz; amplitude ranges from 0-30, with 0 being loudest and 30 being off. Other values generate ERR 2.

To play, say, voice 2 alone, specify amplitude 30 for voice 1 (or for voice 3 alone, specify 30 for voices 1 and 2, and so forth).

Undocumented: The Japanese BASIC-1 manual further mentions that if you specify a negative number (-1, -2, or -3) for the frequency, you receive one of three pseudorandom noise frequencies instead; -1 is the highest pitched and -3 is the lowest, which directly correlate to the first three frequency settings for the sound chip's noise generator. The fourth option (which one assumes would be -4) for using the frequency of voice 3 is not implemented and generates an error. Interestingly, not even the Japanese BASIC-1 manual notes that noise can actually be specified for any of the three voice frequency parameters, but only once (ERR 16 otherwise) because the internal sound chip only has one noise channel. Other negative values generate ERR 2.

STOP $8E Standard BASIC (but see above).
STR$(a) $DB Standard BASIC, but undocumented.
SQR(a) $D3 Standard BASIC.
TAB(a) $FC Standard BASIC, but undocumented.
TRACE $90 Enables BASIC trace mode. Dave mentions this and UNTRACE can work in a program, too.
UNTRACE $91 Disables BASIC trace mode.
VAL(a$) $DA Standard BASIC.

Symbols

In token order.

Symbol Token Description
:: $82 Multiple statement separator.
! $83 Davey suggests, perhaps a tail REM (a la the apostrophe in Microsoft BASIC). Undocumented in both the American and Japanese manuals.
, $B3 Parameter separator.
; $B4 Concatenator and newline suppressor for PRINT and LPRINT.
: $B5 Inserts new lines in PRINT and LPRINT statements; parameter separator in INPUT.
) ( $B6, $B7 Arithmetic precedence operators; also used to denote argument lists for functions. Unlike the C64, where the leading ( is considered a part of the function tokens that require it, ( is a separate token in Tomy BASIC.
& $B8 This works as a string concatenation operator, just like the 99/4A. Undocumented in the American manual but prominently demonstrated in the Japanese manual's type-in examples.
=, <, > $BE, $BF, $C0 Logical comparison operators; = is also the assignment operator. Compound tokens >=, =>, <=, =< and <> also possible with regular BASIC semantics.
+, -, *, /, ^ $C1, $C2, $C3, $C4, $C5 Arithmetic operators. + is also the string concatenator. Standard BASIC.
# $FD Unknown. Undocumented. May be a remnant of never-finished input/output routines (compare with INPUT# on the 99/4A and C64). Dave experimented and found that PRINT #0 prints to the screen; PRINT #1 (all the way up to 255, what dedication!) gives a ERR 19 (see the Errors page); INPUT #0 gives ERR 20 (ibid.); INPUT #1 (through 255?) seems to be keyboard. RESTORE # on any device number gives ERR 19 again, and OPEN # and CLOSE # don't work.

Housekeeping Tokens

These tokens are used internally by Tomy BASIC for delimiters and indicators, do not actually appear in LISTings, and cannot be entered directly.

Token Description
$C7 Indicates literal string in quotes to follow. The LIST routine prints a quote, and gets the length of the string from the byte immediately following. The string is printed, and then a trailing quote.
$C8 Indicates literal string without quotes to follow (i.e. variables, token-less keywords). The length is also in the byte immediately following the token.
$C9 Indicates 16-bit integer to follow, in high-byte/low-byte standard 9995 word format.


Back to the top | Back to "Programming The Tomy Tutor"