Вы находитесь на странице: 1из 105

ALL FUNCTIONS ABOUT

MSX-BASIC & Turbo BASIC Compiler


MSX, MSX2, MSX2+ & MSX Turbo-R
Reserved keywords (Basic)
Following keywords are reserved on all MSX machines. These keywords can be use to extend the
MSX-Basic funtionality:
ATTR$
CMD
IPL
FPOS (Channel) related to OPEN and CLOSE
These keywords are reserved for future use.
MSX (MSX-Basic 1)

ABS
(MSX-Basic)
Syntax:
ABS(<number>)
Function:
Generates the absolute-value (unsigned) of the specified number.
Example:
PRINT ABS(-10)
10
Ok

See also:
SGN

AND
(MSX-Basic)
Syntax:
<number1> AND <number2>
Function:
Performs a bitwise AND-operation:
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
The AND-operation is often used to "mask" one or more bits.
Example:
PRINT 15 AND 11 1111B
11 1011B AND
Ok -----
1011B

PRINT 6 AND 13 0110B


4 1101B AND
Ok -----
0100B

See also:
EQV, IMP, MOD, NOT, OR, XOR, MSX-Basic operators
OPEN
(MSX-Basic, Disk-Basic, RS232-Basic)
Syntax:
OPEN "device:filename" [FOR direction] AS #channel [LEN=recordlength]
Function:
Opens an input- or output-channel from or to the specified device.
device-name for MSX-Basic can be (for example):
Device name device type
CRT: screen (text-mode)
GRP: screen (graphic-mode)
LPT: printer
CAS: tape (not supported on MSX Turbo-R)
A: Disk drive
B: Disk drive
COM: RS232 (serial interface)
MEM: MSX2 RAM-Disk
filename is the name of the file, which is about to be opened. The filename must not specified for
screen-modes and printer.
direction indicates if the file is to be read into the buffer, or the buffer should be written to the file.
The following keywords can be specified:
INPUT = sequential read
OUTPUT = sequential write
APPEND = sequential write to the end of an existing file
If the FOR direction is not specified MSX-Basic assumes that the file is a random file. In this case a
file is created, if not found on the disk of a disk-drive.
Not every direction can be used for all device names. Allowed combinations are as following:
Device name OUTPUT INPUT APPEND
CRT: X - -
GRP: X - -
LPT: X - -
CAS: X X -
A: X X X
B: X X X
COM: X X -
MEM: X X X
RS232: Note that random access to a channel is illegal. Only sequential accesses are logically
possible.
channel is the file-number, as long as the file is opened. This number is used to operate with
Input/Output instructions (such as "INPUT#", "PRINT#", "CLOSE#") on the file.
recordlength is an integer. If set it specifies the record-length of a random-file. The default-value is
256.
Before an I/O operation is performed the file has to be opened first. The maximum number of
simultaneously opene files can be specified by the "MAXFILES" statement.
Example:
OPEN "CAS:TEST" FOR OUTPUT AS #1
PRINT #1,X

The value of X is saved in a file named "TEST" (on tape). I.e. it's possible to read the stored value
using:
OPEN "CAS:TEST" FOR INPUT AS #2
INPUT #2,X

10 SCREEN 2:COLOR 15,4,7


20 OPEN "GRP:" FOR OUTPUT AS #1
30 LINE (32,32)-(120,120),6,B
40 CIRCLE (120,120),56,1
50 PRESET (40,8)
60 PRINT #1,"Text in graphic screen"
70 FOR I=1 TO 2000: NEXT I
80 END
RUN

See also:
CLOSE, INPUT#, PRINT#, EOF, LOC, LOF, MAXFILES, RAM-Disk in MSX-Basic 2

ASC
(MSX-Basic)
Syntax:
ASC(<string>)
Function:
Returns the ASCII-code of the 1st character in string.
Example:
PRINT ASC("EMIL")
69
Ok

See also:
CHR$

ATN
(MSX-Basic)
Syntax:
ATN(<number>)
Function:
Returns the arc-tangent of the specified number in radians.
Example:
PRINT ATN(100)
1.5607966601082
Ok

See also:
COS, SIN, TAN

AUTO
(MSX-Basic)
Syntax:
AUTO [<linenumber>[,<increment>]]
Function:
Generates and increments line-numbers automatically.
Example:
AUTO 100,20

The line-numbering begins at 100 and is subsequently incremented by 20. You can stop this
operation mode by pressing Ctr+C.
A '*' (asterisk) character indicates that the linenumber is already in use. I.e. if
120*
is displayed, this line already exists in the program.
See also:
RENUM

BASE
(MSX-Basic)
Syntax:
BASE(<number>)
Function:
Returns the base-address of a video-processor register. Where number is a number between 0 and
12 and has following meaning:
(*) = Added for MSX2
Mode-name: Screen-mode: Table: Name:
Text 1 Screen 0, width 40 pt pattern-table
*Text 2 Screen 0, width 80 spt sprite-pattern-table
Mutli-color Screen 3 spat sprite-attribute-table
Graphics 1 Screen 1 ct color-table
Graphics 2 Screen 2 nt name-table
*Graphics 3 Screen 4
*Graphics 4 Screen 5
*Graphics 5 Screen 6
*Graphics 6 Screen 7
*Graphics 7 Screen 8
Base: Table: Mode-name: Init:
0 nt Text 1 $0000
2 pt Text 1 $0800
5 nt Text 2 $1800
6 ct Text 2 $2000
7 pt Text 2 $0000
10 nt Graphics 1 $1800
11 ct Graphics 1 $2000
12 pt Graphics 1 $0000
13 spat Graphics 1 $1B00
14 spt Graphics 1 $3800
15 nt Graphics 2 $0800
16 pt Graphics 2 $0000
18 spat Graphics 2 $1B00
19 spt Graphics 2 $3800
20 nt Graphics 3 $1800
21 ct Graphics 3 $2000
22 pt Graphics 3 $0000
23 spat Graphics 3 $1E00
24 spt Graphics 3 $3800
25 nt Graphics 4 $0000
28 spat Graphics 4 $7600
29 spt Graphics 4 $7800
30 nt Graphics 5 $0000
33 spat Graphics 5 $7600
34 spt Graphics 5 $7800
35 nt Graphics 6 $0000
38 spat Graphics 6 $FA00
39 spt Graphics 6 $F000
40 nt Graphics 7 $0000
43 spat Graphics 7 $FA00
44 spt Graphics 7 $F000
Example:
PRINT BASE(2)
2048
Ok

See also:
VDP

BEEP
(MSX-Basic)
Syntax:
BEEP
Function:
Generates a short beep. On MSX1-computers this is 800Hz, 0.25s. PRINT CHR$(7) also generates
a BEEP.
Example:
BEEP

See also:
PLAY, SET BEEP

BIN$
(MSX-Basic)
Syntax:
BIN$(<number>)
Function:
Returns a string which contains the binary representation of number.
Example:
PRINT BIN$(100)
1100100
Ok

See also:
HEX$, OCT$, STR$, VAL

BLOAD
(MSX-Basic, Disk-Basic)
Syntax:
BLOAD "<name>"[,R[,<offset>]]
BLOAD "<name>"[,S]
Function:
Binary LOAD:
The binary file (often a assembly language program) name will be loaded at the beginaddress that
was specified during BSAVE. If the option ',R' is added, the program will be started automatically.
If there was no startadress specified for BSAVE, the program begins it's execution on beginadress.
If an offset is specified the program will be loaded at beginaddres+offset.
If 'S' is specified this contents are loaded to VRAM from disk files. This can done in any screen
mode, note, however, that only the active pages are valid when the screen mode is from 5 to 8. No
cassette tapes can be used.
Turbo-R: the "CAS:" device is no longer supported!
Example:
BLOAD "TEST.BIN",R

See also:
LOAD, CLOAD, DEFUSR, SET PAGE, BSAVE
BSAVE
(MSX-Basic, Disk-Basic)
Syntax:
BSAVE "<name>"[,<beginadress>,<endadress>[,<startadress>][,2]]
BSAVE "<name>"[,<beginadress>,<endadress>][,S]
Function:
Saves the memory-contents from beginadress to endadress with name on the device. If a
startadress is specified the machine-code program will be started on this address if it is loaded
using BLOAD with the ',R' option. When no startaddress is specified the beginaddress will be used
as startaddess.
If the tape-device is used the ',2' option causes the recording speed to be set to 2400 baud in stead of
the normal 1200 baud.
If 'S' is specified VRAM contents are saved to disk. This can be done for any screen mode, note,
however, that only the active pages are valid when the screen mode is from 5 to 8. No cassette tapes
can be used. Valid value range of address is from -32768 to -2, or from 0 to 65534 (&HFFFE).
Turbo-R: the "CAS:" device is no longer supported!
Example:
BSAVE "TEST.BIN",&H9000,&H92FF

See also:
SAVE, CSAVE, SET PAGE, BLOAD

CALL
(MSX-Basic)
Syntax:
CALL <extended statement name>[(<arguments>)]
_ <extended statement name>[(<arguments>)]
Function:
Executes a extended BASIC-command stored in an extension ROM. Instead of the keyword CALL
you can also use a _ (underscore).
Examples:
CALL SYSTEM
CALL KANJI
CALL ANK
CALL TURBO ON
CALL TURBO OFF
CALL PAUSE(100)

See also:
CDBL
(MSX-Basic)
Syntax:
CDBL(<number>)
Function:
Converts number into a double-precision value.
Example:
See also:
CINT, CSNG

CHR$
(MSX-Basic)
Syntax:
CHR$(<number>)
Function:
Returns the character with the ASCII-code number. number must be an integer between 0 and 255.
Example:
10 FOR I=0 TO 255
20 PRINT CHR$(I);
30 NEXT I

See also:
ASC

CINT
(MSX-Basic)
Syntax:
CINT(<number>)
Function:
Converts number into an integer value between -32768 and 32767. Digits behind the decimal-point
are ignored. In other BASIC-dialects the value is rounded up or down.
Example:
PRINT CINT(12.34)
12
Ok
PRINT CINT(123.54)
123
Ok

See also:
CDBL, CSNG
CIRCLE
(MSX-Basic)
Syntax:
CIRCLE [STEP](<x,y>),<radius> [,<color> [,<start>,<end> [,<proportion>]]]
Function:
This command draws an ellipse on the screen.
x, y are coordinates of the center,
radius is the radius of the biggest main-axis
These values must be specified. Optional arguments are the
color of the line (see color-table)
start and end of the line (multiple of PI) and
proportion the aspect-ratio* of the x- and y-axis
Examples:
10 SCREEN 2
20 CIRCLE(100,100),40,1
30 GOTO 30

Draws an ellipse in the center of the screen. With


20 CIRCLE(100,100),40,,,1.4

you'll draw a circle


*note: On a real msx the results of "aspect-ratio" will be different depending on your screens
refresh-frequency, this example assumes 50 Hz (PAL) but when in 60 Hz (NTSC) specifing no
aspect-ratio will result in a circle.
See also:
DRAW, LINE, PSET, PAINT, SCREEN, CLS

CLEAR
(MSX-Basic)
Syntax:
CLEAR [<stringsize> [,<adress>]]
Function:
This command clears the contents of all variables and all dimensions of arrays. The optional
stringsize reserves additional memory on top of memory. Initially there are 200 Bytes reserved - for
use in character-strings.
If adress is specified, this is the maximum address of BASIC-memory. This command can also be
used if arrays must be dimensioned dynamically.
Example:
10 CLEAR
20 INPUT "N=";N
30 DIMA(N)
40 GOTO 10
See also:
ERASE, DIM, FRE, MAXFILES, DEF FN
Note: do not confuse with CLS

CLOAD
(MSX-Basic)
Syntax:
CLOAD "<name>"
Function:
Cassette LOAD:
Loads a basic program from tape. If no name is specified the first available basic-program will be
loaded.
Turbo-R: CLOAD is no longer supported and will generate a "syntax error"
Example:
CLOAD
Found: TEST.BAS
Ok

See also:
CSAVE, BLOAD, RUN

CLOAD?
(MSX-Basic)
Syntax:
CLOAD? "<name>"
Function:
Compares a program on tape with the one in memory.
If the program in memory differs from the program on tape a "Verify error" will occur.
Turbo-R: CLOAD? is no longer supported and will generate a "syntax error"
Example:
CLOAD?

See also:
CSAVE

