MSX2 TECHNICAL HANDBOOK ----------------------- Edited by: ASCII Systems Division Published by: ASCII Coprporation - JAPAN First edition: March 1987 Text files typed by: Nestor Soriano (Konami Man) - SPAIN March 1997 Changes from the original: - In description of REM statement, [] field has been added. - In description of SGN function, "Examines the sign and returns..." has been substitued for "Examines the sign of and returns..." - Descriptions for MSX DISK-BASIC statements DSKI$ and DSKO$ have been added. - Descriptions for new commands on MSX DISK-BASIC version 2 have been added. - In Table 2.20 (List of intermediate codes), the code "FC" is shown as assigned to "\" as it is actually, and not to "$" as in the original text. - In List 2.3 (Changing error handling routine), the third line of "command initialize", which is "LD HL,CMDHDAT" in the original, is corrected and substitued by "LD HL,HDAT". - In section 5, "Notes on Software Development", subsection "BASIC version number", the part "and so on" has been added in point 1. - In error code list, description of errors 72 to 75 have been added. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- CHAPTER 2 - BASIC The BASIC of MSX2 has been upgraded: the new version is called MSX BASIC version 2.0. And, when using a disk system, MSX DISK-BASIC can be used, which consists of MSX BASIC version 2.0 and additional instructions for disk operations. The following sections describe these two versions of BASIC. 1. LIST OF INSTRUCTIONS First of all, the sentence and function for each instruction of BASIC are listed. Each instruction is listed in the format shown in Figure 2.1. Figure 2.1 Instruction list format --------------------------------------------------------------- | Instruction format | | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | | Instruction type | Function or action of instruction | --------------------------------------------------------------- (a) Syntax of instructions If there is an "*" followed by a keyword, it indicates that the syntax or function of the instruction has just been modified after version 1.0, or that the instruction has been added to version 2.0. Descriptions of sentences use the following notational conventions. * [item] .............. the item is optional * [, item ... ] ....... more items having the same form may appear * [item1 | item2] ..... choose item1 or item2 And , which is used in the sentence, is a string specifying I/O devices or files for input/output in the format listed below. for a cassette files is a string consisting of any combination of up to 6 characters. for disk or RAM disk is a string, whose form is " + ". is one of characters from A to H (depending on the number of drives connected). "CAS: " ..... Cassette file "MEM: " ..... RAM disk "CRT:" ................ Text screen "GRP:" ................ Graphic screen "LPT:" ................ Printer ":" .. Disk file (b) Instruction type There are four types of instructions: * Function ............ Returns a certain value depending on the given parameter(s). * System variable ..... Variables available from BASIC. Generally, assignment is allowed. * Statement ........... Takes a certain action. * Command ............. Gives an instruction to BASIC interpreter itself. (c) Function or action of instruction The following list gives a brief description of the action for each instruction. More detailed descriptions about instructions which have been modified or added at version 2.0 are given in section 2. 1.1 Instructions of MSX BASIC version 2.0 --- A --- ABS () Function Returns absolute value of . ASC () Function Returns the code of the first character of . ATN () Function Returns arc tangent of in radians. AUTO [[, ]] Command Produces line numbers automatically. --- B --- * BASE () System variable Contains the table address of the screen assigned on VRAM. BEEP Statement Produces beep to the audio terminal. BIN$ () Function Converts the value of to a string of binary expression, then returns its result. BLOAD ""[,R[,offset]] Command Loads an assembly language program. BSAVE "",,[,] Command Saves an assembly language program. --- C --- CALL [([,...])] Statement Calls the extended statements by inserting various cartridges. * CALL MEMINI [()] Statement Specifies the upper limit of memory for Ram disk. * CALL MFILES Statement Lists file names in RAM disk. * CALL MKILL ("") Statement Deletes a file in RAM disk. * CALL MNAME ("" AS "") Statement Renames a file in RAM disk. CDBL () Function Converts the value of to a double precission real value and returns its result. CHR$ () Returns a character which has the code of Function value. CINT () Function Converts the value of to an integer value and returns its result. * CIRCLE {(X,Y) | STEP(X,Y)},[, [, [, [, ]]]] Statement Draws a circle whose center is at (X,Y) and whose size depends on . CLEAR [[, ]] Statement Initialises variables and sets the size of memory area. CLOAD [""] Command Loads a program from cassette. CLOAD? [""] Command Compares a program on cassette with the one in memory. CLOSE [[#][, [#]...]] Command Closes a file represented by . CLS Statement Clears screen. * COLOR [[, [, ]]] Statement Specifies the colours of each part of the screen. * COLOR [=NEW] Statement Initialises the palette. * COLOR = (, , , ) Statement Sets the palette colour. * COLOR = RESTORE Statement Puts the contents of the colour palette storage table into the palette register. * COLOR SPRITE ()= Statement Sets the colour to the sprite of to the specified colour. * COLOR SPRITE$ ()= Statement Sets the colour of each horizontal line of the sprite using . CONT Command Resumes the execution of the program which has been stopped. * COPY TO Statement Transfers the screen data among the screen, array, and disk file. * COPY SCREEN [] Statement Writes colour bus data into VRAM (optional). COS () Function Returns the cosine value of . CSAVE ""[, ] Command Saves a program to cassette. CSGN () Function Converts the value of to a single precision real value, and returns its result. CSRLIN System variable Contains the vertical screen location of the cursor. No assignment is allowed. --- D --- DATA [, ...] Statement Prepares data to be read by READ statement. DEF FN [([, ...])]= Statement Defines a user-defined function. DEFINT [, ...] Statement Declares the specified variable(s) as integer type. DEFSNG [, ...] Statement Declares the specified variable(s) as single precision real type. DEFDBL [, ...] Statement Declares the specified variable(s) as double precision real type. DEFSTR [, ...] Statement Declares the specified variable(s) as character type. DEF USR []= Statement Defines the starting address for the execution of assembly language routine, called by USR function. DELETE {[-] | | -} Command Deletes the specified portion of the program. DIM ([, ...]) Statement Defines an array variable and allocates it into memory. DRAW Statement Draws a line or lines on the screen according to . --- E --- END Statement Ens the program, close all files, and returns to the command level. EOF () Function Checks if the file is finished and returns -1 if at the end of file. ERASE [, ...] Statement Deletes the array variable(s). ERL System variable Contains the error code for the preceding error. No assignment is allowed. ERR System variable Contains the line number of the previous error. No assignment is allowed. ERROR Statement Puts the program into the error condition. EXP () Function Returns the exponent (power) of the natural exponential form of . --- F --- FIX () Function Returns the value of , without any decimal fractions. FOR = TO [STEP ] Statement Repeats the execution from FOR statement to NEXT statement for the specified times. FRE ({ | }) Function Returns the size of unused user's area or unused character area. --- G --- * GET DATE [, A] Statement Assigns date into a string variable. * GET TIME [, A] Statement Assigns time into a string variable. GOSUB Statement Calls the subroutine at . GOTO Statement Jumps to . --- H --- HEX$ () Function Converts the value of to a string of hexadecimal expression, then returns its result. --- I --- IF THEN { | } [ELSE { | }] Statement Judges the condition. If is not zero, it is true. IF GOTO [ELSE { | }] Statement Judges the condition. If is not zero, it is true. INKEY$ Function Returns a character when a key is being pressed, or when not, returns null string. INP () Function Reads the port specified by and returns its result. INPUT ["";][, ...] Statement Assigns data input from keyboard into the specified variable(s). INPUT #, [, ...] Statement Reads data from the file and assigns the data into the specified variable(s). INPUT$ ([, [#]]) Function Reads the specified size of string from the keyboard or file. INSTR ([,],) Function Searches from the left of , and returns its location if found, otherwise zero. is the character location to start searching. INT () Function Returns the largest integer less than . INTERVAL {ON | OFF | STOP} Statement Allows, suppresses, or suspends the timer interrupt. --- K --- KEY , Command Redefines a function key. KEY LIST Command Displays the contents of function keys. KEY (){ON | OFF | STOP} Statement Allows, supresses, os suspends the function key interrupt. KEY {ON | OFF} Statement Specifies whethter to display the contents of function keys at the bottom of the screen. --- L --- LEFT$ (,) function Gets characters from the left of . LEN () Function Returns the number of characters of . [LET] = Statement Assigns the value of to the variable. * LINE [{(X1,Y1) | STEP(X1,Y1)}] - {(X2,Y2) | STEP(X2,Y2)}[, [, {B|BF}[, ]]] Statement Draws a line or a rectangle on the screen. LINE INPUT ["";] Statement Assigns a whole line of string data from the keyboard into the string variable. LINE INPUT# , Statement Reads data in lines from the file and assigns the data into the string variable. LIST [[] - []] Command Displays the program in memory on the screen. LLIST [[] - []] Command Sends the program in memory to the printer. LOAD "" [,R] Command Loads a program saved in ASCII format. * LOCATE [[, [, ]]] Statement Locates the cursor on the text screen. LOG () Function Returns the natural logarithm of . LPOS () System variable Contains the location of the printer head. No assignment is allowed. LPRINT [[{; | ,}...] Statement Outputs characters or numerical values to the printer. LPRINT USING
; [{; | ,}...] Statement Outputs characters or numerical values through the printer according to . --- M --- MAXFILES = Statement Sets the number of files to be opened. MERGE "" Command Merges the program in memory with the program saved in ASCII format (in external storage device). MID$ (, [, ]) Function Returns character(s) starting from the th position of . MID$ (, [, ]) = Statement Defines using character(s) from the th position of . MOTOR [{ON | OFF}] Statement Turns the motor of cassette ON and OFF. --- N --- NEW Command Deletes the program in meory and clears variables. NEXT [[, ...]] Statement Indicates the end of FOR statement. --- O --- OCT$ () Function Converts the value of to the string of octal expression and returns its result. ON ERROR GOTO Statement Defines the line to begin the error handling routine. ON GOSUB [, ...] Statement Executes the subroutine at according to . ON GOTO [, ...] Statement Jumps to according to . ON INTERVAL =