GoldStar Language Specification For MSX Basic
GoldStar Language Specification For MSX Basic
FAMILY
ER
ee
Cf
EN
54 GoldStar
Language specification for MSX BASIC
CHAPTER 1
MSX BASIC program lines have the following format (square brackets
indicate optional input):
nnnnn BASIC statement [:BASIC statement...] <carriage return>
More than one BASIC statement may be placed on a line, but each must
be separated from the last by a colon.
An MSX BASIC program line always begins with a line number and ends
with a carriage return. A line may contain a maximum of 255 characters.
Character Action
Blank
Eguals sign or assignment symbol
Plus sign
Minus sign
++
Asterisk or multiplication symbol
Slash or division symbol
Up arrow or exponentiation symbol
Left parenthesis
Right parenthesis
Percent
nne Number (or pound) sign
Dollar sign
Exclamation point
Left bracket
Language specifi cation for MSX BASIC
Right bracket
Comma
—_
Period or decimal point
Single quotation mark (apostrophe)
Semicolon
Colon
Ampersand
Question mark
Sivann
Less than
Greater than
Won sign or integer division symbol
At sign
Underscore
<rubout> Deletes last character typed.
<escape> Escapes
<tab> Moves print position to next tab stop.
Tab stops are set every eight columns.
<line feed> Moves to next physical line.
<carriage
return> Terminates input of a line.
1.4 CONSTANTS
Constants are t he values MSX BASIC uses during execution. There are
two types of con stants: string and numeric.
A string constan t is a sequence of up to 255 alphanumeric characters
enclosed in doub le quotation marks.
Examples:
"HELLO"
"$25,000 00"
"Number of Employees"
Numeric constant: s are positive or negative numbers. MSX BASIC numeric
constants cannot contain commas. There are six types of numeric
constants:
1. Integer cons tants Whole numbers between -32768 and 32767. Integer
constants do not contain decimal points.
2. Fixed-point Positive or negative real numbers, i.e., numbers
constants that contain decimal points.
3. Ploating-poi nt Positive or negative numbers represented
constants exponential form (similar to scientific
notation). A floating-point constant consists
of an optionally signed integer or fixed-point
number (the mantissa) followed by the
E and an optionally signed integer
exponent). The allowable range
floating-point constants is 10-64 to 10+63.
Language specification for MSX BASIC
Examples:
235.988E-7 = „0000235988
2359E6 =2359000000
(Double precision floating-point constants
are denoted by the letter D instead of E.)
Examples:
&H76
&H32F
Examples:
80347
Examples:
&B01110110
&B11100111
1.5 VARIABLES
Variables are names used to represent values used in a BASIC program.
The value of a variable may be assigned explicitly by the programmer,
or it may be assigned as the result of calculations in the program.
Before a variable is assigned a value, its value is assumed to be zero.
The following table lists only the number of bytes occupied by the
values represented by the variable names.
Variables Type Bytes
Integer 2
Single Precision 4
Double Precision 8
When necessary, MSX BASIC will convert a numeric constant from one
Eype to another. The following rules and examples should be kept in
mind.
Language specification for MSX BASIC
30 PRINT A!,B
RUN
1.41421 1.41421
1.7 EXPRESSIONS AND OPERATORS
1. Arithmetic
2. Relational
3. Logical
4. Functional
*/ Multiplication, Floating-
point Division
{sy
X/Y
To
+change Addition, Subtraction x+Y
10w4=2
25.68w6.99=4
Integer division follows multiplication and floating-point division
in order of precedence.
Modulus arithmetic is denoted by the operator MOD. Modulus arithmetic
yields the integer value that is the remainder of an integer division.
Example:
10.4 MOD 4=2 (10/4=2 with a remainder 2)
25.68 MOD 6.99=1 (25/6=4 with a remainder 1)
Modulus division in order of precedence.
arithmetic follows integer
1.7.1.2 Overflow And Division By Zero -
If, during the evaluation of an expression, division by zero is
encountered, the "Division by zero" error message is displayed and
execution of program terminates.
If overflow occurs, the "overflow" error message is displayed and
execution terminates.
X+YK(T-1)/Z
is true if the value of X plus Y is less than the value of T-1 divided
by Z.
More examples:
IF SIN(X)<0 GOTO 1000
IF I MOD J<>0 THEN K=K+1
1 0
0 1
AND
x Y Xx AND Y
1 1 1
z 0 0
0 1 0
0 0 0
OR
Xx Y XOR Y
1 1 1
1 0 1
0 1 1
0 0 0
XOR
x Y Xx
XOR Y
1 1 0
1 0 1
0 1 1
0 0 0
EQV
Xx
1 X EQV Y
1 1 1
1 0 0
0 1 0
_10-—
Language specification for MSX BASIC
0 0 1
IMP
Xx Y Xx IMP Y
1 gl 1
1 0 0
0 1 1
0 0 1
—
is
Language specification for MSX BASIC
Strings may be compared using the same relational operators that are
used with numbers:
= <> < > <=
The Full Screen Editor equiped with MSX BASIC allows the user to enter
program lines as usual, then edit an entire screen before recording
the changes. This time-saving capability is made possible by special
-12-
Language specification for MSX BASIC
keys for cursor movement, character insertion and deletion, and line
or screen erasure. Specific functions and key assignments are discussed
in the following sections.
With the Full Screen Editor, a user can move quickly around the screen,
making corrections where necessary. The changes are entered by placing
the cursor on the first line changed and pressing <RETURN> at the
beginning of each line. A program line is not actually changed until
<RETURN> is entered from somewhere within the line.
Writing Programs
Within BASIC,
MSX the editor is in control any time after an OK prompt
and before a RUN command is issued. Any line of text that is entered
is processed by the editor. Any line of text that begins with a number
is considered a program statement.
Program statements are processed by the editor in one of the following
ways:
1. line is added to the program. This occurs if the line
A new
is valid
number through 65529) and at least one non-blank
(O0
_13—
Language specification for MSX BASIC
1. existing characters
Typing over
2. Deleting characters to the right of the cursor
3. Deleting characters to the left of the cursor
4. Inserting characters
5. Appending characters to the end of the logical line
These actions are performed by special keys assigned to the various
Full Screen Editor functions (see next section).
Changes to a line are recorded when a carriage return is entered while
the cursor is somewhere on the line. The carriage return enters all
changes for that logical line, no matter how many physical lines are
included and no matter where the cursor is located on the line.
Table 1. MSX BASIC Control Functions. The ASCII control key is entered
by pressing the key while holding down the Control key.
Hex. Control Special
Code Key Key Function
01 A Ignored
02 * B Move cursor to start of previous word
03+* C Break when MSX is waiting for input
BASIC
04 D Ignored
05 * E Truncate line (clear text to end of logical
line)
06 * F Move cursor to start of next word
07 * G Beep
08 H Back Space Backspace, deleting characters passed over
09 I Tab Tab (moves to next TAB stop)
0A** J Line feed
0B K Home Move cursor to home position
oc * L CLS Clear screen
oD * M
Return Carriage return (enter current logical line)
0E * N Append to end of line
or * 0 Ignored
10 *
*
P Ignored
11 Q Ignored
12 * R INS Toggle insert/typeover mode
4 —
Language specification for MSX BASIC
13
M®:
s
q
Ignored
Ignored
15% U Clear logical line
16 * Vv
Ignored
17* W Ignored
18* x Select Ignored
19
l1A*
*
ï4 Ignored
Ignored
1B [ ESC Ignored
1C * fw
Right arrow Cursor right (íw is Won sign)
1D * |]
*
Left arrow Cursor left
l1E* Up arrow Cursor up
1F *
_ Down arrow Cursor down
7F DEL DEL Delete character at cursor
Note: Those keys marked with asterisk(*) cansels insert mode
when editor is in insert mode.
PREVIOUS WORD
The cursor is moved left to the previous word. The previous
word is defined as the next character to the left of the cursor
in the sets A-Z, a-z, or 0-9.
BREAK
Returns to MSX BASIC direct mode, without saving changes that
were made to the line currently being edited.
TRUNCATE
The cursor is moved to the end of the logical line. The
characters
the new
it passes over are deleted.
cursor position are appended to
Characters typed
the line.
{from
NEXT WORD
The cursor is moved right to the next word. The next word
is defined as the next character to the right of the cursor
in the sets A-Z, a-z, or 0-9.
BEEP
The beep sound will be produced.
BACKSPACE
Deletes the character to the left of the cursor. All characters
to the right of the cursor are moved left one position.
Subsequent characters and lines within the current logical
line are moved up (wrapped).
TAB
TAB moves the cursor to the next tab stop overwriting blanks.
Tab stops occur every 8 characters.
CURSOR HOME
Moves the cursor to the upper left corner of the screen. The
screen is not blanked.
CLEAR SCREEN
Language specification for MSX BASIC
Moves the cursor to home position and clears the entire screen,
zeiardiess of where the cursor is positioned when the key is
entered.
CARRIAGE RETURN
A carriage return ends the logical line
BASIC.
and sends it to MSX
APPEND
Moves cursor to the end of the line, without deleting the
characters passed over. All characters typed from the new
position until a carriage return are appended to the logical
line.
INSERT
Toggle switch for insert mode. When insert mode is on, the
size of the cursor is reduced and characters are inserted at
the current cursor position. Characters to the right of the
cursor move right as new ones are inserted. Line wrap is
observed.
When insert mode is off, the size of cursor returned to normal
size and typed characters will replace existing characters
on the line.
CLEAR LOGICAL LINE
When this
key is entered anywhere in the line, the entire
logical line is erased.
CURSOR RIGHT
Moves the cursor one position to the right. Line wrap is
observed.
CURSOR LEFT
Move the cursor one position to the left. Line wrap is
observed.
CURSOR UP
Moves the cursor up one physical line (at the current position).
CURSOR DOWN
Move the cursor down one physical line (at the current
position).
Logical line Definition with INPUT
—16—
Language specification for MSX BASIC
Insert mode increments the logical line except when the characters
moved will write over non-blank characters that are on the same physical
line but not part of the logical line. In this case, the non-blank
characters not part of the logical line are preserved and the characters
at the end of the logical line are thrown out. This preserves labels
that existed prior to the INPUT statement. If an incorrect character
is entered as a line is being typed, it can be deleted with the <Back
Space> key or with Control-H. and they backspacing over a character
and erasing it. Once a character(s) has been deleted, simply continue
typing the line as desired.
To delete a line that is in the process of being typed, type Control-U.
To correct program lines for a program that is currently in memory,
simply retype the line using the same line number. MSX BASIC will
automatically replace the old line with the new line.
To delete the entire program currently residing in memory, enter the
NEW command. NEW is usually used to clear memory prior to entering
a new program.
Function keys are also used as event trap keys. See ON KEY GOSUB and
KEY ON/OFF/STOP statement for details.
zij
Language specification for MSX BASIC
suspension of the program execution, and MSX BASIC turn on the cursor
display to indicate that the execution is suspended. Another STOP
key input resumes the execution, If the STOP key and control key are
pressed simultaneously, MSX BASIC terminates the execution and return
to command mode with following message.
Break in nnnn
where nnnn is the program line number where the execution stopped.
if ==
Language specification for MSX BASIC
CHAPTER 2
=19=
Language specification for MSX BASIC
NEW
To delete entire program from working memory and reset all
variables.
RENUM [[<new number>][,[<old number>][,<increment>]]]
To renumber program lines.
<new number> is the first line number to be used in the new
sequence. The default is 10. <old number> is the line in the
current program where renumbering is to begin. The default is
the first line of the program. <increment> is the increment
to be used in the new sequence. The default is 10.
RENUM also changes all line number references following GOTO,
GOSUB, THEN, ELSE, ON..GOTO, ON..GOSUB and ERL statements to
reflect the new line numbers. If a nonexistent line number
appears after one of these statement, the error message 'Undefined
line nnnn in mmmm' is printed. The incorrect line number
reference(nnnn) is not changed by RENUM, but line number mmmm
may be changed.
NOTE: cannot be used to change the order of program lines
RENUM
(for example, RENUM 15,30 when the program has three lines
numbered 10, 20 and 30) or to create line numbers greater than
65529. An ‘Illegal function call' error will result.
RUN [<line number>]
To execute a program.
_ 90 —
Language specification for MSX BASIC
TRON/ TROFF
To trace the execution of program statements.
As an aid in debugging, the TRON statement (executed in either
the direct or indirect mode) enables a trace flag that prints
each line number of the program as is executed. The numbers
appear enclosed in square brackets. The trace flag is disabled
with the TROFF statement (or when a NEW command is executed).
21 —
Language specification for MSX BASIC
DE
Language specification for MSX BASIC
24 —
Language specification for MSX BASIC
|
the main program. To prevent inadvertent entry into the
subroutine, it may be preceded by a STOP, END, or GOTO statement
that directs program control around the subroutine. Otherwise,
a 'RETURN without GOSUB' error message is issued and execution
is terminated.
GOTO <line number>
To branch unconditionally out of the normal program sequence
to a specified <line number).
If <line number> is an executable statement, that statement and
those following are executed. If it is a nonexecutable statement,
BE
execution proceeds at the first executable statement encountered
after <line number>.
IP <expression> THEN <statement(s) |<line number>
IF <expression> <line number>
GOTO
<statement (s) |<line number>]
[ELSE
To make a decision regarding program flow based on the result
returned by an expression.
If the result of <expression> is not zero, the THEN or GOTO clause
is executed. THEN may be followed by either a line number for
branching or one or more statements to be executed. GOTO is
always followed by a line number. If the result of <expression>
is zero, the THEN or GOTO clause is ignored and the ELSE clause,
if present, is executed. Execution continues with the next
executable statement.
Example:
A=l:B=2 -> A=B is zero (FALSE).
A=2:b=2 -> A=B is not zero (TRUE).
IF... THEN...ELSE statements may be nested. Nesting is limited
only by the length of the line. If the statement does not contain
the same number of ELSE and THEN clauses, each ELSE is matched
with the closest unmatched THEN. For example,
IF A=B THEN IF B=C THEN PRINT "A=c"
ELSE PRINT "A<>C"
will not print "A<>C" when A<>B. It will print "A<>C" when A=B
and B<>C.
If an IF...THEN statement is followed by a line number in the
Language specification for MSX BASIC
Responding to INPUT with too many items causes the message "?Extra
ignored" to be printed and the next statement to be executed.
Example:
list
10 INPUT "A and B";A,B
20 PRINT A+B
Ok
run
A and B? 10,20,30
?Extra ignored
30
Ok
ni DI me
Language specification for MSX BASIC
Responding to INPUT with too few item causes two question marks
to be printed and a wait for the next data item.
Example:
list
10 INPUT "A and B";A,B
20 PRINT A+B
Ok
run
A and B? 10 (The 10 was typed in by the user)
ee
Ok
(The 20 was typed in by the user)
97
Language specification for MSX BASIC
handling subroutine.
Once error trapping has been enabled all errors detected,
including direct mode errors (e.g., SN (Syntax) errors), will
cause a jump to the specified error handling subroutine. If
<line number> does not exist, an ‘Undefined line number’ error
results. To disable error trapping, execute an ON ERROR GOTO
0. Subseguent errors will print an error message and halt
execution. An ON ERROR GOTO 0 statement that appears in an error
trapping subroutine causes BASIC to stop and print the error
message for the error that caused the trap. It is recommended
that all error trapping subroutines execute an ON ERROR GOTO
0 if an error is encountered for which there is no recovery
action.
If an error occurs during execution of an error handling
subroutine, the BASIC error message is printed and execution
terminates. Error trapping does not occur within the error
handling subroutine.
ON <expression> GOTO <list of line number>
ON <expression> GOSUB <list of line number>
To branch to one of several specified line numbers, depending
on thevalue returned when an expression is evaluated. The valu.
of <expression> determines which line number in the list will
be used for branching. For example, if the value is three, the
third line number in the list will be the destination of the
branch. (If the value is a noninteger, the fractional portion
is discarded.)
In the ON...GOSUB statement, each line number in the list must
be the first line number of a subroutine.
If the value of is zero or greater than the number
<expression>
of items in the list less than or equal to 255), BASIC
(but
continues with the next executable statement. If the value of
<expression> is negative or greater than 255, a 'Illegal function
call! error occurs.
POKE <address of the memory>,<integer expression>
7 To write a byte into a memory location.
<address of the memory> is the
address of the memory location
to be POKEd. expression> is the data (byte) to
The <integer
be POKEd. It must be in the range 0 to 255. And <address of
the memory> must be in the’ range -32768 to 65535. If this value
is negative, address of the memory location is computed as
subtracting from 65536. For example, -1 is same as the 65535
(=65536-1). Otherwise, an 'Overflow'! error occurs.
PRINT [<list of expressions>]
To output data to the console.
_98—
Language specification for MSX BASIC
"&n spaces&”
Specifies that 2+n characters from the string are to be printed.
26
Language specification for MSX BASIC
If the '4&' signs are typed with no spaces, two characters will
be printed; with one space three characters will be printed,
and so on. If the string is longer than the field, the extra
characters are ignored. If the field is longer than the string,
the string will be left-justified in the field and padded with
spaces on the right.
Example:
A$="Korea"
Ok
PRINT USING "& &";A$
Japa
Ok
van
“;n
A plus sign at the beginning or end of the format string will
cause the sign of the number (plus or minus) to be printed before
or after the number.
Example:
— 30 —
Language specification for MSX BASIC
a
PRINT USING "+###.4#";1.25,-1.25
Ook
+1.25 -1.25
PRINT USING "###.##+";1.25,-1.25
1.25-
A minus sign at the end of the format field will cause negative
numbers to be printed with a trailing minus sign.
Example:
PRINT USING "###.##-";1.25,-1.25
1.25 1.25-
Ok
nen
A double asterisk at the beginning of the format string causes
leading spaces in the numeric field to be filled with asterisks.
The ** also specifies positions for two or more digits.
Example:
PRINT USING "**#,##";1.25,-1.25
**1.25#-1,25
Ok
gw
A double won sign causes a yen sign to be printed to the immediate
left of the formatted number. The ww specifies two more digit
positions, one of which is the won sign. The exponential format
cannot be used with ww. Negative numbers cannot be used unless
the minus sign trails …o the right.
Example:
PRINT USING "WW&###,##";12.35,-12.35
w12.35 -w12,35
Ok
PRINT USING "ww&4##, ##-";12.35,-12.35
w12.35 w12.35-
Ok
kkyn
The **w at the beginning of a format string combines the effects
of the above two symbols. Leading spaces will be asterisk-filled
and a won sign will be printed before the number. **w specifies
three more digit positions, one of which is the Won sign.
Example:
PRINT USING "**w#,##";12.35
*w12.35
Ok
—
31
Language specification for MSX BASIC
one digit position will be used to the left of the decimal point
to print a space or minus sign.
Example:
PRINT USING "##.##°7°°";234.56
2.35E+02
Ok
PRINT USING "#.##°77%-";-12.34
1.23E+01-
Ok
PRINT USING "%+#.##°°°";12.34,-12.34
+1.23E+01-1.23E+01
Ok
“9
If the number to be printed is larger than the specified numeric
field, a percent sign is printed in front of the number. Also,
if rounding causes the number to exceed the field, a percent
sign will be printed in front of the rounded number.
Example:
PRINT USING "##.##";123,45
3123.45
Ok
PRINT USING ",##";,999
41.00
Ok
ja
Language specification for MSX BASIC
_33_
Lang uage specification for MSX BASIC
4
Language specification for MSX BASIC
ASC(X$)
3 Returns a numerical value that is the ASCII code of the first
character of the string X$. If X$ is null, a 'Illegal function
call' error is returned.
ATN(X)
+ Returns the arctangent of X in radians. Result is in the range
-pi/2 to pi/2. The expression X may be any numeric type, but
the evaluation of ATN is always performed in double precision.
BIN$(n)
3
Returns a string which represents the binary value of the decimal
argument.
n is a numeric expression in the range -32768 to 65535. Ifn
is negative, the two's complement from is used. That is, BIN$(-n)
is the same as BIN$(65536-n).
CDBL(X)
; Converts X to a double precision number.
CHRS(I)
+ Returns a string whose one element is the ASCII code for I. ASC$
is commonly used to send a special character to the console,
etc.
CINT(X)
3 Converts X to a integer number by truncating the fractional
portion. If X isn't the range -32768 to 32767, an 'Overflow'
error occurs.
cos (X)
3 Returns the cosine of X in radians. COS(X) is calculated to
double precision.
CSNG(X)
3 Converts X to a single precision number.
CSRLIN
; Returns the vertical coordinate of the cursor.
ERL/ERR
3 When an error handling subroutine is entered, the variable ERR
contains the error code for error. and the variable ERL contains
the line number of the line in which the error was detected.
The ERR and ERL variables are usually used in IF...THEN statements
to direct program flow in the error trap routine.
If the statement that caused the error was a direct mode
Language specification for MSX BASIC
Otherwise, use
IF ERL=<line number> THEN …..
IF ERR=<error code> THEN....
Because ERL and ERR are reserved variables, neither may appear
to the left of the equal sign in a LET (assignment) statement.
EXP(X)
3 Returns e to the power of X. X must be <=145.06286085862. If
EXP overflows, the 'Overflow' error message is printed.
FIX(X)
; Returns the integer part of X (fraction truncated). PIX(X) is
equivalent to SGN(X)*INT(ABS(X)). The major difference between
FIX and INT is that FIX does not return the next lower number
for negative X.
FRE(0)
FRE("")
; Arguments to FRE are dummy arguments. FRE returns the number
of bytes in memory not being used by BASIC.
FRE(0) returns the number of bytes in memory which can be used
for BASIC program, text file, machine language program file,
etc. FRE("") returns the number of bytes in memory for string
space.
HEXS (X)
3 Returns a string which represents the hexadecimal value of the
decimal argument.
n is a numeric expression in the range -32768 to 65535. Ifn
is negative, the two's complement from is used. That is, HEX$(-n)
is the same as HEX$(65536-n).
INKEY$
; Returns either a one-character string containing a character
read from the keyboard or a null string if no key is pressed.
No characters will be echoed and all characters are passed through
to the program except for Control-C, which terminates the program.
INPUTS (X)
3 Returns a string of X characters, read from the keyboard. No
character will be echoed and all character: are passed through
except Control-C, terminates the execution of the INPUTS function.
INSTR([I,]X$,Y$)
3 Searches for the first occurrence of string Y$in X$ and returns
the position at which the match is found. Optional offset I
a TG ie
Language specification for MSX BASIC
LEFTS(XS,I)
3 Returns a string comprising the leftmost I characters of X$.
I must be in the range 0 to 255. If I is greater than LEN(XS),
the entire string (X$) is returned. If I=0, a null string (length
zero) is returned.
LEN(X$)
3 Returns the number of characters in X$. Nonprinting characters
and blanks are counted,
LOG(X)
; Returns the natural logarithm of X. X must be greater than zero.
LPOS(X)
; Returns the current position of the line printer print head within
the line printer buffer. Does not necessarily give the physical
position of the print head. X is a dummy argument.
MIDS(X$,I[,9])
; Returns a string of length J characters from X$ beginning with
the Ith character. I and J must be in the range 1 to 255. If
J is omitted or if there are fewer than J characters to the right
of the Ith character, all rightmost characters beginning with
the Ith character are returned. If I>LEN(X$), MIDS returns a
null string.
ocT$(n)
3 Returns a string which represents the octal value of the decimal
argument.
n is a numeric expression in the range -32768 to 65535. If n
is negative, the two's complement from is used. That is, OCT$(-n)
is the same as OCT$(65536-n).
PEEK(I)
3 Returns the byte integer in the range 0 to 255) read
(decimal
from memory location I. I must be in the range -32768
to 65535.
PEEK is the complementary function to the POKE statement.
POS(I)
; Returns the current cursor position. The leftmost position is
0. I is a dummy argument.
RIGHTS (X$,I)
; Returns the rightmost I characters of string XS. If I=LEN(X$),
return X$. If I=0, a null string (length zero) is returned.
en
Language specification for MSX BASIC
RND(X)
3 Returns a random number between 0 and 1. The same sequence of
random number is generated each time the program is RUN. If
x<0, the random generator is reseeded for any given Xx. X=0
repeats the last number generated. X>0 generates the next random
number in the sequence.
SGN(X)
3 Returns 1 (for X>0), O0
(for X=0), -1 (for X<0).
SIN(X)
3 Returns the sine of X in radians. SIN(X) is calculated to double
precision.
SPACE$ (X)
3 Returns the string of spaces of length Xx. The expression Xx
STRING$(1,J)
STRING$(I,X$)
3 Returns a string of length I whose characters all have ASCII
code J or the first character of the string X$.
TAB(I)
3
Spaces to position I on the console. If the current print
position is already beyond space I, TAB does nothing. Space
0 is the leftmost position, and the rightmost position is the
width minus one. I must be in the range 0 to 255. TAB may only
be used with PRINT and LPRINT statements.
TAN(X)
3
Returns the tangent of X in radians. TAN(X) is calculated to
double precision. If TAN overflows, an 'Overflow' error will
occur.
USR[<digit>] (X)
3 Calls the user's assembly language subroutine with the argument
X. <digit> is in the range 0 to 9 and corresponds to the digit
supplied with the DEFUSR statement for that routine. If <digit>
is omitted, USRO is assumed.
VAL (XS)
+ Returns the numerical value of the string X$. The VAL function
also strips leading blanks, tabs, and linefeeds from the argument
_38—
Language specification for MSX BASIC
VARPTR(<variable name>)
VARPTR(#<file number>)
+ Returns the address of the first byte of data identified with
<variable name>. A value must be assigned to <variable name>
prior to execution of VARPTR. Otherwise, an 'Illegal function
call' error results. Any type variable name may be used (numeric,
string, array), and the address returned will be an integer in
the range -32768 to 32767. If a negative address is returned,
add it 65536 to obtain the actual address,
£o
9
Language specification for MSX BASIC
2.2.1 Statements
SCREEN [<mode>][,<sprite size>] [,<key click switch>]
[,<cassette baud rate>][,<printer option>]
+ To assign the screen mode, sprite size, key click, cassette baud
rate and printer option.
<mode> should be set to 0 to select 40x24 text mode, l to select
32x24 text mode, 2 to select high resolution mode, 3 to select
multi color (low-resolution mode).
0:40x24 text mode
1:32x24 text mode
2:high resolution mode
3:multi color mode
<sprite size> determines the size of sprite. Should be set to
0 to select 8x8 unmagnified sprites, l to select 8x8 magnified
sprites, 2 to select 16x16 unmagnified sprites, 3 to select 16x16
magnified sprites. NOTE: If <sprite size> is specified, the
contents of SPRITE$ will be cleared.
0:8x8 unmagnified
1:8x8 magnified
2:16x16 unmagnified
3:16x16 magnified
<key click switch> determines whether to enable or disable the
key click. Should be set to 0 to disable it.
O:disable the key click
non zero:enable the key click
Note that in text mode, all graphics statements except 'PUT
SPRITE' generate an 'Illegal function call' error. Note also
that the mode is forced to text mode when an 'INPUT' statement
is encountered or BASIC returns to command level.
<cassette baud rate> determines the default baud rate for
succeeding write operations. 1 for 1200 baud, and 2 for 2400
baud. Baud rate can also be determined using CSAVE command with
baud rate option.
Note that when reading cassette, baud rate is automatically
determined, so the user don't have to know in what baud rate
the cassette is written. <printer option> determines if the
printer in operation is 'MSX printer' (which has 'graphics symbol
and 'HIRAGANA' capability) or not. Should be non-0 if the printer
does not have such capability. In this case, graphics symbols
40 —
Language specification for MSX BASIC
—41-
Language specification for MSX BASIC
the ellipse will begin and end. If the start or end angle is
negative, the ellipse will be connected to the center point with
a line, and the angles will be treated as if they were positive
(Note that this is different than adding 2*PI).
The <aspect ratio> is for horizontal and ‘vertical ratio of the
ellipse.
42
Language specification for MSX BASIC
The following two prefix commands may precede any of the above
movement commands.
B doesn't plot any points.
;Moves, but
N returns to the original position
;Moves, but
when finished.
The following commands are also available:
An iSets angle n. may range from to 3, where
mn O0
0 is O0
degree, 1 is 90, 2 is 180, 3 is 270.
0
1
l--+--3
l
_43—
Language specification for MSX BASIC
KEY LIST
3 To list the contents of all function keys.
Example:
KEY LIST
color
auto
goto
list
run
color 15,7,7
cload"
cont
list
run
Ok
"color" aligns with key "fl", "auto" with "f2", "goto" with "£3",
and so on. Position in the list reflects the key assignments
Note that control characters assigned to a function key is
converted to spaces.
KEY ON|OFF
3 To turn on/off function key display on 24th line of text screen.
_45-—
Language specification for MSX BASIC
Event trapping does not take place when BASIC is not executing
a program. When an error trap (resulting {from an ON ERROR
statement) takes place this automatically disables all trapping
(including ERROR, STRIG, STOP, SPRITE, INTERVAL and KEY).
STRIG (<n>) ON/OFF/ STOP
To activate/deactivate trapping of trigger buttons of joy sticks
in a BASIC program.
<n> can be in the range of 0..4. If <n>=0, the space bar is
used for a trigger button. If <n> is either l or 3, the trigger
of a joy-stick 1 is used. When <n> is either 2 or 4, joy-stick
2.
A STRIG(n)ON statement must be executed to activate trapping
_ 46 —
Language specification for MSX BASIC
STOP ON/OFF/STOP
3 To activate/deactivate trapping of a control-STOP.
A STOP ON statement must be executed to activate trapping of
a control-STOP. After STOP ON statement, if a line number is
specified in the ON STOP GOSUB statement then every time BASIC
starts a new statement it will check to see if a control-STOP
was pressed. If so, it will perform a GOSUB to the line number
specified in the ON STOP GOSUB statement.
If a STOP OFF statement has been executed, no trapping takes
place and the event is not remembered even if it does take place.
If statement has been executed, no trapping will
a STOP STOP
take place,but if a control-STOP is pressed this is remembered
so an immediate trap will take place when STOP ON is executed.
ON SPRITE GOSUB <line number>
Ss
Language specification for MSX BASIC
Event trapping does not take place when BASIC is not executing
a program. When an error trap (resulting {from an ON ERROR
statement) takes place this automatically disables all traps
(including ERROR, STRIG, STOP, SPRITE, INTERVAL and KEY).
INTERVAL ON/OFF/STOP
3 To activate/deactivate trapping of time interval in a BASIC
program.
A INTERVAL ON statement must be executed to activate trapping
of time interval.
After INTERVAL ON statement, if a line number
is specified in the ON INTERVAL GOSUB statement then every time
If so it will perform a GOSUB to itthe line number specified in
BASIC starts a new statement will check the time interval.
the ON INTERVAL GOSUB statement.
Language specification for MSX BASIC
PLAY <string exp for voice l>[,<string exp for voice 2> [,<string exp
for voice 3)>]]
+ To play music according to music macro language.
PLAY implements a concept similar to DRAW by embedding a "music
macro language" character string. <stting exp for voice
into a
n> is a string expression consisting of single character music
commands. When a null string is specified, the voice channel
remains silent. The single character commands in PLAY are:
A to G with optional #,+,0r -
;Plays the indicated note in the current octave.
A number sign(#) or plus sign(+) afterwards
indicates a sharp, a minus sign(-) indicates
a flat. The #,+, or - is not allowed unless
it corresponds to a black
example, B# is an invalid note.
key on a piano. For
—49-—
Language specification for MSX BASIC
4 is 36.)
Ln Sets the length of the following notes. The
actual note length is 1l/n. n may range {from
l to 64, The following table may help explain
this:
Length Equivalent
Ll whole note
12 half note
L3 one of a triplet of three
half notes (1/3 of a 4 beat
measure)
L4 quarter note
L5 one of a quintuplet (1/5
of a measure)
L6 one of a quarter note triplet
L64 sixty-forth note
The length may also follow the note when you
want to change the length only for the note.
For example, Al6 is equivalent to L16A. The
default is 4.
;Pause(rest). may range from l to 64,
mn
and
figures the length of the pause in the same
way as L(length). The default is 4.
3 (Dot or period) After a note, causes the note
to be played as a dotted note. That is, its
length is multiplied by 3/2. More than one
dot may appear after the note, and the length
is adjusted accordingly. For example, "A..."
will play 27/8 as long, etc. Dots may also
appear after the pause(P) to scale the pause
length in the same way.
;Tempo. Sets the number of quarter notes in
a minute. may range from 32 to 255.
mn The
default is 120.
Volume. Sets the volume of output. n may range
from 0 to 15. The default is 8.
;Modulation. Sets period of envelope. n may
range from l to 65535. The default is 255.
;Shape. Sets shape of envelope. n may range
from l to 15. The default is 1. The pattern
set by this command are as follows:
_50-—
Language specification for MSX BASIC
0,1,2:3,9 \
Xx<variable>;
jExecutes specified string.
In all of these commands the n argument can be a constant like
12 or it can be "=<variable>;" where variable is the name of
a variable. The semicolon(;) is required when you use a variable
in this way, and when you use the X command. Otherwise, a
semicolon is optional between commands.
Note that values specified with above commands will be reset
to the system default when beep sound is generated.
MAXFILES=<expression>
; To specify the maximum number of files opened at a time,
<expression> can be in the range of 0..15. When 'MAXFILES=0'
is executed, only SAVE and LOAD can be performed.
arb ae
Language specification for MSX BASIC
— 52 —
Language specification for MSX BASIC
zS5j=
Language specification for MSX BASIC
55
Language specification for MSX BASIC
2.2.2 Functions
POINT(<X coordinate>,<Y coordinate>)
3 Returns color of a specified pixel.
VPEEK(<address of VRAM>)
Returns a value of
3 VRAM specified. <address of VRAM) can be
in the range of 0..16383.
STICK (<n>)
+ Returns the direction of a joy-stick. <n> can be in the range
of 0..2. If <n>=0, the cursor key is used as a joy-stick. If
<n> is either l or 2, the joy-stick connected to proper port
is used. When neutral, 0 is returned. Otherwise, value
corresponding to direction is returned.
a
u
8 | 2
\1 7
7
\I/
/l
6
ZIN| 4
5
STRIG(<n>)
+ Returns the status of trigger button of a joy-stick. <n> can
a
be in the range of 0..4. If <n>=0, the space bar is used for
a trigger button. If <n> is either 1 or 3, the trigger of a
joy-stick 1 is used. When <n> is either 2 or 4, joy-stick 2.
0 is returned if the trigger is' not being pressed, -1 is returned
otherwise.
PDL (<n>)
3 Returns the value of a paddle. <n> can be in the range of 1..12.
When <n> is either 1, 3, 5, 7, 9 or 11, the paddle connected
to port 1 is used. When 2, 4, 6, 8, 10 or 12, the paddle
connected to port 2 is used.
PAD(<n>)
7 Returns various status of touch pad. <n> can be in the range
of 0..7.
When 0..3 is specified, touch pad connected to joy stick port
l is selected, when 4..7, port 2.
When <n>=0 or 4, the status of touch pad is returned, -1 when
touched, 0 when released.
When <n>=l or 5, the X-coordinate is returned, when <n>=2 or
6, Y-coordinate is returned.
When <n>=3 or 7, the status of switch on the pad is returned,
_56—
Language specification for MSX BASIC
ee
« or assigned like other ordinary variables. Prepared for *
* advanced programmers only. If you don't know the meaning, *
RKK
u
*
never use. 5
*
KAKKEN KRK KAAK KKK KR RKK KKK KK KRK KRK KR
-58-—
Language specification for MSX BASIC
=i6Û ==
Language specification for MSX BASIC
CHAPTER 3
APPENDIX
code message
1 NEXT without FOR
A variablein a NEXT statement does not
correspond to any previously executed, unmatched
FOR statement variable.
Syntax error
A line is encountered that contains some
incorrect sequence of characters (such as
unmatched parenthesis, misspelled command or
statement, incorrect punctuation, etc.)
RETURN without GOSUB
A RETURN statement is encountered for which
there is no previous, unmatched GOSUB statement.
Out of DATA
A READ statement is executed when there are
no DATA statement with unread data remaining
in the program.
Illegal Afunction call
parameter that is out of the range is passed
to a math or string function. An FC error
may also occur as the result of:
Overflow
The result of a calculation is too large to
be represented in BASIC's number format.
7 Out of memory
A program is too large, has too many files,
has too many FOR loops or GOSUBs, too many
variables, or expressions that are too
ai =
Language specification for MSX BASIC
complicated.
8 Undefined line number
A line reference in a GOTO, GOSUB,
IF... THEN...ELSE is to a nonexistent line.
9 Subscript out of range
An array element is referenced either with
a subscript that is outside the dimensions
of the array, or with the wrong number of
subscripts.
10 Redimensioned array
Two DIM statements are given for the same array,
or DIM statement is given for an array after
the default dimension of 10 has been established
for that array.
11 Division by zero
A by zero is encountered in an
division
expression, or the operation of involution
results in zero being raised to a negative
power.
12 Illegal direct
A statement that is illegal in direct mode
is entered as a direct mode command.
13 Type mismatch
A string variable name is assigned a numeric
value or vice versa; a function that expects
a numeric argument is given a string argument
or vice versa.
14 Out of string space
String variables have caused BASIC to exceed
the amount of free memory remaining. BASIC
will allocate string space dynamically, until
it runs out of memory.
15 String too long
An attempt is made to create a string more
than 255 character long.
16 String formula too complex
A string expression is too long or too complex.
The expression should be broken into smaller
expressions.
17 Can't continue
An attempt is made to continue a program that:
1. has halted due to an error,
2. has been modified during a break in
execution, or
62 —
Language specification for MSX BASIC
20 Verify error
The current program is different {from the
program saved on the cassette.
21 No RESUME
An error trapping routine is entered but
contains no RESUME statement.
22 RESUME without error
A RESUME statement is encountered before an
error trapping routine is entered.
23 Unprintable error
An error message is not available for the error
condition which exists. This is usually caused
by an ERROR with an undefined error code.
24 Missing operand
An expression contained an operator with no
operand following it.
25 Line buffer overflow
An entered line has too many characters.
26 Unprintable errors
These codes have no definitions. Should be
49 reserved for future expansion in BASIC.
50 FIELD overflow
A FIELD statement is attempting allocate more
bytes than were specified for the record length
of a random file in the OPEN statement. Or,
the end of the FIELD buffer is encountered
while doing sequential I/O(PRINT#, INPUT#) to
a random file.
51 Internal error
An internal malfunction has occurred. Report
to Microsoft the conditions under which the
message appeared.
52 Bad file A number
statement or command references a file with
a file number that is not OPEN or is out of
ij
Language specification for MSX BASIC
582 -026A