CLOSE
(MSX-Basic, Disk-Basic, RS232-Basic)
Syntax:
CLOSE [#][<filenumber>]
Function:
Closes a file, if no filenumber is specified all open files will be closed.
RS232: If the channel was opened in output mode, the EOF character is sent. Note that the file
buffer allocated by BASIC following the FCB is not actually used.
Example:
10 MAXFILES=1
20 OPEN "TEST" FOR OUTPUT AS#1
30 A$="MSX"
40 PRINT #1,A$
50 CLOSE #1
60 END

See also:
OPEN, EOF, LOC, LOF

CLS
(MSX-Basic)
Syntax:
CLS
Function:
Clears the screen (as well in text as in graphics modes).
Example:
-
See also:
CALL CLS, PRINT, CIRCLE, DRAW, LINE, PSET, PAINT, SCREEN

COLOR
(MSX-Basic)
Syntax:
COLOR [<foreground>][,<background>][,<border>]
Function:
COLOR modifies the color of the foreground (active drawing), background and border. Possible
values and differences in various screen-modes can be found in the color-table.
Example:
1000 COLOR 15,1,1:SCREEN 2
1010 OPEN "GRP:" FOR OUTPUT AS #1
1020 PRESET (10,5)
1030 PRINT #1, "A WELL TUNED TV-SET"
1040 PRESET (10,15)
1050 PRINT #1, "SHOWS 15 COLORS AND BLACK"
1060 CLOSE #1
1070 FOR G=2 TO 15
1080 COLOR G
1090 LINE (G*16-15,30)-(G*16,184),,BF
1100 NEXT G
1110 GOTO 1110

See also:
COLOR SPRITE COLOR SPRITE$ COLOR=, COLOR=RESTORE, COLOR=NEW, DRAW,
LINE, CIRCLE, PSET, PAINT

CONT
(MSX-Basic)
Syntax:
CONT
Function:
CONT continues a program, which was halted with CTRL/STOP or the STOP or END instruction.
Example:
10 PRINT "Test line 1"
20 END
30 PRINT "Test line 2"

RUN
Test line 1
Ok
CONT
Test line 2
Ok

See also:
RUN, END, STOP

COS
(MSX-Basic)
Syntax:
COS(<number>)
Function:
Calculates the cosine of the specified number.
Example:
PRINT COS(100)
.86231887228917

See also:
ATN, SIN, TAN

CSAVE
(MSX-Basic)
Syntax:
CSAVE "<name>" [,2]
Function:
Cassette Save, stores a basic program on tape.
If the ',2' option is added the recording speed is set to 2400 baud in stead of the normal 1200 baud.
Turbo-R: CSAVE is no longer supported and will generate a "syntax error"
Example:
CSAVE "TEST",2

See also:
CLOAD?, CLOAD, SAVE, BSAVE

CSNG
(MSX-Basic)
Syntax:
CSNG(<number>)
Function:
Converts number into a single-precision value.
Example:
-
See also:
CDBL, CINT

CSRLIN
(MSX-Basic)
Syntax:
CSRLIN
Function:
Returns the current Y-position of the cursor.
Example:
LOCATE 0,5:PRINT CSRLIN
5
Ok

See also:
LOCATE, POS

DATA
(MSX-Basic)
Syntax:
DATA <value>[,<value2> [,...]]
Function:
With this instruction a set of elements can be added a program.
These elements can be either numbers or strings, they can be accessed one by one using the READ
instruction and are always separated by comma's. Strings are also placed between quotation marks.
Example:
10 READ A$
20 PRINT A$
30 READ A,B
40 PRINT A
50 PRINT B
60 DATA "TEST",10,20

See also:
READ, RESTORE

DEF FN
(MSX-Basic)
Syntax:
DEF FN <functionname>[(<arguments>)]=<function definition>
Function:
With this instruction one can create his own functions.
Example:
10 DEF FN TEST$(E)="And the character is: "+CHR$(E)
20 PRINT FN TEST$(65)
RUN
"And the character is: A"

See also:
CLEAR

DEFDBL
(MSX-Basic)
Syntax:
DEFDBL <letter>[-<lastletter>] [<letter2> [,-<lastletter2>]]
Function:
Defines all variables starting with the specified letter(s) as double-precision variables.
Example:
DEF DBL A-E

See also:
DEFINT, DEFSNG, DEFSTR, CLEAR
DEFINT
(MSX-Basic)
Syntax:
DEFINT <letter>[-<lastletter>] [<letter2> [,-<lastletter2>]]
Function:
Defines all variables starting with the specified letter(s) as integer variables.
Example:
DEF INT G

See also:
DEFDBL, DEFSNG, DEFSTR, CLEAR

DEFSNG
(MSX-Basic)
Syntax:
DEFSNG <letter>[-<lastletter>] [<letter2> [,-<lastletter2>]]
Function:
Defines all variables starting with the specified letter(s) as single-precision variables.
Example:
DEF SGN A

See also:
DEFDBL, DEFINT, DEFSTR, CLEAR

DEFSTR
(MSX-Basic)
Syntax:
DEFSTR <letter>[-<lastletter>] [<letter2> [,-<lastletter2>]]
Function:
Defines all variables starting with the specified letter(s) as string variables.
Example:
DEF STR A

See also:
DEFDBL, DEFINT, DEFSNG, CLEAR
DEFUSR
(MSX-Basic)
Syntax:
DEFUSR[<number>] = <address>
Function:
Specifies the starting address of a machine-language program, the program can be executed by
using the USR function. number can be 0-9, if no number is specified 0 is assumed.
Example:
DEF USR1=&H156:A=USR1(0)

See also:
USR, BLOAD, POKE, VARPTR

DELETE
(MSX-Basic)
Syntax:
DELETE <line> [-<line2>]
Function:
Deletes program-lines, if this command is executed within a program the program will terminate
after this command.
Example:
DELETE 10-40

See also:
MERGE, RENUM

DIM
(MSX-Basic)
Syntax:
DIM <array-name>(<maximun index>)[,<array-name>...]
Function:
Reserves memory for the specified variables and intitializes the array.
If if an array is referred to when not first created with a DIM instruction, a maximum index of 10 is
assumed. The first index is always 0.
Example:
10 DIM M(25)
20 FOR A=0 TO 25:M(A)=3*A:NEXT
30 FOR A=0 TO 25
40 PRINT "3 times ";A;" is ";M(A)
50 NEXT A
See also:
CLEAR

DRAW
(MSX-Basic)
Syntax:
DRAW "<string>"
Function:
With this function strait lines can easily be drawn by using simple codes.
The following codes can be used:
Code Function
S Scale
Ax Rotates the coordinate system in steps of 90 degrees. x can be 0-3.
Cxx Active drawing color, xx can be 0-15.
Move, draws a line from the last known coordinates (x,y) to (x+qq,y+zz) qq en zz can also
Mqq,zz
be negative.
BMqq,z
Blank move, moves the (x,y) coordinates without ectually drawing a line.
z
Uxx Up, draws a line xx pixels up.
Dxx Down, draws a line xx pixels down
Rxx Right, draws a line xx pixels to the right.
Lxx Left, draws a line xx pixels to the left.
Exx Draws a line xx pixels up-right.
Fxx Draws a line xx pixels down-right.
Gxx Draws a line xx pixels up-left.
Hxx Draws a line xx pixels down-left.
Variables can also be used within draw-instructions, the '=' symbol can be used to allow interger-
variables. If a string-variable is used a X should be prefixed and all variables should be closed by a
';'.
Example:
10 SCREEN 5
20 A$="C15BM50,50"
30 S=50
40 DRAW "XA$;D=B;R=B;U=B;L=B;"
50 A$=INPUT$(1)

See also:
CIRCLE, LINE, PSET, PAINT, SCREEN, CLS

END
(MSX-Basic)
Syntax:
END
Function:
Terminates a programs execution. When the interpreter reaches the last line of the program, it is
automaticly terminated, END is not necessary there. After END a CONT instruction can continue
the program execution on the next line.
Example:
10 FOR A=1 TO 10
20 PRINT A
20 IF A=5 THEN END
30 NEXT

See also:
STOP, RUN, CONT

EOF
(MSX-Basic, RS232-Basic)
Syntax:
EOF(<filenumber>)
Function:
EOF is zero while the end of the open file in not reached.
Example:
10 IF EOF(2) THEN CLOSE#2

See also:
OPEN, CLOSE, LOC, LOF

ERASE
(MSX-Basic)
Syntax:
ERASE <array-name>[,<array-name>]
Function:
ERASE frees up the memory used by array's previously allocated by a DIM instruction.
Example:
10 DIM A(100),X$(60)
...
500 ERASE A,X$

See also:
CLEAR, DIM
ERR
(MSX-Basic, Disk-Basic)
Syntax:
ERR
Function:
Returns the number of the last error that occured. The error number can be found in the errortable.
Example:
10 ON ERROR GOTO 50
20 A=25: PRINT A
30 B=A/0
40 END
50 PRINT "Error number ";ERR;" occured in line ";ERL
60 RESUME NEXT

See also:
ERL, ERROR, ON ERROR GOTO, RESUME

ERL
(MSX-Basic)
Syntax:
ERL
Function:
Returns the line-number where the last error occured.
Example:
See ERR
See also:
ERR, ERROR, ON ERROR GOTO, RESUME

ERROR
(MSX-Basic, Disk-Basic)
Syntax:
ERROR <number>
Function:
Displays the error-message that belongs to the error-number.
Error Message
1 NEXT without FOR
2 Syntax error
3 RETURN without GOSUB
4 Out of DATA
5 Illegal function call
6 Overflow
7 Out of memory
8 Undefined line number
9 Subscript out of range
10 Redimensioned array
11 Division by zero
12 Illegal direct
13 Type mismatch
14 Out of string space
15 String too long
16 String formular too complex
17 Cant CONTINUE
18 Undefined user function
19 Device I/O error
20 Verify error
21 No RESUME
22 RESUME without error
23 Unprintable error
24 Missing operand
25 Line buffer overflow
Disk-Basic: following additional ERRORs are defined:
Error Message
50 FIELD overvlow
51 Internal error
52 Bad file number
53 File not found
54 File already open
55 Input past end
56 Bad file name
57 Direct statement in file
58 Sequential I/O only
59 File not OPEN
60 Bad FAT
61 Bad file mode
62 Bad drive name
63 Bad sector number
64 File still open
65 File already exists
66 Disk full
67 Too many files
68 Disk write protected
69 Disk I/O error
70 Disk offline
71 Rename across disk
Example:
ERROR 64
File still open
Ok

See also:
ERR, ERL, ON ERROR GOTO, RESUME

EQV
(MSX-Basic)
Syntax:
number1 EQV number2
Function:
Logical equivalence.
0 EQV 0 = 1
0 EQV 1 = 0
1 EQV 0 = 0
1 EQV 1 = 1
Example:
See also:
AND, IMP, MOD, NOT, OR, XOR, MSX-Basic operators

EXP
(MSX-Basic)
Syntax:
EXP(<number>)
Function:
Calculates the power of e for number (base is e=2.718281884588).
number must be less or equal 145.06286058562.
Example:
PRINT EXP(10)
22026.4657948
Ok

See also:
LOG

FIX
(MSX-Basic)
Syntax:
FIX(<number>)
Function:
Return the integer part of number. This function is identical to
SGN(<number>)*INT(ABS(<number>)).
The difference between "FIX" and "INT" is that negative values are not rounded to the next lower
value.
Example:
PRINT FIX(1.7)
1
Ok

See also:
INT, SGN, ABS

FOR
(MSX-Basic)
Syntax:
FOR <variable>=<number> TO <number2> [STEP <number3>]
NEXT [<variable> [,<variable2>][, ...]]]
Function:
This instruction forms a program loop that looks like:
FOR <variable>=X TO Y [STEP Z]
.
. Instructions
.
NEXT <variable>
The instructions between FOR and NEXT are executed with values from X to Y. If STEP Z is not
specified a step-width of 1 is used. Within a loop another loop can be implemented, so loops can be
nested.
Every loop will be executed at least once because the termination-condition is checked in the NEXT
statement.
Example:
10 FOR I=1 TO 4
20 PRINT I;
30 NEXT:PRINT
40 FOR I=0 TO 5 STEP 5
50 FOR J=0 TO I+2
60 PRINT J
70 NEXT J,I:PRINT
80 END

See also:
CALL PAUSE

FRE
(MSX-Basic)
Syntax:
FRE(number)
FRE(string)
Function:
FRE(number) returns the free memory available to Basic programs, where FRE(string) returns the
free memory for strings.
Example:
NEW
PRINT FRE(0)
28815
Ok
PRINT FRE("")
200
Ok

See also:
CLEAR, ERASE, DIM, MAXFILES

GOSUB
(MSX-Basic)
Syntax:
GOSUB line
Function:
This statement jumps to a subroutine. The program can return from this routine by using the
RETURN statement.
Example:
100 PRINT "Hello"
110 GOSUB 200
120 GOSUB 300
130 END
200 PRINT "Here am I"
210 RETURN
300 PRINT "End"
310 RETURN

Outputs the following text:


Hello
Here am I
End

See also:
RETURN, ON GOSUB, GOTO

GOTO
(MSX-Basic)
Syntax:
GOTO line
GO TO line
Function:
Unconditional jump-statement. The program continues at the specified line.
Example:
-
See also:
ON GOTO, GOSUB

HEX$
(MSX-Basic)
Syntax:
HEX$(number)
Function:
Converts the specified number into a hexadecimal value. A hexadecimal-number consists of digits 0
to 9 and the characters A to F.
Example:
PRINT HEX$(1023)
3FF
Ok

See also:
BIN$, OCT$, STR$, VAL

IF
(MSX-Basic)
Syntax:
IF expression THEN <StatementsA> [ELSE <StatementsB>]
Function:
If the condition is met StatementsA are executed. After this the program continues with the next
program line.
If the condition is not met then StatementsB after the ELSE are executed. After this the program
continues with the next program line too.
Example:
100 INPUT "A=";A
110 IF A>=0 THEN PRINT "positive" ELSE PRINT "negative"
120 INPUT "Again ( /N)";A$
130 IF A$<>"N" GOTO 100 ELSE END

Is the condition A>=0 in line 110 met then "positive" is printed. As line 130 indicates the THEN can
be replaced by GOTO. On the other hand the GOTO after THEN is not necessary. Line 130 can also
look like:
130 IF A$<>"N" THEN 100 ELSE END
See also:
GOTO

INKEY$
(MSX-Basic)
Syntax:
INKEY$
Function:
The function INKEY$ scans the keyboard for a pushed key. The returned string is empty if no key
is pressed or the ASCII character of the pressed key.
Example:
10 PRINT "Please press any key"
20 IF INKEY$="" THEN 20
30 PRINT "Continuing..."

If the key-input should result in a more detailed evaluation it should be stored in a string-variable.
10 PRINT "Please press any key"
20 A$=INKEY$:IF A$="" THEN 20
30 IF ASC(A$)=13 THEN 10

If ENTER/RETURN is pressed in line 20 the program restarts in line 10.


See also:
INPUT$, STICK, STRIG

IMP
(MSX-Basic)
Syntax:
number1 IMP number2
Function:
Logical implication.
0 IMP 0 = 1
0 IMP 1 = 1
1 IMP 0 = 0
1 IMP 1 = 1
Example:
See also:
AND, EQV, MOD, NOT, OR, XOR, MSX-Basic operators

INP
(MSX-Basic)
Syntax:
INP(port)
Function:
Reads the content of the specified input-port (0-255).
The statement "OUT" can be used to write a byte to an output-port.
Example:
10 A=INP(&HA8)
20 A$="00000000"+BIN$(A)
30 PRINT RIGHT$(A$,8)
40 END
RUN

See also:
OUT, WAIT

INPUT
(MSX-Basic, Disk-Basic)
Syntax:
INPUT ["prompt";] variable [,variable2 [,...]]
INPUT#channel, variable [,variable2 [,...]]
Function:
Retrieves a number or string from the keyboard and assignes it to a variable. The input is finished
with the Return/Enter key. A prompt can be printed before the input starts. A "?" sign is also printed
to indicate the input.
The INPUT# statement reads data from a sequential file opened as #channel and assigns it to the
listed variables.
Special: If a string already has a value and the new input is empty (only Return/Enter pushed) then
the old value remains unchanged. In other Basic dialects the value will be cleared. This is also valid
for the input of numbers (not only strings).
Example:
10 INPUT "Length of the page";L

See also:
LINE INPUT, GET, INPUT$, PRINT, OPEN, PRINT[#]

INPUT$
(MSX-Basic)
Syntax:
INPUT$(number [#channel])
Function:
This function reads number characters from the keyboard or a file opened as #channel.
The INPUT$ function can also recognize control-sequences, which cannot be entered using the
INPUT statement. Therefore INPUT$ is useful for data-transfer from other machines. In such
transmissions all characters might be important.
Example:
10 PRINT "C continues, E ends the program"
20 A$=INPUT$(1)
30 IF A$="E" THEN END
40 IF A$="C" THEN GOTO 60
50 GOTO 10
60 REM code continues here

See also:
INKEY$

INSTR
(MSX-Basic)
Syntax:
INSTR([position,] string, substring)
Function:
This function looks for the 1st occurence of the substring in the specified string and returns the
start-position. In addition a position (0-255) can be specified, which indicates where the search
should start.
If the substring is not found, or position is larger as the length of the string or the string is empty
then INSTR returns 0. If substring is empty INSTR returns 1.
Example:
10 A$="Merry Christmas"
20 PRINT INSTR(A$, "ist")
30 PRINT INSTR(A$, "IST")
40 PRINT INSTR(5, A$, "r")
RUN
10
0
9

See also:
LEN, MID$

INT
(MSX-Basic)
Syntax:
INT(<number>)
Function:
Returns the integer-part of <number>.
Example:
10 A=-2.7
20 PRINT INT(A)
30 A=2.7
40 PRINT INT(A)
50 END
RUN
-2
2
Ok

See also:
FIX, SGN, ABS

INTERVAL
(MSX-Basic)
Syntax:
INTERVAL ON
INTERVAL OFF
INTERVAL STOP
Function:
After "INTERVAL ON" the program checks if a specified time-interval has been elapsed. If so
MSX-Basic calls the subroutine that was specified with the "ON INTERVAL GOSUB" statement.
After the "INTERVAL OFF" statement no checking is performed. After "INTERVAL STOP" MSX-
Basic still checks if the interval has been elapsed, but calls the subroutine only after the next call of
"INTERVAL ON".
Example:
See: ON INTERVAL GOSUB
See also:
ON INTERVAL GOSUB

KEY
(MSX-Basic)
Syntax:
KEY number, string
Function:
Associates the function key identified by number (1-10) with a string. The string can have up to a
maximum of 15 characters.
Example:
10 A$="CLOAD"
20 KEY 1,A$+CHR$(13)
30 END

See also:
KEY LIST, KEY ON/OFF
KEY
(MSX-Basic)
Syntax:
KEY LIST
Function:
Lists the assignment of the function-keys (F1-F10).
Example:
KEY LIST
color
auto
goto
list
run
color 15,4,4
cload"
cont
list.

See also:
KEY (assignment), KEY ON/OFF

KEY
(MSX-Basic)
Syntax:
KEY ON
KEY OFF
Function:
"KEY ON" enables and "KEY OFF" disables the display of the function-key assignment in line 25
(only in textmodes 1 and 2).
Example:
KEY OFF

See also:
KEY (assignment), KEY LIST

KEY
(MSX-Basic)
Syntax:
KEY(number) ON
KEY(number) OFF
KEY(number) STOP
Function:
number specifies a function-key number (1-10).
After the "KEY(number) ON" statement MSX-Basic checks if the specified function-key was
pressed. If so MSX-Basic calls the subroutine, that was defined by the "ON KEY GOSUB"
statement.
After the statement "KEY(number) STOP" MSX-Basic checks if the specified function-key was
pressed, but does not call the defined subroutine until the next invocation "KEY(number) ON".
Example:
See: ON KEY GOSUB
See also:
ON KEY GOSUB

FOR
(MSX-Basic)
Syntax:
FOR <variable>=<number> TO <number2> [STEP <number3>]
NEXT [<variable> [,<variable2>][, ...]]]
Function:
This instruction forms a program loop that looks like:
FOR <variable>=X TO Y [STEP Z]
.
. Instructions
.
NEXT <variable>
The instructions between FOR and NEXT are executed with values from X to Y. If STEP Z is not
specified a step-width of 1 is used. Within a loop another loop can be implemented, so loops can be
nested.
Every loop will be executed at least once because the termination-condition is checked in the NEXT
statement.
Example:
10 FOR I=1 TO 4
20 PRINT I;
30 NEXT:PRINT
40 FOR I=0 TO 5 STEP 5
50 FOR J=0 TO I+2
60 PRINT J
70 NEXT J,I:PRINT
80 END

See also:
CALL PAUSE

LEFT$
(MSX-Basic)
Syntax:
LEFT$(string, number)
Function:
Returns the first number (0-255) characters from the specified string. If number is larger than the
string the whole string is returned. If number is 0 an empty string is returned.
Example:
10 A$="MSX-Computer"
20 FOR I=1 TO LEN(A$)
30 PRINT LEFT$(A$,I)
40 NEXT I
RUN
M
MS
MSX
MSX-
MSX-C
MSX-Co
MSX-Com
MSX-Comp
MSX-Compu
MSX-Comput
MSX-Compute
MSX-Computer

See also:
MID$, RIGHT$

LEN
(MSX-Basic)
Syntax:
LEN(string)
Function:
Returns the number of characters in the string.
Example:
PRINT LEN("BASIC")
5

See also:

LET
(MSX-Basic)
Syntax:
[LET] variable=value
Function:
Assigns a value to the specified variable. The LET statement itself is optional and can be skipped.
Example:
LET A=10
LET B$="Hello"
C=20
D$="World"

See also:
SWAP

LINE
(MSX-Basic)
Syntax:
LINE[[STEP](x1,y1)]-[STEP](x2,y2)[,color [,B[F]]]
Function:
Draws a line from x1,y1 to x2,y2, which can be absolute or relative ("STEP" keyword) coordinates.
If the word "STEP" is used x1 and y1 are interpreted relative to the current cursor-position. In this
case the values can also be negative.
x2 and y2 are the coordinates of the line-endpoint. If the word "STEP" is specified these are also
relative to the cursor-position.
color is the line-color to be used for drawing (see color-table). If color is not specified the current
foreground-color is used. If "B" is specified a rectangle is drawn, where the current line is used as
diagonal.
If "F" after "B" is specified the rectangle is filled with the given color.
Example:
10 SCREEN 2
20 FOR I=0 TO 95 STEP 2
30 LINE (128-I,95-I)-(128+I,95+I),1,B
40 NEXT
50 FOR K=0 TO 2000:NEXT
60 END

See also:
CIRCLE, DRAW, PSET, PAINT, SCREEN, CLS

LINE INPUT
(MSX-Basic)
Syntax:
LINE INPUT ["prompt";] stringvariable
LINE INPUT #channel, stringvariable
Function:
Retrieves a whole line, up to 254 characters, from the keyboard into the specified stringvariable. A
given prompt (if any) is printed first.
The LINE INPUT# statement is used to read a complete record from a sequential file (opened as
#channel), which must have been opened for "INPUT". The "LINE INPUT" statement is often used
to read a MSX-Basic program as datafile, if it was saved (by using the "SAVE" statement) in ASCII
format.
Example:
10 LINE INPUT "TEXT";A$
20 PRINT A$
30 END
RUN
TEXT
Ok

See also:
INPUT, GET, PRINT, OPEN

LIST
(MSX-Basic)
Syntax:
LIST [[startline] [-[endline]]]
Function:
Lists a whole or part of the Basic-program from memory.
If only startline is given this line is listed only. If startline and endline are specified all lines within
this range are listed. If only endline is given all lines from the beginning to this line are listed. If
neither startline nor endline are given the whole program is listed. If startline and "-" are given then
this line and all followings are listed.
Example:
LIST 10

Program line 10 is listed only.


LIST 50-100

Program lines 50 to 100 are listed.


LIST -100

All program lines from 0 to 100 are listed.


LIST

All program lines are listed.


LIST .

The last maintained line is listed.


See also:
LLIST

LLIST
(MSX-Basic)
Syntax:
LLIST [[startline] [-[endline]]]
Function:
A complete program or part of it is printed. The statement works in the same way as "LIST".
Example:
See LIST
See also:
LIST

LOAD
(MSX-Basic, Disk-Basic)
Syntax:
LOAD "devicename:filename" [,R]
Function:
Loads a program from a device into the computer-memory.
Devicenames can be, e.g.: CAS:, A: or B:
The "SAVE" statement must have been used to store the program in ASCII format (on tape or disk).
The filename is an alphanumerical constant, that has been specified while the program was stored
using the "SAVE" statement.
Disk-Basic: if ",R" is specified the programm is started immediately, after the load-operation is
finished.
Turbo-R: the "CAS:" device is no longer supported!
Example:
LOAD "CAS:DEMO"

"LOAD CAS:" can only be used if a tape-recorder is connected to the MSX-Computer.


LOAD "A:DEMO"

"LOAD A:" or "LOAD B:" can only be used if a disk-drive is connected to the MSX-Computer.
See also:
BLOAD, CALL MFILES, CLOAD, FILES, MERGE, RUN, SAVE

LOCATE
(MSX-Basic)
Syntax:
LOCATE line, column [,cursoronoff]
Function:
Places the cursor to the position specified by line and column, where 0,0 is the upper left corner.
Option cursoronoff toggles the cursor on/off. Usually the cursor is only visible during input, but
LOCATE,,1
can enable it at any time.
Example:
10 KEY OFF
20 LOCATE 1,23
30 PRINT "A"
40 LOCATE,,1
50 GOTO 50

See also:
CRSLIN, POS, PRINT

LOG
(MSX-Basic)
Syntax:
LOG(number)
Function:
Calculates the natural logarithm (base e=2.718281884588).
Example:
PRINT LOG(10)
2.302585092994
PRINT LOG(100)/LOG(10)
2

See also:
EXP

LPOS
(MSX-Basic)
Syntax:
LPOS(number)
Function:
Returns the position in the printer-buffer. The result is not necessarily the physical position of the
printhead.
Example:
10 FOR I=1 TO 1000
20 LPRINT "Hello";
30 IF LPOS(0)>38 THEN LPRINT CHR$(13)
40 NEXT
50 END

See also:
LPRINT

LPRINT
(MSX-Basic)
Syntax:
LPRINT [USING "format";] [value [,value2 [,...]]] [;]
Function:
Prints information on the printer. The statement works in the same way as "PRINT".
Example:
See PRINT
See also:
PRINT, TAB, SPC, LPOS

MAXFILES
(MSX-Basic)
Syntax:
MAXFILES=number
Function:
Specifies the maximum number of files, that can be simultaneously open. number can be in range
from 0-15.
Technote: the MAXFILES statement is built by 2 basic tokens (MAX FILES)
Example:
10 MAXFILES=2
20 OPEN "CAS:DEMO" FOR INPUT AS #1
30 OPEN "LPT:" FOR OUTPUT AS #2
40 INPUT #1,A$
50 PRINT #2,A$
60 CLOSE
70 END

See also:
CLEAR, OPEN

MERGE
(MSX-Basic, Disk-Basic)
Syntax:
MERGE "[device:]filename"
Function:
Merges a program in memory with another from tape or disk. The lines to be merged must be saved
in ASCII by using the "SAVE" statement. If some new lines have the same numbers as in memory
the already existing lines will be replaced.
Turbo-R: the "CAS:" device is no longer supported!
Example:
MERGE "CAS:DEMO"

See also:
LOAD, SAVE
MID$
(MSX-Basic)
Syntax:
MID$( string, position [,characters])
MID$( string, position [,characters])=string2
Function:
(1) An alphanumerical expression consisting of characters number of characters (or up to the string-
end) beginning by position will be returned.
If characters is not specified or there are no more characters to the right of position then all
remaining characters is returned. If position if larger than LEN(string) then an empty string is
returned.
(2) Replaces parts of string by string2. Characters in string, beginning on position are replaced by
string2. If characters is not specified all characters of string2 are used, as long as enabled by the
length of string.
Disk-Basic: in addition to LSET and RSET also MID$ can be used to format strings, declared in the
FIELD statement.
Example:
10 A$="Basic MSX Computer"
20 PRINT MID$(A$,7,3)
30 END
RUN
MSX
Ok

10 A$="ABCDEFG"
20 PRINT A$
30 MID$(A$,4)="XYZ"
40 PRINT A$
50 END
RUN
ABCDEFG
ABCXYZG
Ok

See also:
LEFT$, RIGHT$, INSTR, LSET, RSET

MOD
(MSX-Basic)
Syntax:
number MOD number2
Function:
Calculates the dividend of an integer division.
Example:
PRINT 5 MOD 3
2
Ok
PRINT 5 MOD 5
0
Ok

See also:
AND, EQV, IMP, NOT, OR, XOR, MSX-Basic operators

MOTOR
(MSX-Basic)
Syntax:
MOTOR ON
MOTOR OFF
Function:
Turns the motor of the tape-recorder on or off. If "ON" or "OFF" is specified the motor is toggled.
This means that a switched on motor is turned off and a switched off motor is turned on.
Setting "ON" turns the motor on, setting "OFF" turns the motor off.
Turbo-R: MOTOR is no longer supported and will generate a "syntax error"
Example:
10 FOR I=1 TO 10
20 MOTOR
30 FOR J=1 TO 500:NEXT J
40 NEXT I

See also:
CLOAD, CLOAD?, CSAVE

NEW
(MSX-Basic)
Syntax:
NEW
Function:
Erases the Basic program in memory.
"NEW" is usually used to delete the computer memory before starting with a new Basic program.
Example:
NEW

See also:

NOT
(MSX-Basic)
Syntax:
NOT expression
Function:
Logical complement.
NOT 0 = 1
NOT 1 = 0
Example:
PRINT HEX$(NOT &H7FFF)
8000
Ok

100 INPUT "Y/N";A$


120 IF NOT A$="N" THEN PRINT "Yes" ELSE PRINT "No"
RUN
(Y/N)?N
No

See also:
AND, EQV, IMP, MOD, OR, XOR, MSX-Basic operators

OCT$
(MSX-Basic)
Syntax:
OCT$(number)
Function:
Converts the specified number into an octal value. An octal number consists of the digits 0 to 7.
Example:
PRINT OCT$(1023)
1777
Ok

See also:
BIN$, HEX$, STR$, VAL

ON ERROR
(MSX-Basic)
Syntax:
ON ERROR GOTO line
Function:
line is the 1st line of an error-handling routine.
If "ON ERROR GOTO" statement is set MSX-Basic jumps to the specified line of the error-handler
routine, whenever an error occurs.
"ERR" returns the corresponding errorcode and "ERL" returns the line-number where the error
occured.
If the statement "ON ERROR GOTO 0" is set MSX-Basic does not jump to a specific line. In this
case the normal error-handler takes place, stops the program and prints the error-message. Its
recommended to use "ON ERROR GOTO 0" for errors, which are not handled by another error-
handling routine.
If MSX-Basic recognizes an error while the error-handling routine is executed the common error is
displayed.
The "RESUME" statement returns from the error-handling routine to the program location where
the error occured.
Example:
See ERR
See also:
RESUME, ERL, ERROR, ERR

ON GOSUB
(MSX-Basic)
Syntax:
ON value GOSUB line [,line2 [,...]]
Function:
line1 respectively line2 are the 1st program-line of a subroutine.
The value determines, which subroutine MSX-Basic executes.
If, for example value is 3 a jump to the 3rd subroutine is performed.
If value is no integer it will be rounded down.
The value cannot be greater than 255 or negative.
Example:
10 FOR I=1 TO 3
20 ON I GOSUB 50,70,90
30 NEXT I
40 END
50 PRINT "I=";I;"subroutine line 50"
60 RETURN
70 PRINT "I=";I;"subroutine line 70"
80 RETURN
90 PRINT "I=";I;"subroutine line 90"
100 RETURN
RUN
I= 1 subroutine line 50
I= 2 subroutine line 70
I= 3 subroutine line 90
Ok

See also:
GOSUB

ON GOTO
(MSX-Basic)
Syntax:
ON value GOTO line [,line2 [,...]]
Function:
line1 and line2 are program line-numbers.
The value determines to which line number MSX-Basic jumps and where the program continues.
If, for example value is 3 a jump to the 3rd routine is performed.
If value is no integer it will be rounded down.
The value cannot be greater than 255 or negative.
Example:
10 FOR I=1 TO 3
20 ON I GOTO 50,70,90
30 NEXT I
40 END
50 PRINT "I=";I;"line 50"
60 GOTO 30
70 PRINT "I=";I;"line 70"
80 GOTO 30
90 PRINT "I=";I;"line 90"
100 GOTO 30
RUN
I= 1 line 50
I= 2 line 70
I= 3 line 90
Ok

See also:
GOTO

ON INTERVAL
(MSX-Basic)
Syntax:
ON INTERVAL=number GOSUB line
Function:
Calls a subroutine after the specified timeout has been elapsed. The timeout is number*1/60 (or
number*1/50) seconds. After this statement MSX-Basic automatically calls the subroutine in line in
the number of intervals.
During the processing of an errorhandler MSX-Basic automatically performs the "INTERVAL
OFF" statement.
Example:
10 ON INTERVAL=300 GOSUB 60
20 INTERVAL ON
30 FOR I=1 TO 10000:NEXT I
40 INTERVAL OFF
50 END
60 K=K+6:PRINT K;"seconds"
70 RETURN
RUN
6 seconds
12 seconds
Ok

See also:
INTERVAL ON/OFF/STOP
ON KEY
(MSX-Basic)
Syntax:
ON KEY GOSUB line [,line2 [,...]]
Function:
line, line2, ... are the first line number of the corresponding subroutine. line substitutes the
linenumber of the subroutine, which is called after the function-key 1 (F1) has been pressed, line2
references F2, and so on...
Before a subroutine can be called the "KEY(number) ON" statement must be executed. After doing
so MSX-Basic automatically checks if the corresponding function-key was pressed and calls the
associated subroutine.
During the processing of an errorhandler MSX-Basic automatically performs the "KEY(number)
OFF" statement.
Example:
10 KEY OFF
20 ON KEY GOSUB 70, 80, 90
30 KEY(1) ON:KEY(2) ON:KEY(3) ON
40 GOTO 60
50 PRINT " pressed"
60 GOTO 60
70 PRINT "F1";:RETURN 50
80 PRINT "F2";:RETURN 50
90 PRINT "F3";:RETURN 50

See also:
KEY ON/OFF/STOP

ON SPRITE
(MSX-Basic)
Syntax:
ON SPRITE GOSUB line
Function:
Calls a subroutine in line if two sprites are colliding. line is the first line of the subroutine.
The subroutine can only be called after the "SPRITE ON" statement has been executed. After this
statement MSX-Basic automatically calls this subroutine when two sprites are colliding.
During the processing of an errorhandler MSX-Basic automatically performs the "SPRITE OFF"
statement.
Example:
10 DATA 60,66,165,129,165,153,66,60
20 DATA 60,126,219,255,255,219,102,60
30 A$=""
40 FOR I=1 TO 8
50 READ A:A$=A$+CHR$(A)
60 NEXT I
70 B$=""
80 FOR I=1 TO 8
90 READ A:B$=B$+CHR$(A)
100 NEXT I
110 SCREEN 2,1:COLOR 15,4,1
120 ON SPRITE GOSUB 210
130 SPRITE$(0)=A$:SPRITE$(1)=B$
140 SPRITE ON
150 A=INT(RND(1)*256)
160 B=INT(RND(1)*256)
170 FOR I=0 TO 191
180 PUT SPRITE 0,(A,I),1
190 PUT SPRITE 1,(B,191-I),15
200 NEXT I:GOTO 140
210 SPRITE OFF
220 PLAY "L4CDEFEDCREFGAGFER"
230 PUT SPRITE 0,(0,208)
240 PUT SPRITE 1,(0,208)
250 I=191:RETURN
RUN

ON STOP
(MSX-Basic)
Syntax:
ON STOP GOSUB line
Function:
Calls a subroutine in CTRL+STOP keys are pressed simultaneously. line is the first line of the
subroutine.
The subroutine cann only be called after the "STOP ON" statement. After this instruction MSX-
Basic automically calls the subroutine when CTRL- and STOP keys are pressed simultaneously.
During the processing of an errorhandler MSX-Basic automatically performs the "STOP OFF"
statement.
Example:
10 ON STOP GOSUB 50
20 STOP ON
30 INPUT A$
40 IF A$="END" THEN STOP OFF:END ELSE GOTO 30
50 PRINT "Enter END and press Return":RETURN
RUN
END
Ok

See also:
STOP ON/OFF/STOP

ON STRIG
(MSX-Basic)
Syntax:
ON STRIG(stick) GOSUB line, line2, ...
Function:
Pressing a "fire-button" calls a subroutine. line respectively line2 is the first line of the
corresponding subroutine.
line corresponds to the first line number of the subroutine which is called if the Space key is
pressed, where line2 is the line-number to be called if the key on Joystick 1 is pressed, and so on.
The subroutine can only be called after the "STRIG(stick) ON" statement. After this instruction
MSX-Basic automically calls the subroutine when a fire-button is pressed.
During the processing of an errorhandler MSX-Basic automatically performs the "STRIG(stick)
OFF" statement.
Example:
10 CLS
20 ON STRIG(X) GOSUB 50
30 STRIG(0) ON
40 GOTO 40
50 LOCATE 5,5
60 PRINT "SPACE key pressed"
70 FOR I=1 TO 300:NEXT I
80 LOCATE 5,5:PRINT SPC$(17)
90 RETURN
RUN

See also:
STRIG ON/OFF/STOP

OPEN
(MSX-Basic, Disk-Basic, RS232-Basic)
Syntax:
OPEN "device:filename" [FOR direction] AS #channel [LEN=recordlength]
Function:
Opens an input- or output-channel from or to the specified device.
device-name for MSX-Basic can be (for example):
Device name device type
CRT: screen (text-mode)
GRP: screen (graphic-mode)
LPT: printer
CAS: tape (not supported on MSX Turbo-R)
A: Disk drive
B: Disk drive
COM: RS232 (serial interface)
MEM: MSX2 RAM-Disk
filename is the name of the file, which is about to be opened. The filename must not specified for
screen-modes and printer.
direction indicates if the file is to be read into the buffer, or the buffer should be written to the file.
The following keywords can be specified:
INPUT = sequential read
OUTPUT = sequential write
APPEND = sequential write to the end of an existing file
If the FOR direction is not specified MSX-Basic assumes that the file is a random file. In this case a
file is created, if not found on the disk of a disk-drive.
Not every direction can be used for all device names. Allowed combinations are as following:
Device name OUTPUT INPUT APPEND
CRT: X - -
GRP: X - -
LPT: X - -
CAS: X X -
A: X X X
B: X X X
COM: X X -
MEM: X X X
RS232: Note that random access to a channel is illegal. Only sequential accesses are logically
possible.
channel is the file-number, as long as the file is opened. This number is used to operate with
Input/Output instructions (such as "INPUT#", "PRINT#", "CLOSE#") on the file.
recordlength is an integer. If set it specifies the record-length of a random-file. The default-value is
256.
Before an I/O operation is performed the file has to be opened first. The maximum number of
simultaneously opene files can be specified by the "MAXFILES" statement.
Example:
OPEN "CAS:TEST" FOR OUTPUT AS #1
PRINT #1,X

The value of X is saved in a file named "TEST" (on tape). I.e. it's possible to read the stored value
using:
OPEN "CAS:TEST" FOR INPUT AS #2
INPUT #2,X

10 SCREEN 2:COLOR 15,4,7


20 OPEN "GRP:" FOR OUTPUT AS #1
30 LINE (32,32)-(120,120),6,B
40 CIRCLE (120,120),56,1
50 PRESET (40,8)
60 PRINT #1,"Text in graphic screen"
70 FOR I=1 TO 2000: NEXT I
80 END
RUN

See also:
CLOSE, INPUT#, PRINT#, EOF, LOC, LOF, MAXFILES, RAM-Disk in MSX-Basic 2

OR
(MSX-Basic)
Syntax:
number1 OR number2
Function:
Logical inclusive or.
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
Example:
See also:
AND, EQV, IMP, MOD, NOT, XOR, MSX-Basic operators

OUT
(MSX-Basic)
Syntax:
OUT port,value
Function:
Writes a value to an output-port. value and port must be in range from 0 to 255.
To read a byte from an input-port the function "INP" must be used.
Example:
See also:
INP, WAIT

PAD
(MSX-Basic)
Syntax:
PAD( <number> )
Function:
Returns the position on the touchpad. One or more touchpads can be connected on the joystick-
port(s).
<number> is an integer between 0 and 7. If <number> has a value between 0 and 3 it's assumed
that the touchpad is connected to port 1. If <number> has a value between 4 and 7 the touchpad is
connected to port 2.
If <number> is 0 or 4 the state of the touchpad is returned. The function returns -1, if the pad is
touched and 0 if not.
If <number> is 1 or 5 the X-coordinate is returned, if <number> is 2 or 6 the Y-coordinate is
returned.
If <number> is 3 or 7 the state of the button on the touchpad is returned. This function returns -1 if
the button is pressed and 0 is not.
MSX 2 and MSX 2+:
If <number> is in range from 8 to 11 PAD is used to retrieve the state of a lightpen.
Note: this support is removed at the MSX Turbo-R, therefore such computers will return 0 in this
case.
MSX 2 and higher:
If <number> is 12 the X/Y-offset of the mouse in port 1 is retrieved and can be queried by using
PAD(13) and PAD(14). The return-value of PAD(12) is always -1.
If <number> is 13 the X-offset of the mouse in port 1 is returned (-128 to +127)
If <number> is 14 the Y-offset of the mouse in port 1 is returned (-128 to +127)
If <number> is 15 the return-value is 0 (reserved for mouse in port 1).
If <number> is 16 the X/Y-offset of the mouse in port 2 is retrieved and can be queried by using
PAD(17) and PAD(18). The return-value of PAD(16) is always -1.
If <number> is 17 the X-offset of the mouse in port 2 is returned (-128 to +127)
If <number> is 18 the Y-offset of the mouse in port 2 is returned (-128 to +127)
If <number> is 19 the return-value is 0 (reserved for mouse in port 2).
Please note that the button-state of the mouse must be retrieved with the STRIG-function.
Example:
10 SCREEN 2
20 A=0
30 IF PAD(0)=0 THEN 20
40 X=PAD(1):Y=PAD(2)
50 IF A=0 THEN PSET(X,Y) ELSE LINE-(X,Y)
60 A=1
70 GOTO 30

See also:
PDL, STICK, STRIG

PAINT
(MSX-Basic)
Syntax:
PAINT [STEP](x,y)[,color][,bordercolor]
Function:
Fills a drawing in graphics mode with the specified color.
x is the X-coordinate of the starting point and must be an integer between 0 and 255 (or 511).
y is the Y-coordinate of the starting point and must be an integer between 0 and 191 (or 211).
If the word "STEP" is used the values of x and y are depending on the current cursor-position. In
this case x and y can be negative too.
color is the color-number to be used for filling.
bordercolor is the color-number of the border-line.
In graphic-mode 1 the fill-color must be equal to the border-color. In this case bordercolor does not
need to be specified. In graphic-mode 2 (and higher) fill-color and border-color can be different.
color and bordercolor must be integers between 0 and 15. See: color-table
Example:
10 SCREEN 2:COLOR 15,4,7
20 CIRCLE (80,80),20,8
30 PAINT (80,80),8
40 FOR I=1 TO 2000:NEXT I
50 SCREEN 3:COLOR 15,4,7
60 LINE (10,10)-(100,100),8,B
70 PAINT (45,45),2,8
80 FOR I=1 TO 2000:NEXT I
90 END
RUN

See also:
CIRCLE, DRAW, LINE, PSET, SCREEN, CLS
PDL
(MSX-Basic)
Syntax:
PDL( <number> )
Function:
Returns the position of a paddle. One or two paddles can be connected to the joystick-port(s).
This function returns a value between 0 and 255.
<number> is a number from 1 to 12. If <number> is 1, 3, 5, 7, 9 or 11 so the paddle is connected to
port 1. If <number> is 2, 4, 6, 8, 10 or 12 the paddle is connected to port 2.
Example:
10 CLS
20 FOR I=1 TO 500
30 LOCATE 10,5:PRINT PDL(1),PDL(2)
40 NEXT I
50 END

See also:
PAD, STICK, STRIG

PEEK
(MSX-Basic)
Syntax:
PEEK(address)
Function:
Returns a memory-byte.
This function returns the decimal-value of a memory-address and therefore results in a value
between 0 and 255.
address is the memory-address and must be in range between -32768 and 65535.
If address is negative the binary complement is used. This means PEEK(-1)=PEEK(65536-
1)=PEEK(65535).
The "POKE"statement is used to write a byte to a specific memory-address.
Example:
10 A=PEEK(65535)
20 A$="00"+HEX$(A)
30 PRINT RIGHT$(A$,2)
40 END
RUN
F0
Ok

See also:
POKE, VPEEK, BLOAD, BSAVE, VARPTR
PLAY
(MSX-Basic)
Syntax:
PLAY "string" [,"string2"[,"string3"]]
Function:
This functions plays the notes specified in string. In this string you can also specify the pitch,
duration, tempo and pause.
string, string2 and string3 are sub-commands built by alphanumeric constants. string corresponds
to voice 1, string2 to voice 2 and string3 to voice 3.
To play a note from the scale: the following sub-commands are creating a note from the scale: A, B,
C, D, E, F and G. A "+" or "#" after a note are indicating an -is (increased by a halftone) where A "-"
indicates an -es (decreased by a halftone.
To set an octave: the sub-command "Onumber" sets the octave-number, which should be played.
number is an integer from 1 to 8.
If no octave is specified the last used octave is used. The default value is 4.
To play a note-number: instead of playing an octave-number and a note-number music-note-
numbers can be specified also. The sub-command "Nnumber" is used to specify a note-number.
number is an integer between 0 and 95. If number is 0 no sound is generated. In this case a short
pause is played before the remaining part.
To specify a note-length: the note-length is specified by the sub-command "Lnumber". number is an
integer between 1 and 64 and has the following meaning:
1 = full note
2 = half note
3 = third note
4 = quarter note
and so on.
If no length is specifed the last used note is used. The default value is 4.
To change a note-length: by adding a dot (.) direct after specifying a note the length is multiplied by
1/2. You can also add multiple dots; e.g. "..." means the note is played in 15/8 times the speed of its
original length.
To set a pause: the sub-command "Rnumber" is used to set a pause. number is an integer between 1
and 64 and has the following meaning:
1 = full pause
2 = half pause
3 = third pause
4 = quarter pause
and so on.
To set a tempo: the tempo is set with the sub-command "Tnumber". number is an integer from 32 to
255 and indicates the number of quarter notes per minute. If no tempo is set the last tempo will be
used. The default value is 120.
To set an envelope: the envelope is set with the sub-command "Snumber". number is an integer
from 0 to 15.
If no envelope is specified the last set value will be used. The default value is 1.
Sound modulation: the sound-period is specified with the sub-command "Mnumber". number is an
integer from 1 to 65536 and sets the sound-period.
If no modulation is specified the last set modulation will be used. The default value is 255.
To start execution: The music instructions in an alphanumeric variable can be executed with the
sub-command "XA$;" (don't forget the semicolon!).
A$ is the name of the variable that contains the musical sub-commands. Numeric variables can be
used instead of numeric values in sub-commands. In this case an equal sign (=) has to be specified
before these numeric variables and they have to be terminated with a semicolon (;), e.g.:
AB=10:PLAY "N=AB;".
If MSX-Basic generates a beep-sound all values of the sub-commands will be reset to their default
values!
Example:
PLAY "O5CDEFGABO6C"

10 A$="T128"
20 B$="L4CCFGL2AL8FEL4D.L8B-L4B"
30 PLAY "XA$;"
40 PLAY "XB$;"
50 END
RUN

See also:
BEEP, PLAY(), PLAY (MSX-Music)

PLAY
(MSX-Basic)
Syntax:
PLAY(voice)
Function:
Returns the state of playing music.
voice has the following meaning:
0 = voice1, voice 2 and voice 3
1 = voice 1
2 = voice 2
3 = voice 3
The function returns -1 if the selected voice is playing. If playing has ended the function returns 0
again.
If the function is called immediately after the "PLAY" statement the value -1 is persistent.
Example:
10 A$="":BEEP
20 FOR I=1 TO 6
30 READ AA$:A$=A$+AA$
40 NEXT I
50 PLAY "XA$;"
60 SCREEN 0:WIDTH 35:CLS
70 IF PLAY(0)=-1 THEN PRINT "The music is playing":GOTO 70
80 PRINT "The music has ended"
90 END
100 DATA CCGGAAGR
110 DATA FFEEDDCR
120 DATA GGFFEEDR
130 DATA GGFFEEDR
140 DATA CCGGAAGR
150 DATA FFEEDDCR
RUN

See also:
PLAY

POINT
(MSX-Basic)
Syntax:
POINT(x,y)
Function:
Returns the color-number of the specified point in graphics-mode.
x is the X-coordinate and must be an integer between 0 and 255 (or 0 and 511).
y is the Y-coordinate and must be an integer between 0 and 191 (or 0 and 211).
Example:
10 SCREEN 2:COLOR 15,1,7
20 OPEN "GRP:" FOR OUTPUT AS #1
30 FOR I=1 TO 10
40 PRESET(I*16,8)
50 C=INT(RND(1)*13)+2
60 COLOR C
70 PRINT #1,CHR$(1)+CHR$(66)
80 NEXT I
90 COLOR 15
100 PRESET (40,24)
110 PRINT #1,"Color numbers"
120 FOR I=1 TO 20
130 C=POINT(I*16+4,12)
140 PRESET(I*16,I*8+56),4
150 PRINT#1,USING "##";C
160 NEXT I
170 FOR I=1 TO 2000:NEXT I
180 COLOR 15,4,7
190 END
RUN

See also:
PSET

POKE
(MSX-Basic)
Syntax:
POKE adress,value
Function:
Fills a byte in memory adress with a byte of value.
address is the memory-address and must be in range between -32768 and 65535.
If address is negative the binary complement is used. This means POKE-1,0=POKE(65536-1),0.
This function is used to change the value of a specific byte in memory.
Example:
10 POKE 65534,PEEK(65534)
20 END
RUN
Ok

See also:
PEEK, VPOKE, BLOAD, BSAVE, DEFUSR, VARPTR

POS
(MSX-Basic)
Syntax:
POS(number)
Function:
Gives the X-coordinate (column-number) of the cursor.
This function returns a number between 0 and 39 (or 0 and 79). The most left column is 0. This
function can only be used in text mode.
Example:
10 SCREEN 0
20 LOCATE 10,20
30 PRINT POS(0)
30 END
RUN
10
Ok

See also:
CSRLIN, LOCATE

PRESET
(MSX-Basic)
Syntax:
PRESET [STEP](x,y)[,color]
Function:
Sets a color into the specified point at x,y in graphics mode.
x is the X-coordinate of the point and must be an integer between 0 and 255 (or 0 and 511).
y is the Y-coordinate of the point and must be an integer between 0 and 191 (or 0 and 211).
If the word "STEP" is used values for x and y are relative to the current cursor-position. In this case
x and y can be negative too.
color is the color-number and must be an integer between 0 and 15 (see: color-table).
If color is not set the last used background-color will be assumed. The default-value of color is 4.
Example:
10 SCREEN 2:COLOR 15,4,7
20 LINE (40,40)-(215,151),15,BF
30 FOR I=0 TO 1000
40 A=INT(RND(1)*173)+41
50 B=INT(RND(1)*109)+41
60 PRESET(A,B)
70 FOR K=0 TO 300:NEXT K
80 NEXT I
90 END
RUN

See also:
PSET, CIRCLE, DRAW, LINE, PAINT, SCREEN, CLS

PRINT
(MSX-Basic, Disk-Basic)
Syntax:
PRINT [USING "format";] [value [,value2 [,...]]] [;]
PRINT #channel, [USING "format";] variable
Function:
The first format is used to display data on the screen. If the word PRINT is used without suffix
MSX-Basic generates an empty line. If an expression is added it's value is displayed on the screen.
The expression can be of numeric or alphanumeric type. In case of alphanumeric constants these
have to be quoted (e.g. 10 PRINT "Hello").
Print position: The position where the printout appears on the screen depends on the punctation
between different values (expressions). MSX-Basic separates each screen-line into zones of 14
positions. If a value is followed by a colon (,) the next output appears in the next zone. If the value
is followed by a semicolon (;) the next output appears immediately behind the last value. If a
"PRINT" statement ends with a colon (,) or a semicolon (;) the output of the next "PRINT"
statement appears on the same screen-line. If a "PRINT" statement does not end with a colon (,) or a
semicolon (;) the output of the next "PRINT" statement appears in the next line. If the number of
positions in the printout is larger than the number of positions per screen-line (defined by the
"WIDTH" statement) MSX-Basic automatically continues in the next line.
Numbers: Behind each number, that is displayed on the screen, is always a space. In front of
positive numbers is a space, in front of negative numbers a minus (-).
The 2nd format of the "PRINT" statement is used to write data into a sequential file (opened as
#channel) opened for OUTPUT. After every "PRINT" statement a 'CR' and 'LF' character is written
into the file. MSX-Basic automatically places a colon "," between numerical expressions in a simple
"PRINT" statement as well as a hyphen if printing goes to a file. Alphanumerical expressions have
to be separated by a colon and a hyphen. To read data from a file with uniform records the statement
"INPUT#" can be used.
Printing formats: printout can be formatted, if preceded by "USING". Possible syntax of the
specified format is documented in the chapter "USING".
Instead of the keyword "PRINT" also a question mark (?) can be used.
Example:
? "Hello"
Hello

PRINT "World"
World
10 CLS
20 FOR I=1 TO 5
30 ? USING "Number is #.#-";I
40 NEXT

See also:
LPRINT, TAB, SPC, PUT, INPUT, CLS, WIDTH, LOCATE, OPEN, INPUT[#]

PSET
(MSX-Basic)
Syntax:
PSET [STEP](x,y)[,color]
Function:
Sets a color into the specified point at x,y in graphics mode.
x is the X-coordinate of the point and must be an integer between 0 and 255 (or 0 and 511).
y is the Y-coordinate of the point and must be an integer between 0 and 191 (or 0 and 211).
If the word "STEP" is used values for x and y are relative to the current cursor-position. In this case
x and y can be negative too.
color is the color-number and must be an integer between 0 and 15 (see: color-table).
If color is not set the last used foreground-color will be assumed. The default-value of color is 15.
Example:
10 SCREEN 2:COLOR 15,4,7
20 LINE (40,40)-(215,151),15,B
30 FOR I=0 TO 1000
40 A=INT(RND(1)*173)+41
50 B=INT(RND(1)*109)+41
60 PSET(A,B)
70 FOR K=0 TO 300:NEXT K
80 NEXT I
90 END
RUN

See also:
PRESET, CIRCLE, DRAW, LINE, PAINT, POINT, SCREEN, CLS

PUT SPRITE
(MSX-Basic)
Syntax:
PUT SPRITE priority, [STEP](x,y), color, number
Function:
Put a defined sprite in graphics mode on the screen.
priority specifies the priority of the sprite and must be an integer between 0 and 31.
x is the X-coordinate of the sprite and must be an integer between -32 and 255.
y is the Y-coordinate of the sprite and must be an integer between -32 and 191 or 208 or 209. If y is
208 all sprites with a lower priority will disappear from the screen. If y is 209 only this sprite will
disappear from the screen.
If the word "STEP" is specified the values x and y are relative to the current screen-position. In this
case x and y can be negative too. If x and y are not specified the actual coordinate remains
unchanged.
color is the color-number of the sprite and must be an integer between 0 and 15 (see: color-table).
If color is not set the last foreground-color will be used. The default-value is 15.
number is the number of the sprite, as used in SPRITE$(number). If number is not specified its
equal to the priority.
Example:
See: ON SPRITE GOSUB
See also:
SPRITE$, ON SPRITE GOSUB, SCREEN, COLOR SPRITE, COLOR SPRITE$

READ
(MSX-Basic)
Syntax:
READ variable [,variable2 [,...]]
Function:
Reads a constant from the "DATA" statement and assigns it to a variable.
The "READ" statement can only be used with a "DATA" statement. The "READ" statement gives
access to the data, listed after the "DATA" statement and in order of the line-numbers.
The variable in the "READ" statement can be numeric or alphanumeric. The type of the variable
must match with the corresponding constant in the "DATA" statement.
A single "READ" statement can give access to one or more "DATA" statements. Its also possible to
access the data of a single "DATA" statement with multiple "READ" statements.
If the number of variables in the "READ" statement is larger than the number of constants in the
"DATA" statement MSX-Basic generates an "Out of data" error.
If the number of variables in the "READ" statement is smaller than the number of constants in the
"DATA" statement the next "READ" statement continues with the remaining constants. If no more
"READ" statements are executed the remaining constants are ignored.
"DATA" statements can be specified since the program-start, or explicitly selected with a line-
number in the "RESTORE" statement.
Example:
See: DATA
See also:
DATA, RESTORE

REM
(MSX-Basic)
Syntax:
REM
'
Function:
Inserts a remark into the program text.
"REM" statements are not executed when the program runs, but printed if the program is listed.
The program use "GOTO" and "GOSUB" to link to a "REM" statement. In this case the program
execution continues at the statement behind the "REM".
Instead of the keyword "REM" also a single apostroph (') can be used. Do not use this keyword
within a "DATA" statement.
Example:
10 REM Calculation
20 FOR I=1 TO 10
30 SUM=SUM+I
40 NEXT I
50 SUM=SUM/10

or
10 FOR I=1 TO 10 'Calculation
20 SUM=SUM+I
30 NEXT I
40 SUM=SUM/10

See also:
DATA

RENUM
(MSX-Basic)
Syntax:
RENUM [line] [,line2 [,increment]
Function:
Renumbers program lines.
line is the first program-line, which is used in the new order. If line is not specified the order starts
in line 10.
line2 is the existing program-line where the re-ordering should start. If line2 is not specified the
order starts in the 1st program-line.
increment is the step-width of the new order. If increment is not specified MSX-Basic uses 10.
The statement "RENUM" renumbers also the line-numbers after the statements "GOTO",
"GOSUB", "IF THEN ELSE", "ON GOTO" and "ON GOSUB". The renumbered value is based on
the new line-number which has been changed due to the re-ordering. If a non-existing line-number
is recognized the error "Undefined line XX in YY" is raised.
The statement "RENUM" can not be used to change the order of line-numbers.
Example:
RENUM

This statement renumbers all program lines, beginning at the first line. The first line gots the
number 10. Subsequent line-numbers are increased by 10.
RENUM 1000,900,50

(new value=1000, previously 900, increment by 50)


This statement renumbers all program lines, beginning on line 900. Line 900 becomes line 1000
ands ubsequent line-numbers are increased by 50.
900 FOR I=1 TO 10
910 PRINT I;
920 IF I<10 THEN 930 ELSE 940
930 NEXT
940 END

1000 FOR I=1 TO 10


1050 PRINT I;
1100 IF I<10 THEN 1150 ELSE 1200
1150 NEXT
1200 END

See also:
AUTO

RESTORE
(MSX-Basic)
Syntax:
RESTORE [line]
Function:
The "RESTORE" statement sets the data-pointer to the first element of the "DATA" statement to
line of the program.
line is the line-number of a "DATA" statement. After a "RESTORE" is performed the first constant
of a "DATA" statement is returned by the "READ" statement.
If line is not specified the "READ" statement returns the 1st constant of the 1st "DATA" statement.
Example:
10 DATA 123,ABC,48.5
20 READ A%,A$,A!
30 PRINT A%;A$;A!
40 RESTORE
50 READ A%:PRINT A%
60 END
RUN

See also:
DATA, READ

RESUME
(MSX-Basic)
Syntax:
RESUME [line]
RESUME 0
RESUME NEXT
Function:
line is the line-number of the program, in which - after execution of the error-handling routine
specified by "ON ERROR GOTO" - the program will be resumed. If line is not specified or 0 the
program will be continued on the location where the error was detected.
If the keyword "NEXT" is used (instead of line) the program execution is resumed on the statement
immediately following the error-location.
Example:
See ERR
See also:
ON ERROR GOTO, ERL, ERROR, ERR

RETURN
(MSX-Basic)
Syntax:
RETURN [linenumber]
Function:
Returns from a subroutine that was invoked by GOSUB.
In contrast to other Basic dialects the RETURN statement can specify an explicit line-number
where the program can return to.
Example:
100 PRINT "Hello"
110 GOSUB 200
120 END
200 PRINT "Here am I"
210 RETURN 110

Generates an infinite loop because the subroutine always returns to it's invocation point:
Hello
Here am I
Here am I
...

See also:
GOSUB

RIGHT$
(MSX-Basic)
Syntax:
RIGHT$(string, number)
Function:
Returns the last number (0-255) characters from the right end of the specified string. If number is
larger than the string the whole string is returned. If number is 0 an empty string is returned.
Example:
10 A$="Basic"
20 FOR I=1 TO LEN(A$)
30 PRINT RIGHT$(A$,I)
40 NEXT
50 END
RUN
c
ic
sic
asic
Basic

See also:
LEFT$, MID$

RND
(MSX-Basic)
Syntax:
RND(number)
Function:
Generates a random-number between 0 and 1.
Whenever a program is started with "RUN" the same sequence of random-numbers is generated.
If number is greater than 0 the next random-value of the sequence is returned. If number is equal to
0 the last random-value of the sequence is returned.
If number is less than 0 the sequence of random-numbers is rebuilt based on the negative number.
To generate a real random-number the generator must always select a new sequence after the
program has been started. This can be ensured by using the variable "TIME".
Example:
10 R=RND(TIME)
20 FOR I=1 TO 10
30 SCREEN 2:COLOR 15,4,7
40 C=INT(RND(1)*15+1)
50 IF C=4 GOTO 40
60 CIRCLE (80,80),20,C
70 PAINT (80,80),C
90 NEXT I
100 END
RUN

See also:
TIME

RUN
(MSX-Basic, Disk-Basic)
Syntax:
RUN [line]
RUN "devicename:filename" [,line]
Function:
Starts the execution of a program, which is stored in the computer-memory or a device.
Devicenames can be, e.g.: CAS:, A: or B:
The "SAVE" statement must have been used to store the program in ASCII format (on tape or disk).
The filename is an alphanumerical constant, that has been specified while the program was stored
using the "SAVE" statement.
If devicename and filename are not specified the program in memory will be executed.
line corresponds to the program line-number. If line is specified the program starts in this line. If
line is not specified the program starts in the first line.
Turbo-R: the "CAS:" device is no longer supported!
Example:
RUN 100

(in this case the program execution starts in line 100)


See also:
LOAD, CALL RUN, END, STOP, CONT

SAVE
(MSX-Basic, Disk-Basic)
Syntax:
SAVE "devicename:filename" [,A]
Function:
Stores a program of the computer-memory onto a device (tape or disk).
If a program is saved to a tape ("CAS:") it can be restored with the "LOAD" and "MERGE"
statements.
Reminder:
CSAVE saves in binary format
SAVE "CAS:" saves in ASCII format onto tape
SAVE saves binary and SAVE...,A in ASCII code onto disk
Devicenames can be, e.g.: CAS:, A: or B:
Turbo-R: the "CAS:" device is no longer supported!
Example:
SAVE "CAS:DEMO"

See also:
BSAVE, CSAVE, LOAD, MERGE

SCREEN
(MSX-Basic)
Syntax:
SCREEN screenmode [,spritesize, keyclick, baudrate, printertype, interlacemode]
Function:
Specifies the screenmode, spritesize, sound on keypress, baudrate for the data-recorder and the used
printer-type.
screenmode may be specified from 0 to 3. When specifying a screen mode, in BASIC it is called
"SCREEN MODE", which is somewhat different from "screen mode" which is used by VDP
internally. The Screen-modes table shows these correspondences and meanings. The difference
between screen modes 2 and 4 is only in the sprite display functions.
If screenmode is not specified the last used screenmode remains unchanged. The default-value is 0.
The graphic-operations "PUT SPRITE", "CIRCLE", "DRAW", "LINE", "PAINT", "PSET",
"PRESET", "ON SPRITE GOSUB", "SPRITE ON/OFF/STOP" and "POINT" can only be used in
graphics-mode.
MSX 2: adds screenmodes 4-8.
Korean MSX 2: supports screenmode 9 too.
MSX 2+: adds screenmodes 10-12.
spritesize specifies the sprite-size.
0 small sprites (8x8 dots)
1 small sprites (enlarged to 16x16 dots)
2 large sprites (16x16 dots)
3 large sprites (enlarged to 32x32 dots)
If spritesize is not specified the last value remains unchanged. The default-value is 0.
keyclick specifies if a sound is generated when a key is pressed. The value should be 0 or 1 and has
the following meaning:
0 no sound
1 sound (key click)
If keyclick is not specified the last value remains unchanged. The default value is 0.
baudrate specifies the baud-rate of the data-recorder. The value must be 1 or 2 and has the
following meaning:
1 1200 baud
2 2400 baud
If baudrate is not specified the last value remains unchanged. The default value is 1.
printertype indicates if an MSX-Printer is used. The value should be 0 or 1 and has the following
meaning:
0 MSX-Printer
1 no MSX-Printer (e.g. Epson compatible)
If printertype is not specified the last value remains unchanged. The default value is 1.
interlacemode enables to set the interlace functions of VDP (see Interlace mode). In the alternate
screen display mode, the display page specified in "SET PAGE" must be odd. In this case the
display page and the page of which the number is smaller by one is displayed alternately.
If interlacemode is not specified the last value remains unchanged. The default value is 0.
MSX 2: adds screenmodes 4-8, interlacemode is added too. The values of the last used text
screenmode (0 or 1), keyclick, baudrate and printertype can be saved by using "SET SCREEN"
statement and will be restored from the CMOS on power-up.
Korean MSX 2: adds screenmode 9.
MSX 2+: adds screenmodes 10-12 (mode 9 is supported on Korean computers only).
Turbo-R: the baudrate setting is ignored.
Example:
10 FOR I=2 TO 3
20 SCREEN I:COLOR 15,4,7
30 LINE (32,32)-(200,132),6
40 FOR K=0 TO 3000:NEXT
50 NEXT I
60 END
RUN

See also:
PRINT, INPUT, CIRCLE, DRAW, LINE, PAINT, PSET, PRESET, WIDTH, CLS, CALL CLS,
CALL KANJI, CALL ANK, SET PAGE, SET SCREEN

SGN
(MSX-Basic)
Syntax:
SGN(number)
Function:
Returns the value 1 if number is > 0, returns the value 0 if number is = 0 and returns the value -1 if
number is < 0.
Example:
10 INPUT "Number";N
20 IF N<-1 OR N>1 THEN GOTO 10
30 H=SGN(N):H=H+2
40 ON H GOSUB 70,80,90
50 PRINT B$
60 END
70 B$="Number is negative":RETURN
80 B$="Number is zero":RETURN
90 B$="Number is positive":RETURN
RUN

See also:
ABS

SIN
(MSX-Basic)
Syntax:
SIN(number)
Function:
Returns the sinus of the specified number in radians.
Example:
10 X=5
20 PRINT SIN(X)
30 END
RUN

See also:
ATN, COS, TAN

SOUND
(MSX-Basic)
Syntax:
SOUND register, value
Function:
Writes a value into the PSG register.
register is the register-number and must be an integer betwenn 0 and 15.
value is the value to be written into the register. This must be an integer between 0 and 255.
USE THIS STATEMENT ONLY IF YOU ARE FAMILIAR WITH THE PSG (PROGRAMMABLE
SOUND GENERATOR).
Example:
10 FOR I=0 TO 13
20 SOUND I,0
30 NEXT I
40 SOUND 7,62:SOUND 8,15
50 FOR I=0 TO 255
60 SOUND 0,I
70 NEXT I
80 SOUND 8,0
90 END
RUN

See also:
PLAY, BEEP, CALL AUDREG (MSX-Music)

SPACE$
(MSX-Basic)
Syntax:
SPACE$(number)
Function:
Generates an alphanumeric string with number of spaces.
number must be an integer between 0 and 255.
Example:
10 FOR I=0 TO 5
20 A$=SPACE$(I)
30 PRINT A$;I
40 NEXT I
50 END
RUN
1
2
3
4
5
Ok

See also:
STRING$, TAB, SPC

SPC
(MSX-Basic)
Syntax:
SPC(number)
Function:
Prints number of characters.
This function can only be used with "PRINT" and "LPRINT" statements.
number must be an integer between 0 and 255.
Example:
See also:
PRINT, LPRINT, TAB, SPACE$, STRING$

SPRITE
(MSX-Basic)
Syntax:
SPRITE ON
SPRITE OFF
SPRITE STOP
Function:
Checks for sprite-collisions.
After the "SPRITE ON" statement MSX-Basic checks with every statement if two sprites are
overlapping. If so MSX-Basic calls the subroutine, that was specified in the "ON SPRITE GOSUB"
statement.
If the "SPRITE OFF" statement is set, MSX-Basic does no longer check for collisions.
After the "SPRITE STOP" statement MSX-Basic checks for collisions, but does not call the
subroutine that was specified in the "ON SPRITE GOSUB" statement. But collisions are
remembered. In this case the subroutine is immediately called after the "SPRITE ON" statement is
executed.
Example:
10 DATA 60,66,165,129,165,153,66,60
20 DATA 60,126,219,255,255,219,102,60
30 A$=""
40 FOR I=1 TO 8
50 READ A:A$=A$+CHR$(A)
60 NEXT I
70 B$=""
80 FOR I=1 TO 8
90 READ A:B$=B$+CHR$(A)
100 NEXT I
110 SCREEN 2,1:COLOR 15,4,1
120 ON SPRITE GOSUB 210
130 SPRITE$(0)=A$:SPRITE$(1)=B$
140 SPRITE ON
150 A=INT(RND(1)*256)
160 B=INT(RND(1)*256)
170 FOR I=0 TO 191
180 PUT SPRITE 0,(A,I),1
190 PUT SPRITE 1,(B,191-I),15
200 NEXT I:GOTO 140
210 SPRITE OFF
220 PLAY "L4CDEFEDCREFGAGFER"
230 PUT SPRITE 0,(0,208)
240 PUT SPRITE 1,(0,208)
250 I=191:RETURN
RUN

See also:
ON SPRITE GOSUB

SPRITE$
(MSX-Basic)
Syntax:
SPRITE$(number)=string
Function:
Contains the definition of sprites in graphic mode.
number stays for the number of sprites. If the sprite-size has been specified with 0 or 1 (by using the
"SCREEN" statement), then number must be an integer between 0 and 255. If the sprite-size has
been specified with 2 or 3, then number must be an integer between 0 and 63.
The contents of the variable "SPRITE$" can be a binary, a hexadecimal or decimal value - as down
in the following example:
Binary Hexadecimal Decimal
&B00011000 &H18 24
&B00111100 &H3C 60
&B01111110 &H7E 126
&B11111111 &HFF 255
&B00100100 &H24 36
&B00100100 &H24 36
&B01000010 &H42 66
&B10000001 &H81 129
Binary definition:
10 SCREEN 2,0
20 Y=1
30 B$=""
40 FOR I=1 TO 8
50 READ A$:B$=B$+CHR$(VAL("&B"+A$))
60 NEXT I
70 SPRITE$(0)=B$
80 FOR X=1 TO 200
90 Y=Y+1
100 PUT SPRITE 0,(X,Y)
110 NEXT X
120 END
130 DATA
00011000,00111100,01111110,11111111,00100100,00100100,010000010,10000001

Hexadecimal definition:
10 SCREEN 2,0
20 Y=1
30 B$=""
40 FOR I=1 TO 8
50 READ A$:B$=B$+CHR$(VAL("&H"+A$))
60 NEXT I
70 SPRITE$(0)=B$
80 FOR X=1 TO 200
90 Y=Y+1
100 PUT SPRITE 0,(X,Y)
110 NEXT X
120 END
130 DATA 18,3C,7E,FF,24,24,42,81

Decimal definition:
10 SCREEN 2,0
20 Y=1
30 B$=""
40 FOR I=1 TO 8
50 READ A$:B$=B$+CHR$(VAL(A$))
60 NEXT I
70 SPRITE$(0)=B$
80 FOR X=1 TO 200
90 Y=Y+1
100 PUT SPRITE 0,(X,Y)
110 NEXT X
120 END
130 DATA 24,60,126,255,36,36,66,129

Example:
See: ON SPRITE GOSUB
See also:
PUT SPRITE, ON SPRITE GOSUB

SQR
(MSX-Basic)
Syntax:
SQR(number)
Function:
Returns the square-root of the specified number.
Example:
10 X=10:Y!=SQR(X)
20 PRINT Y!
30 END
RUN
3.16228
Ok

See also:

STICK
(MSX-Basic)
Syntax:
STICK(sticknumber)
Function:
This function returns the direction of the joystick. The meaning of the returnvalue is as following:
8 1 2
7 0 3
6 5 4
The sticknumber can have the following values:
0 = Cursor-keys (space is trigger)
1 = Joystick on port 1
2 = Joystick on port 2
Example:
10 PRINT "Press the cursor-keys"
20 PRINT STICK(0)
30 FOR I=0 TO 300:NEXT I
40 GOTO 20
RUN

See also:
PAD, PDL, STRIG, INKEY$, ON GOSUB, ON GOTO

STOP
(MSX-Basic)
Syntax:
STOP
Function:
Terminates a programs execution. When the interpreter reaches the last line of the program, it is
automaticly terminated, STOP is not necessary there. After STOP a CONT instruction can continue
the program execution on the next line.
Example:
10 PRINT "Test"
20 STOP
30 PRINT "CONT was used"
40 END
RUN

See also:
END, RUN, CONT

STOP
(MSX-Basic)
Syntax:
STOP ON
STOP OFF
STOP STOP
Function:
Checks if the CTRL and STOP keys are pressed simultaneously.
After the "STOP" stamement MSX_Basic checks with every statement if the CTRL+STOP keys are
pressed simultaneously. If so the MSX-Basic program calls the subroutine that was specified in the
"ON STOP GOSUB" statement.
After the "STOP OFF" statement MSX-Basic does no no longer check if CTRL+STOP keys are
pressed simultaneously.
After the "STOP STOP" statement MSX-Basic checks if CTRL+STOP are pressed simultaneously,
but does not call the subroutine that was specified in the "ON STOP GOSUB" statement. But the
state is remembered. In this case the subroutine is immediately called after the "STOP ON"
statement is executed.
Example:
10 ON STOP GOSUB 50
20 STOP ON
30 INPUT A$
40 IF A$="END" THEN STOP OFF:END ELSE GOTO 30
50 PRINT "Enter END and press Return":RETURN
RUN
END
Ok

See also:
ON STOP GOSUB

STRIG
(MSX-Basic)
Syntax:
STRIG(sticknumber)
Function:
Returns the state of the Joysticks or space key.
number is a number between 0 and 4 and has the following meaning:
0 Space key
1 Joystick in connector 1
2 Joystick in connector 2
3 Joystick in connector 1
4 Joystick in connector 2
If the joystick or space key are activated the function returns -1. If not 0 is returned.
Example:
10 PRINT "Hit the space key"
20 P=STRIG(0)
30 IF P=-1 THEN BEEP
40 GOTO 20
RUN

See also:
PAD, PDL, STICK, INKEY$
STRIG
(MSX-Basic)
Syntax:
STRIG(number) ON
STRIG(number) OFF
STRIG(number) STOP
Function:
Checks the status if the joystick or space key.
number is a number between 0 and 4 and has the following meaning:
0 Space key
1 Joystick in connector 1
2 Joystick in connector 2
3 Joystick in connector 1
4 Joystick in connector 2
After the "STRIG(number) ON" statement MSX-Basic checks with every statement if the specified
joystick button is pressed. If so MSX-Basic calls the subroutine, that was specified in the "ON
STRIG GOSUB" statement.
After the "STRIG(number) OFF" statement MSX-Basic no longer checks, if the specified joystick
button is pressed.
After the "STRIG(number) STOP" statement MSX-Basic checks if the specified joystick button is
pressed, but does not call the subroutine that was specified in the "ON STRIG GOSUB" statement.
But the state is remembered and the subroutine is automatically called after the "STRIG(number)
ON" statement.
Example:
See: ON STRIG GOSUB
See also:
ON STRIG GOSUB

STR$
(MSX-Basic)
Syntax:
STR$(number)
Function:
Creates the alpanumeric representation of the numeric expression in number.
Use the "VAL" function to get the numeric representation of the alphanumeric expression.
Example:
10 AMOUNT=12.34216:PRINT AMOUNT
20 A$=STR$(AMOUNT)
30 H%=INSTR(A$,".")
40 IF H%=<1 GOTO 80
50 MID$(A$,H%,1)=","
60 H$=LEFT$(A$,H%+2)
70 PRINT H$
80 END
RUN
12.34216
12,34
Ok

See also:
BIN$, HEX$, OCT$, VAL

STRING$
(MSX-Basic)
Syntax:
STRING$(length, character)
Function:
Creates a string with length characters, which consists only of characters that was specified in
character.
length is the length of the alpanumeric value and must be an integer in range between 0 and 255.
character is the code of the character and must be an integer between 32 and 255, or the
corresponding character (string) directly.
Example:
10 SCREEN 1:COLOR 15,4,7
20 A$=CHR$(42)
30 FOR K=1 TO 22
40 C=INT(RND(1)*20)
50 LOCATE 3,K
60 PRINT USING "##";C
70 LOCATE 6,K
80 PRINT STRING$(C,A$)
90 NEXT K
100 END
RUN

See also:
SPACE$, SPC, TAB

SWAP
(MSX-Basic)
Syntax:
SWAP variable, variable2
Function:
Exchanges the contents of two variables.
Every type of variable (integer, single precision, double precision, alphanumeric) can be used. The
only restriction is that both variables are of the same type.
Example:
10 X=3:Y=7
20 GOSUB 60
30 SWAP X,Y
40 GOSUB 60
50 END
60 PRINT "X=";X;"Y=";Y
70 RETURN
RUN

See also:
LET

TAB
(MSX-Basic)
Syntax:
TAB(position)
Function:
Sets a tabulator. The cursor jumps to a pre-defined position in the same line.
This function can only be used with "PRINT" and "LPRINT" statements.
number must be an integer between 0 and 255.
If the cursor has already reached the specified position the function is ignored.
Example:
10 PRINT "0";TAB(9);"9"
20 END
RUN

See also:
PRINT, LPRINT, SPC, SPACE$, STRING$

TAN
(MSX-Basic)
Syntax:
TAN(number)
Function:
Returns the tangent of the specified number in radians.
Example:
10 X=5
20 PRINT TAN(X)
30 END
RUN
-3.3805150062446
Ok

See also:
ATN, COS, SIN

TIME
(MSX-Basic)
Syntax:
TIME
Function:
Contains the internal system-time.
Every time the video display processor creates an interrupt (every 1/60s or 1/50s), the variable
"TIME" is incremented by 1.
If no interrupt is generated (e.g. while saving a program to tape or loading from tape) the "TIME"
variable remains unchanged.
Example:
10 CLS
20 LOCATE 10,6
30 PRINT "HH:MM:SS START"
40 TIME=0
50 T=TIME
60 H=INT(T/180000)
70 T=T-(H*180000)
80 M=INT(T/3000)
90 T=T-(M*3000)
100 S=INT(T/50)
110 LOCATE 10,8
120 PRINT USING "##:##:##";H;M;S
130 GOTO 50
RUN

See also:
RND, GET TIME

TROFF
(MSX-Basic)
Syntax:
TROFF
Function:
Disable tracing of the program execution.
The trace function is enabled with the "TRON" statement. The trace function can also be disabled
with the "NEW" statement.
Example:
See: TRON
See also:
TRON, NEW

TRON
(MSX-Basic)
Syntax:
TRON
Function:
Enables the trace function.
After the "TRON" statement MSX-Basic prints all program-lines (that are executed during the
program flow) in brackets.
Example:
10 FOR I=1 TO 3
20 PRINT I
30 NEXT
40 END
TRON
Ok
RUN
[10][20] 1
[30][20] 2
[30][20] 3
[30][40]
Ok
TROFF
Ok

See also:
TROFF

USR
(MSX-Basic)
Syntax:
USR[<number>] (argument)
Function:
Starts a machine-language program.
number is an integer between 0 and 9. If number is not specified 0 will be used.
The start-address of the machine-language program must be specified by using the DEF USR
statement.
argument is the value, that is passed to the machine-language subroutine. It can be passed in the
following ways:
For alphanumeric values
Memory address &HF663 contains the value 3. Memory address &HF7F8 and &HF7F9
contains the address of the type of the alphanumeric value. The type contains 3 bytes. The
first byte is the length of the alphanumeric value, the second and third contains the memory-
address of the alphanumeric value.
For integer values
The memory address &HF663 contains the value 2. Memory address &HF7F8 and &HF7F9
contains the value of the integer.
For single precision values
The memory address &HF663 contains the value 4. Memory address &HF7F6 to &HF7F9
contains the single precision value.
For double precision values
The memory address &HF663 contains the value 8. Memory address &HF7F6 to &HF7FD
contains the double precision value.
Values that are returned from the machine-language to MSX-Basic have to be provided in the same
way from the machine-language program.
Use the "CLEAR" statement to reserve the necessary memory for the machine-language program.
Example:
DEF USR1=&H156:A=USR1(0)

10 CLEAR 200,&HEFFF
20 AB=&HF000
30 FOR I=AB TO AB+9
40 READ A$:A=VAL("&H"+A$)
50 POKE I,A
60 NEXT I
70 DEFUSR=&HF000
80 INPUT "Enter an integer";A%
90 PRINT "The integer is";A%
100 R=USR(A%)
110 PRINT "Result is the integer plus 1";R
120 END
130 DATA 23,23,4E,23,46,03,70,2B,71,C9
RUN

See also:
DEFUSR, BLOAD, POKE, VARPTR, CLEAR

VAL
(MSX-Basic)
Syntax:
VAL(string)
Function:
Returns the value of the alphanumeric expression in string.
The function ignores spaces and control-characters in the expression.
The "STR$" function can be used to get an alphanumeric representation of a numeric expression.
Example:
10 AMOUNT=12.34216:PRINT AMOUNT
20 A$=STR$(AMOUNT)
30 H%=INSTR(A$,".")
40 IF H%=<1 GOTO 80
50 H%=H%+2
60 B$=LEFT$(A$,H%)
70 AMOUNT=VAL(B$):PRINT AMOUNT
80 END
RUN
12.34216
12.34
Ok

See also:
BIN$, HEX$, OCT$, STR$

VARPTR
(MSX-Basic, RS232-Basic)
Syntax:
VARPTR(variable)
VARPTR(#channel)
Function:
Returns the memory-address of the first byte of a variable or the first byte of a file-control-block (of
an open file).
The first format returns the memory-address of a variable. This variable must be already initialized
with a value, otherwise an "Illegal function call" will be generated.
Every type of variable (integer, single precision, double precision, alphanumeric) and dimensioned
variables (defined by the "DIM" statement) can be used with the "VARPTR" function.
Before the address of a dimensioned variable can be accessed its necessary to assign a value to all
non-dimensioned variables. This is required because adresses of dimensioned variables will change
if new not-dimensioned variables are used.
The function "VARPTR" is most recently used to get the memory-address of a variable, which
should be passed to an assembly-language subroutine.
The second format returns the first address of the file-control-block of a file.
channel is the file-number of the file, which was opened with the "OPEN" statement.
The "VARPTR" function returns a value between -32768 and 32767. If a negative value is given
65536 is added first to get the actual address.
Example:
10 A=10
20 B=VARPTR(A)
30 IF B<0 THEN B=B+65536
40 C$="0000"+HEX$(B)
50 PRINT RIGHT$(C$,4)
60 END
RUN
C059
Ok

See also:
PEEK, POKE, DEFUSR, USR, DIM, OPEN

VDP
(MSX-Basic)
Syntax:
VDP(register)
Function:
Contains the value of the specified VDP register (video display processor).
register is the register number and must be an integer between 0 and 8. The content of register 8 is
read-only and cannot be changed.
MSX2: registers 9 to 24 and 33 to 47 are added.
MSX2+ registers 26-28 are added.
USE THIS VARIABLE ONLY IF YOU ARE FAMILIAR WITH THE VDP (VIDEO DISPLAY
PROCESSOR).
Example:
10 FOR I=0 TO 8
20 A=VDP(I)
30 B$="00000000"+BIN$(A)
40 PRINT RIGHT$(B$,8)
50 NEXT I
60 END
RUN

See also:
BASE

VPEEK
(MSX-Basic)
Syntax:
VPEEK(adress)
Function:
Returns the value of a byte within the video-memory.
The function returns a byte-value for the specified address and is therefore in range between 0 and
255.
address is the address within the video-memory and must be in range between 0 and 16383 (or
-32768 and 32767).
The statement "VPOKE" can be used to write a byte into the video memory.
MSX2: the size of video-memory has been increased from 16KB to 64KB and more, therefore
address can be in range from -32768 to 32767.
USE THIS FUNCTION ONLY IF YOU ARE FAMILIAR WITH THE VDP (VIDEO DISPLAY
PROCESSOR)
Example:
10 A=VPEEK(0)
20 A$="00"+HEX$(A)
30 PRINT RIGHT$(A$,2)
40 END
RUN

1000 REM ********************


1010 REM Hardcopy of screen 0
1020 REM ********************
1030 LPRINT CHR$(13):FOR I=0 TO 959
1040 LPRINT CHR$(VPEEK(I));
1050 IF I>0 AND (I+1)/40=INT((I+1)/40) THEN LPRINT CHR$(13);
1060 NEXT I

See also:
VPOKE, PEEK, SCREEN, SET PAGE

VPOKE
(MSX-Basic)
Syntax:
VPOKE adress,value
Function:
Writes a byte into the video-memory.
address is the address within the video-memory and must be in range between 0 and 16383 (or
-32768 and 32767).
value is the byte value and must be between 0 and 255.
The function "VPEEK" can be used to read a byte from video-memory.
MSX2: the size of video-memory has been increased from 16KB to 64KB and more, therefore
address can be in range from -32768 to 32767.
USE THIS FUNCTION ONLY IF YOU ARE FAMILIAR WITH THE VDP (VIDEO DISPLAY
PROCESSOR)
Example:
10 VPOKE 0,(VPEEK(0))
20 END
RUN

See also:
VPEEK, POKE, SCREEN, SET PAGE

WAIT
(MSX-Basic)
Syntax:
WAIT port, xormask[, andmask]
Function:
Monitors the status of a machine input-port port.
While this statement is executed data from the port is read and compared with xormask (on XOR
base) and andmask (on AND base) . If the result of this comparison is 0, then MSX-Basic reads the
port again and compares the data. In all other cases the program will be continued.
If andmask is not specified the value 0 will be assumed.
Example:
See: INP and OUT
See also:
INP, OUT, XOR, AND

WIDTH
(MSX-Basic)
Syntax:
WIDTH textwidth
Function:
Specifies the number of positions in a single screenline for textmode 1 and 2.
textwidth is the number of positions per line and must be an integer between 1 and 40 (or 1 and 80)
in textmode 1 and an integer between 1 and 32 in textmode 2.
If MSX-Basic starts Textmode 1 uses "WIDTH 37" and textmode 2 uses "WIDTH 19".
MSX2: the textmode 1 can now have up to 80 characters, therefore the textwidth can be in range
between 1 and 80. If textwidth is > 40 the 80 character mode is activated, if textwidth is <= 40 the
40 character mode is activated.
The width can also be saved by using the "SET SCREEN" statement, so the system will restore the
changed defaults on power-up.
Example:
5 SCREEN 0
10 FOR I=37 TO 10 STEP -1
15 WIDTH I
20 PRINT "This is a line of text on the screen"
25 FOR X=1 TO 300:NEXT
30 REM line 25 is a time-delay
35 NEXT I
40 WIDTH 40
45 REM line 40 restores the old format again
50 END

See also:
SCREEN, SET SCREEN, CALL KANJI

XOR
(MSX-Basic)
Syntax:
number1 XOR number2
Function:
Logical exclusive or.
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
Example:
See also:
AND, EQV, IMP, MOD, NOT, OR, MSX-Basic operators
MSX 2 (MSX-Basic 2)
See also: RAM-Disk in MSX-Basic 2

COLOR SPRITE
(MSX-Basic 2)
Syntax:
COLOR SPRITE(<plane>)=color
Function:
Sets the color to the sprite of plane to the specified color.
This statement sets the whole sprite of the specified plane to the color, this uses color for color
specification. The format of the color specification is valid for screen mode 4 through 8
(respectively 12).
Bitwise meanings of color:
Bit 7 Not used (disabled).
Bit 6 If 1, move the sprites of the successive planes together. The priority and conflict of sprites
are ignored, and when sprites are piled up, they are displayed in the color which is OR-ed
with their color numbers.
For example, assuming that bit 6 of sprite plane 1 is "0" and bit 6 of sprite plane 2 is "1",
only by moving sprite plane 1, will sprite plane 2 be displayed displayed to be piled at the
same location.
Bit 5 If 1, the conflict of sprites are ignored.
Bit 4 Unused.
Bits Palette number (see color-table).
0-3
Example:
COLOR SPRITE(0)=15

See also:
COLOR, COLOR SPRITE$, PUT SPRITE

COLOR SPRITE$
(MSX-Basic 2)
Syntax:
COLOR SPRITE$(<plane>)=string
Function:
Sets the colour of each horizontal line of the sprite using string.
string consists of one to sixteen characters. Bits 0 throgh 3 of the character's ASCII code are used
for the colour specification, and bits 4 through 7 are used to specify each function of the sprite.
These specifications are valid only for screen modes 4 through 8 (respectively 12).
Bitwise meanings of string expression:
Bit 7 If 1, move the sprite to left by 32 dots.
Bit 6 If 1, move the sprites of the successive planes together. The priority and conflict of sprites
are ignored, and when sprites are piled up, they are displayed in the color which is OR-ed
with their color numbers.
For example, assuming that bit 6 of sprite plane 1 is "0" and bit 6 of sprite plane 2 is "1",
only by moving sprite plane 1, will sprite plane 2 be displayed displayed to be piled at the
same location.
Bit 5 If 1, the conflict of sprites are ignored.
Bit 4 Unused.
Bits Palette number (see color-table).
0-3

Relation of the sprite and string:


COLOR SPRITE$ = CHR$ (color of the first line) + CHR$ (color of the second line) + ...... +
CHR$ (color of the eight line)
---------------------------------
Line 1 --> | * | | | * | * | | | * |
|---+---+---+---+---+---+---+---|
Line 2 --> | * | * | | | | | * | * |
|---+---+---+---+---+---+---+---|
| | | | | | | | |
|---+---+---+---+---+---+---+---|
| * | * | | | | | * | * |
|---+---+---+---+---+---+---+---|
| | | * | | | * | | |
|---+---+---+---+---+---+---+---|
| * | | | * | * | | | * |
|---+---+---+---+---+---+---+---|
| * | * | | | | | * | * |
|---+---+---+---+---+---+---+---|
Line 8 --> | | | * | * | * | * | | | The color for each line
--------------------------------- can be set.

Example:
COLOR SPRITE$(0)=STRING$(16,&HFF)

See also:
COLOR, COLOR SPRITE, PUT SPRITE

COLOR=
(MSX-Basic 2)
Syntax:
COLOR=(palette no., red luminance, green lumincane, blue luminance)
Palette no. Condition: when screen mode is 0 to 7 or 10: 0 to 15. Numerical constant variable, array
variable or expression.
Red/green/blue luminance: 0 to 7. Integer constant
Function:
You can express 512 kind of colors by combining red, green and blue luminance. If you do not
execute this command to a palette no, it's color stays default.
Note: use CALL PALETTE statement to specify palette color under Japanese input mode. If you try
to use this COLOR statement during Japanese input mode, you will get "Illegal function call".
(Same is true with COLOR=NEW and COLOR=RESTORE statements).
Example:
100 SCREEN 5
110 FOR I=7 to 0 STEP -1
120 CIRCLE(120,100),I*10+5,I
130 PAINT(120,100),I,1
140 NEXT I
150 J=(J+1) MOD 8
160 FOR I=0 to 7
170 COLOR=(I,0,J,0)
180 J=(J+1) MOD 8
190 NEXT I
200 GOTO 150

See also:
CALL PALETTE, COLOR=RESTORE, COLOR=NEW, DRAW, LINE, CIRCLE, PSET, PAINT

COLOR=RESTORE
(MSX-Basic 2)
Syntax:
COLOR=RESTORE
Function:
This commands substitues contents of "Color Lookup Table" inside VRAM, into VDP color palette
registers.
Usage:
COLOR=RESTORE (no options whatsoever; just this form)
How it works, and how you use this:
If you BSAVE with ,S option, you can save the contents of VIDEO RAM to the disk along with
color palette infos. If you BLOAD with ,S option, you can load such palette data to VRAM.
However, such color palette info is only set into lookup table, and do not make any changes to the
actually displayed colors. If you execute COLOR=RESTORE, then you can set the info inside
lookup table as color palette, and you can display the picture in the same color at the time you saved
with BSAVE,S.
Example:
10 SCREEN 2
20 BLOAD "BOX",S
30 COLOR=RESTORE
40 GOTO 40

See also:
COLOR=, COLOR, COLOR=NEW

COLOR=NEW
(MSX-Basic 2)
Syntax:
COLOR=NEW
Function:
This statement initialises the colour palette to the same state as when the power of the computer is
turned on (see Color-table). It is a good idea to place this statement at the beginning and the end of
the program.
Example:
COLOR=NEW

See also:
COLOR=, COLOR, COLOR=RESTORE

CALL MEMINI
(MSX-Basic 2)
Syntax:
CALL MEMINI [(size)]
Function:
This statement specifies the amount of memory to be used as a RAM disk, initialises the RAM disk,
and deletes all files. When the RAM disk is to be used, this statement should always be executed.
Size is "the amount of memory to be used as RAM disk minus 1". By default, the maximum size is
allocated for RAM disk. "CALL MEMINI(0)" causes the RAM disk feature to be disabled.
Example:
CALL MEMINI(&H3FFF)

See also:
CALL MFILES, CALL RAMDISK RAM-Disk in MSX-Basic 2, RAM-Disk in Disk-Basic 2,
RAM-Disk in MSX-DOS 2

CALL MKILL
(MSX-Basic 2)
Syntax:
CALL MKILL("filename")
Function:
This statement deletes the specified file.
Example:
See also:
KILL, CALL MNAME

CALL MNAME
(MSX-Basic 2)
Syntax:
CALL MNAME ("old filename" AS "new filename")
Function:
This statement renames the specified file.
Example:
See also:
NAME, CALL MKILL

CALL MFILES
(MSX-Basic 2)
Syntax:
CALL MFILES
Function:
This statement displays file names on the RAM disk.
Example:
See also:
FILES, LOAD, CALL MEMINI

SET PAGE
(MSX-Basic 2)
Syntax:
SET PAGE [visible][,work]
Function:
This statement allows users to set the page to display and the page to read and write data to. This is
valid when the screen mode is greater than 4, and the value specified depends on the VRAM
capacity and the screen mode:
Screen mode VRAM 64K VRAM 128K
SCREEN 5 0 to 1 0 to 3
SCREEN 6 0 to 1 0 to 3
SCREEN 7 Unusable 0 to 1
SCREEN 8 Unusable 0 to 1
SCREEN 10 (MSX2+) Unusable 0 to 1
SCREEN 11 (MSX2+) Unusable 0 to 1
SCREEN 12 (MSX2+) Unusable 0 to 1
Example:
See also:
BSAVE, BLOAD, COPY, SCREEN
SET VIDEO
(MSX-Basic 2)
Syntax:
SET VIDEO [mode[, Ym[, CB[, sync[, voice[, video input[, AV control]]]]]]]
Function:
With this instruction is possible to define the so called 'superimpose mode'. Superimpose means that
images could mix together (one on another).
Attention: This statement is for the superimposer or the digitiser which are optional, so it can be
used only for machines which are equipped with this the 'superimpose' capability.
Mode sets the superimposing mode and can be set to the value listed in the following table. This
indicates where the image comes from:
Mode S1 S2 TP Display screen
0 0 0 0 Computer
1 0 1 1 Computer
2 0 1 0 Superimpose (together with another image, one on the other)
3 1 0 0 Television (from the input of the video)
Note: In the case of mode 0, external sync cannot be used. In other modes the compoalte output of
VDP is not available. S1, S0, and TP are the names of flags in the VDP register.
Ym specified the intensity (brightness) of the television. If not specified the value defaults to 0.
Ym brightness
0 half
1 full
When CB is 1, the colour bus of VDP is prepared for input, and, when 0, it is prepared for output. If
not specified the value defaults to 0.
CB color-control
0 only for output
1 only for input
When sync is 1, "external sync" is selected, and, when 0, "internal sync" is selected. If not specified
the value defaults to 0.
sync synchronisation
0 internal
1 external
Voice specifies whether to mix external signal for output, and values are listed in the following
table. If not specified the value defaults to 0.
Voice Function for external voice signal
0 No mixing
1 Right channel mixed
2 Left channel mixed
3 Both channels mixed
Video input is used to alternate the input of external video signals. When it is 0, the RGB
multiconnector is selected; when it is 1, external video signal connector is selected. If not specified
the value defaults to 0.
Video input external input
0 Euroconnector RGB (SCART)
1 Connector TV
AV control specifies AV control terminal output of the RGB multiconnector. When it is 0, the output
is OFF; when it is 1, the output is ON. If not specified the value defaults to 0.
AV control audio/video output of the euroconnector RGB (SCART)
0 not selected
1 selected
Example:
SET VIDEO 2

See also:
COPY SCREEN

SET ADJUST
(MSX-Basic 2)
Syntax:
SET ADJUST(x,y)
Function:
This statement sets the location to display on the screen. The coordinate offset is from -7 to 8.
Example:
SET ADJUST(0,0)

See also:
SET SCROLL

SET BEEP
(MSX-Basic 2)
Syntax:
SET BEEP timbre, volume
Function:
This statement sets BEEP sound. Timbre and volume are from 1 to 4. The table below shows the
correspondance of timbre and to the actual sound.
Timbre Sound
1 High tone beep (same as MSX1)
2 Low tone beep
3 2 - tone beep
4 3 - tone beep
Example:
See also:
BEEP
SET TITLE
(MSX-Basic 2)
Syntax:
SET TITLE "greeting" [, color]
Function:
This statement specifies the title and the colour of the initial screen at system startup. The title is set
by a string of up to 6 characters and color is one of the values listed below. When title is 6
characters, keyboard input is awaited just after the title screen is displayed.
Color Screen color
1 Blue
2 Green
3 Red
4 Orange
Example:
SET TITLE "Hello"

See also:
SET PROMPT, SET PASSWORD

SET PASSWORD
(MSX-Basic 2)
Syntax:
SET PASSWORD "password"
Function:
This statement sets a system password. Password is a string expression up to 255 characters. Once
this statement is done, input of the password is requested for invoking the system. When the correct
password is given, the system is normally invoked; otherwise, correct password input is requested.
When the system is invoked by pressing both graphic key and stop key, no password input is
requested (in this case, the password setting has been done by the key cartridge; however,
password input is always required for system startup). The password is disabled by specifying a null
character in SET TITLE.
Example:
See also:
SET TITLE, SET PROMPT

SET PROMPT
(MSX-Basic 2)
Syntax:
SET PROMPT "prompt"
Function:
This statement sets the prompt. Prompt can have up to 6 characters.
Example:
SET PROMPT "Ready"

See also:
SET PASSWORD, SET TITLE

SET SCREEN
(MSX-Basic 2)
Syntax:
SET SCREEN
Function:
This statement records the current parameters of the "SCREEN" statement. At the system startup,
they are automatically set. Items to be recorded are the following:
Screen number of text mode
Key click switch
Screen width of text mode
Printer option
Foreground, background, and border colours
Cassette baud rate
Function key switch
Display mode
Example:
See also:
SCREEN, WIDTH

SET DATE
(MSX-Basic 2)
Syntax:
SET DATE "date" [,A]
Function:
This statement sets date to timer. The form of parameter and option is the same as "GET DATE".
When option A is specified, the alarm date is set.
Example:
SET DATE "85/03/23"

See also:
GET DATE, SET TIME
SET TIME
(MSX-Basic 2)
Syntax:
SET TIME "time" [,A]
Function:
This statement sets the time to the timer. The form of parameter and option is the same as "GET
TIME".
e.g.) SET TIME "22:15:00"
When option A is specified, the alarm time is set.
Example:
See also:
SET DATE, GET TIME

GET DATE
(MSX-Basic 2)
Syntax:
GET DATE string-variable [,A]
Function:
This statement is for reading the date from the timer and assigning it to the string variable. The
format of date to be read is as follows:
Japanese: (YY = lower two digits of year, MM = month, DD =
YY/MM/DD day)
e.g. 85/03/23 (March 23, 1985)
International: (YY = lower two digits of year, MM = month, DD =
MM/DD/YY day)
e.g. 03/23/85 (March 23, 1985)
Korean: (YY = lower two digits of year, MM = month, DD =
DD/MM/YY day)
e.g. 23/03/85 (March 23, 1985)
When option A is specified, the alarm date is read.
Example:
GET DATE D$
PRINT D$

See also:
GET TIME, SET DATE, CALL GREG

GET TIME
(MSX-Basic 2)
Syntax:
GET TIME string-variable [,A]
Function:
This statement is for reading time from the timer and assigning it to a string variable. The form of
time to be read is as follows:
HH:MM:SS(HH = hour, MM = minute, SS = second)
e.g. 22:15:00(22 hours 15 minutes 0 seconds)
When A is specified, the time for the alarm time is read.
Example:
GET TIME T$
PRINT T$

See also:
GET DATE, SET TIME, TIME, CALL TIME
MSX 2+ (MSX-Basic 3)

SET SCROLL
(MSX-Basic 3)
Syntax:
SET SCROLL [x ] [,y]
Function:
Performs horizontal and vertical scrolling of the screen-contents in graphic-mode.
Notes:
Under screen 0 mode 0-7 is specifyable as X-distance. If 0 (or omitted), horizontal scroll does not
happen. If a value between 1 and 7 is specified, 1 causes 7 pixels, 2 causes 6 pixels, ... 7 causes 1
pixel of scroll to right.
0 to 7 is specifiyable as Y-distance. If 0 (or omitted), vertical scroll does not happen. If a value
between and 7 is specified, 1 causes 1 pixel, 2 causes pixels, ... 7 causes 7 pixels of scroll to up.
"Vertical scroll" does not move displayed characters themselves, but instead causes scrolling inside
each of the horizontal character rows.
After scrolling, (if horizontal scroll was specified) entire displayed screen is displaced to X-axial
direction and (if vertical scroll was) character patterns are scrolled Y-axially inside each of the rows.
Scrolled positions return to initial conditions if you re-set the screen mode by using SCREEN
statement.
Example:
SET SCROLL ,1

See also:
SET ADJUST
MSX Turbo-R (MSX-Basic 4)
BLOAD, BSAVE, LOAD, MERGE, OPEN, RUN, SAVE do no longer support the "CAS:" device
CLOAD, CSAVE, MOTOR are no longer supported and will generate a "syntax error"

CALL PAUSE
(MSX-Basic 4)
Syntax:
CALL PAUSE(time)
Function:
Pauses the execution for the specified time.
The unit of time is milliseconds. Interrupts are enabled during the pause, and you can abort the
pause by [CTRL]+[STOP].
Example:
CALL PAUSE(1000)

See also:

CALL PCMPLAY
(MSX-Basic 4)
Syntax:
CALL PCMPLAY(@startaddr, endaddr, samplerate, ramtype [,S])
CALL PCMPLAY(arrayname, [length], samplerate)
Function:
Specify the area where data you want to replay using "starting address" startaddr and "ending
address" endaddr. You cannot omit these figures. Range of precision samplerate is 0 to 3. You must
specify the precision used at time of CALL PCMREC to play correctly.
Example:
CALL PCMPLAY(@&HB000,&HDFFF,1)

See also:
CALL PCMREC

CALL PCMREC
(MSX-Basic 4)
Syntax:
CALL PCMREC(@startaddr, endaddr, samplerate [, [triggerlevel] [, reductionswitch]] [,S])
CALL PCMREC(arrayname, length, samplerate [, [triggerlevel] [, reductionswitch]])
Function:
This command stores the sound which was captured through microphone into memory specified by
starting address startaddr and ending address endaddr. Usually, you must reserve certain amount of
RAM using CLEAR statement before using this command.
"Precision" (in samplerate) stands for a smallest length of segments in sound. Range: 0 to 3. Bigger,
data will be more rough, but fewer the data amount, therefore allowing you to record longer sound.
This example can record for a length of approximately 2 seconds.
Recording begins when a microphone catches a sound louder than "level" triggerlevel. Range of
"level" is 0 to 127.
If "Compression flag" reductionswitch is 0 or omitted, then no compression occurs. If it is 1,
compression takes place. When compression is on, MSX compresses all silent moments while
recording. So, you can record longer sound. The quality will degrade, however. The compression
rate depends on type of sound you record.
Example:
CALL PCMREC(@HB000,&HDFFF,1,32,1)

See also:
CALL PCMPLAY
Kanji (Basic)
Kanji-Basic is available since MSX-DOS 2.20 and MSX Turbo-R's

CALL PALETTE
(Kanji-Basic)
Specify display color to a palette during Japanese input mode.
Syntax:
CALL PALETTE(palette no.,red lumincance,green luminance,blue luminance)
_PALETTE(palette no.,red lumincance,green lumincance,blue luminance)
Palette no.: 0 to 15. Numerical constant, variable, array variable or expression.
Red/green/blue luminance: 0 to 7. Integer constant.
Function:
You must use this command to specify colors in Japansese input mode. COLOR= statement is
disabled in Japanese input mode.
If you omit all parameters (execute simply CALL PALETTE), all palettes return to default.
Example:
CALL PALETTE(15,4,4,4)

See also:
COLOR=

CALL CLS
(Kanji-Basic)
Delete all the contents in the screen during Japanese input mode.
Syntax:
CALL CLS
_CLS
Function:
You must use this command to clear away the screen once you enter Japanese input mode by using
CALL KANJI command.
CLS statement may not wok properly in Japanese input mode.
Example:
See also:
CLS

CALL AKCNV
(Kanji-Basic)
Convert all character data to zenkaku characters, and substitue them into a character string.
Syntax:
CALL AKCNV(character variable,X$)
_ AKCNV(character variable,X$)
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
Function:
If any characters which are not zenkaku are containted in X$, this command converts them into
zenkaku characters, and substitute the whole string into a character variable.
Example:
CALL AKCNV(A$,"ABC "):PRINT A$

Among the character string given to this CALL AKCNV statement, "ABC" and "" were
converted, since they were hankaku.
See also:
Zenkaku and Hankaku

CALL JIS
(Kanji-Basic)
Substitue a JIS code which corresponds to first character in a character data to a numeric variable.
Syntax:
CALL JIS(character variable,X$)
_ JIS(character variable,X$)
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
Function:
If a first character in X$ is a 2-byte character, this command substitutes the JIS code (hex, 4 digits)
of that character into a numeric variable.
Example:
CALL JIS(A$,""):PRINT A$
3441

See also:
About how to access Kanji-ROM

CALL SJIS
(Kanji-Basic)
Substitue a shift-JIS code which corresponds to first character in a character data to a numeric
variable.
Syntax:
CALL SJIS(character variable,X$)
_ SJIS(character variable,X$)
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
Function:
If a first character in X$ is a 2-byte character, this command substitutes the SJIS code (hex, 4 digits)
of that character into a numeric variable.
Example:
CALL SJIS(A$,""):PRINT A$
8ABF

See also:
About how to access Kanji-ROM

CALL KACNV
(Kanji-Basic)
Convert any character that can be converted into hankaku characters as hankaku characters, and
substitue them into a character string.
Syntax:
CALL KACNV(character variable,X$)
_ KACNV(character variable,X$)
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
Function:
Characters contained in X$ will be converted as follows.
Before Conversion After Conversion
Zenkaku alphabets and numerics Hankaku alphabets and numerics
Zenkaku hiraganas Hankaku katakanas
Zenkaku katakanas Hankaku katakanas
Kanji Kanji (no conversion)
Example:
CALL KACNV(A$,""):PRINT A$

See also:
Zenkaku and Hankaku

CALL KEXT
(Kanji-Basic)
Extract zenkaku or hankaku characters exclusively out of a character data, and substitue them into a
character string.
Syntax:
CALL KEXT(character variable,X$,option)
_ KEXT(character variable,X$,option)
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
Option: 0 or 1.
Function:
This command extracts only hankaku characters out of a character data if value of option is 0; only
zenkaku characters if value option is 1, and substitute them into a character string.
Example:
CALL KEXT(A$,"",0):PRINT A$

CALL KEXT(A$,"",1):PRINT A$

See also:
Zenkaku and Hankaku

CALL KINSTR
(Kanji-Basic)
Search for a certain character data among a character data, and substitute found position into a
numeric variable.
Syntax:
CALL KINSTR(numeric variable,[,N],X$,Y$)
_ KINSTR(numeric variable,[,N],X$,Y$)
Numeric variable: Variable of numeric type.
N: 1 to 256. Numeric constant, variable, array variable or expression. Default=1.
X$, Y$: Character constant, variable, array variable or expression.
Function:
This command checks from which position the Y$ starts in relation to beginning of a character
string X$, and substitutes the found value into a numeric variable. If you state a value for N, the
search takes place from Nth character in X$.
You must use this CALL KINSTR command instead of INSTR function if the character in question
is of Japanese input type.
Example:
CALL KINSTR(A,"TOKYO ",""):PRINT A
8

* If value of N is greater than length of X$, if X$ is a null string, or if Y$ is not found, then this
command substitutes 0 to the numeric variable. And if Y$ is a null string, then this command
substitutes 1 to the numeric variable. (However, it substitutes 0 if X$ is also a null string)
CALL KLEN
(Kanji-Basic)
Substitute number of all characters (length)/hankaku characters only/zenkaku characters only in a
character data to a numeric variable.
Syntax:
CALL KLEN(numeric variable,X$[,option])
_ KLEN(numeric variable,X$[,option])
Numeric variable: Variable of numeric type.
X$: Character constant, variable, array variable or expression.
Option: 0 to 2. Default=0.
Function:
Substitute number of all characters in (length of) a character data if a value of the option is 0 or
omitted, number of hankaku characters if 1, and number of zenkaku characters if 2.
You must use this CALL KLEN command instead of LEN function if the character in question is of
Japanese input type.
Example:
CALL KLEN(A,""):PRINT A
7

CALL KLEN(A,"",1):PRINT A
6

CALL KLEN(A,"",2):PRINT A
1

* A hankaku accent will be counted as an independent character too.


See also:
Zenkaku and Hankaku

CALL KMID
(Kanji-Basic)
Choose a part of a character data and substitute it to a character variable.
Syntax:
CALL KMID(character variable,X$,M[,N])
_ KMID(character variable,X$,M[,N])
Character variable: Variable of character type.
X$: Character constant, variable, array variable or expression.
M: 1 to 256. Numeric constant, variable, array variable or expression.
N: 0 to 256. Numeric constant, variable, array variable or expression. Default= all characters from
M to last.
Function:
Choose N characters from Mth character in a character data, and substitute them into a chracter
variable.
You must use this CALL KMID command instead of MID function if the character in question is of
Japanese input type.
Example:
CALL KMID(A$,"",4,2):PRINT A$

* A hankaku accent will be counted as an independent character too.


See also:
Zenkaku and Hankaku

CALL KNJ
(Kanji-Basic)
Substitute a character that stands for a specified kanji code to a character variable.
Syntax:
CALL KNJ(character variable,X$)
_ KNJ(character variable,X$)
Character variable: Variable of character type.
X$: Character variable, variable, array variable or expression which stands for a 4-digits kanji code.
Function:
Specify a hexadecimal 4-digits kanji code to X$. The kanji code will be treated as a JIS code is
lower than 8000, or as a Shift-JIS code if it is 8000 or more.
Example:
CALL KNJ(A$,"3441"):PRINT A$

See also:
About how to access Kanji-ROM

CALL KTYPE
(Kanji-Basic)
Check whether a character in a specified position in a character data is hankaku or zenkaku.
Syntax:
CALL KTYPE(numeric variable,X$,N)
_ KTYPE(numeric variable,X$,N)
Numeric variable: Variable of numeric type.
X$: Character constant, variable, array variable or expression.
N: 1 to 255. Numeric constant, variable, array variable or expression.
Function:
This command substitutes 0 to a variable if a Nth character in X$ is hankaku, 1 if zenkaku.
If you specify N larger than number of characters in X$, you will get "Illegal function call" error.
Example:
CALL KTYPE(A,"",1):PRINT A
0

CALL KTYPE(A,"",5):PRINT A
1

* A hankaku accent will be counted as an independent character too.


See also:
Zenkaku and Hankaku

CALL KANJI
(Kanji-Basic)
Activates the Kanji text-mode.
This mode supports high-resolution Kanji-characters and is provided by MSX-DOS 2.20 and the
Kanji-Basic.
Once the Kanji-mode is activated you can use also graphic-modes to output/input text as in all other
text-modes. The SCREEN-command switches between all modes as normal, but does not deactivate
the Kanji-mode.
Due to this some Basic-statements/functions are not working properly and will return an error.
These statements/functions have new equivalents in Kanji-Basic which must be used instead. Use
CALL ANK to deactivate the Kanji-mode.
By executing this command, certain memory domain will be allocated for Japanese processing. At
this point, himem address setting specified by CLEAR statement will be negated, and all variables
and stacks (for FOR-NEXT and GOSUB/RETURN statements) will return to default.
You can use single-kanji conversion option if MSX-JE is not installed, renbunsetsu (sequential
segments) conversion option if installed. See MSX-JE section for details.
Press Ctrl+Space simultaneously to activate input of extended characters. In this mode the lower bar
in bottom of screen is displayed in reverse colors, entered characters are displayed in double width.
This mode can be exited by pressing Ctrl+Space again.
CALL KANJI or _KANJI
31x13
CALL KANJI0 or _KANJI0
CALL KANJI1 or _KANJI1 39x13
CALL KANJI2 or _KANJI2 31x24
CALL KANJI3 or _KANJI3 39x24
See also:
MSX-JE

CALL ANK
(Kanji-Basic)
Quit Japanese input mode.
Syntax:
CALL ANK
_ ANK
Function:
Deactivates the Kanji text-mode activated by CALL KANJI. However, execution of this command
does not release memory which was allocated for kanji driver through CALL KANJI statement.
See also:
MSX-JE
TURBO BASIC Compiler
The Turbo-Basic compiler is a separately sold cartridge. It can be found in MSX2+ Sanyo machines
too. It is also known as KUN-Basic or X-Basic. The following additional commands are provided:

CALL TURBO ON
(Turbo-Basic compiler)
Syntax:
CALL TURBO ON
Function:
Defines the beginning of the turbo block. The turbo block is the part of the program you want to
execute fast. When the entire program contains some uncompilable statements, you can define the
block to be compiled using this set.
The following statements, commands and functions that can not be compiled:
AUTO, BASE, BLOAD, BSAVE, CALL, CDBL, CINT, CLEAR, CLOAD, CLOAD?, CLOSE,
CONT, CSAVE, CSNG, CVD, CVI, CVS, DEFFN, DELETE, DRAW, DSKF, EOF, ERASE, ERL,
ERR, ERROR, EQV, FIELD, FILES, FPOS, FRE, GET, IMP, INPUT#, KEY LIST, LFILES,
LINEINPUT#, LIST, LLIST, LOAD, LOC, LOF, LPRINT USING, LSET, MAXFILES, MERGE,
MOTOR, MKD$, MKI$, MKS$, NAME, NEW, ON ERROR GOTO, ON INTERVAL GOSUB
(due to a bug), OPEN, PLAY, PRINT#, PRINT USING, PUT KANJI, RENUM, RESUME, RSET,
SAVE, SPC, TAB, TRON, TROFF, WIDTH.
List of those with limits.
CIRCLE: Start, end angles and aspect ratio can't be specified.
COPY: Only graphic COPY is available.
DEFDBL: Same as DEFSNG.
DIM: Must come first in the program or in the turbo block.
INPUT: Can handle only one variable at the time.
KEY: ON KEY GOSUB, KEY(n) ON/OFF only.
LOCATE: x,y must be given in as a set. No cursor switch parameter.
NEXT: Variable names after the NEXT can not be omitted.
ON: ON STOP GOSUB, ON INTERVAL GOSUB not available.
PRINT: Commas work in a different way. No wrapping for digits.
PUT: PUT SPRITE only.
RUN: Variables won't be initialized.
SCREEN: Screen mode and sprite size only.
SET: SET PAGE only.
STOP: Same as END.
USR: Parameter type must be integer only.
VARPTR: File number can not be given as the parameter.
Otherwise there is no significant difference.
In general, I/O commands & functions, and editing commands can not be compiled. Of course they
are available in the direct mode, and outside of the turbo block. You can edit, debug and save a
program in MSX-BASIC and execute it by _RUN.
If you want to use PRINT# to write characters on GRP:, use it outside of turbo block. Otherwise
study the sample, "PRINT.TRB".
If you want to use PLAY, use BGM compiler, and get the sound by USR(n).
Example:
100 SCREEN 8:DEFINT A-Z
110 BLOAD"PICTURE",S
120 _TURBO ON
130 FOR X=0 TO 255
140 LINE(X,0)-(X,211),0
150 NEXT X
160 _TURBO OFF
170 GOTO 170

See also:
CALL TURBO OFF, CALL RUN

CALL TURBO OFF


(Turbo-Basic compiler)
Syntax:
CALL TURBO OFF
Function:
The end of a turbo-block started with CALL TURBO ON.
Example:
100 SCREEN 8:DEFINT A-Z
110 BLOAD"PICTURE",S
120 _TURBO ON
130 FOR X=0 TO 255
140 LINE(X,0)-(X,211),0
150 NEXT X
160 _TURBO OFF
170 GOTO 170

See also:
CALL TURBO ON, CALL RUN

CALL RUN
(Turbo-Basic compiler)
Syntax:
CALL RUN
Function:
This command compiles and executes the entire program on memory. If it finds an error it will stop
and yield the message.
Example:
CALL RUN

See also:
CALL TURBO ON, CALL TURBO OFF, RUN
CALL BC
(Firmware)
This function is available in the Sanyo MSX 2+ only!
Syntax:
CALL BC
Function:
This command turn on the BASIC COMPILER options.
Example:
See also:
Turbo-Basic compiler

Вам также может понравиться