MSX Technical Data Book Hardware/Software Specifications Presented by Robsy"s MSa Hor kshop Originaly scanned by Ivan Latorre Converted to PDF Eduardo Robsy [September 2004] SONY. MSX Technical Data Book Hardware/Software Specifications SONY. Sony Corporation 4 14 1, Asahi-cho, Atsugi- shi, Kanagawa-ken, 243 Japan Copyright © 1984 Microsoft Corporation Produced by ASCII Corporation Printed in Japan PREFACE The Microsoft MSX standard was invented to provide end users and software developers with a standardized computer so that programs could run on any computer even though they were made by different manufacturers. This book presents the MSX specifications in detail. It is intended to be a reference for advanced programmers and software developers. The information is generally divided four parts. Part A, MSX HARDWARE SPECIFICATIONS, presents the specifications for the MSX system hardware. Chapter 1, Hardware Specification, covers the MSX standard hardware configuration in terms of the requirements for the LSIs, memory size, interrupts, screen, keyboard, and sound used in the main unit; and the various (cassette, floppy, printer, serial, and slot) interfaces and connectors. It also covers topics such as cartridges, expansion, ports, and memory maps. Part B, MSX SYSTEM SOFTWARE, contains a reference guide for MSX- BASIC and information for advanced programming. Chapter 2, Language Specification, is a guide to MSX~-BASIC and is for use with advanced programming requiring machine lan- guage routines. Part C, EXPANDED MSX SYSTEM SOFTWARE, is about the advanced fea~ tures of MSX, including Expanded Disk BASIC and MSX-DOS. Chapter 3, MSX-DOS, contains a user's guide to MSX-DOS and Disk BASIC, and includes information needed for the advanced programmer. Chapter 4, Other Expansion, covers the serial (RS-232C) ex- pansion and BIOS calls available in the extended version. Part D, SOFTWARE DEVELOPMENT GUIDE, contains information for soft- ware developers. Chapter 5, International MSX Versions and their Differences, is for manufacturers or programmers who wish to make the hardware or software be usable internationally. Chapter 6, Notes for MSX Software Developers, contains information that software developers should consider when programming for MSX computers. Syntax Notation in Reference Sections Wherever the format for a statement/command or a function is given, the following rules apply: CAPS Items in capital letters must be input as shown. <> Items in lowercase letters enclosed in angle brackets (< >) are to be supplied by the user. [J] Items in square brackets ([ ]) are optional. coe Items followed by an ellipsis (...) may be repeated any number of times (up to the length of the line). { } Braces indicate that the user has a choice between two or more entries. At least one of the entries enclosed in braces must be chosen unless the entries are also enclosed in square brackets. ! Vertical bars separate the choices within braces. At least one of the entries separated by bars must be chosen unless the entries are also enclosed in square brackets. All punctuation except angle brackets and square brackets (i.e., commas, parentheses, semicolons, hyphens, equal signs) must be included where shown. Arguments to functions are always enclosed in parentheses. In the formats given for the functions in this book, the arguments are abbreviated as follows: X and Y Represent any numeric expressions. I and J Represent integer expressions. X$ and Y$ Represent string expressions. CONTENTS PART A MSX HARDWARE SPECIFICATIONS 1. Hardware Specifications 1.1 MSX Standard .... ccc ee eee ... eee 1.2 MSX System Configuration ec cccccee oe ee WR 1 Main Unit ........ ee eececccee me PRP Ree 1 oe 2 Memory ....... oe 3 Interrupts ..... 4 Screen .. eee WWWWWW 5 Keyboard ............4 6 Sound .........66. teeeeceee a nterfaces ..... Oe eerccccrccccccs BEE RRP RP ee ee eae 0 1 Cassette Interface ............ 2 Floppy Disk Interface «8 3 Printer Interface ... . 4 RS-232C Interface ...... eeeeeeee 5 Peripheral I/O Port(s) ........ 6 Joysticks ...... ee vocsces eee 7 Paddles .......000. 8 Connectors .....-.-ee 9 SLOCS ..scecceeeeee B Ule Ci ALCKLAGES . ee ce ewe new cece Eee 1 Cartridge Standard ..........sceeceee eee 2 Cartridge BUS ..... cece cece.. eevee naan 3 Cartridge Bus Connenction Conditions BER . 4 Cartridge Power Capacity .-cceecccesscvccuccseeeveeeedd Nee 5 Sample Circuit Diagram of Expanded Slot Select Signal35 ew Notes for System Expansion ......ceseeeeee +636 PREP RP RRP PEPER EER, RAM Expansion ...ceececscccccece ee Slot ExpansSion ..-.cereececcvvvcces I/O Expansion .e.eceeecee ees eene GdresS MapS «eee e eee eee encees Memory Map ..---eececcccencccce eee I/O Address Map ......-eseeeeeee Printer Port ... ee PPI Port eee External Memory (SONY) eee eeees Light Pen (SANYO) .....-....... Audio/Video Control ....... tse eeee 0 Notes on I/O Address Assignments . -11 8255 (PPI) Bit Assignments ..... 2 PSG Bit Assignments ............06 PAR! TB MSX SYSTEM SOFTWARE 2. Language Specifications 2.1 MSX BASIC Reference Guide ...........2.2008 Soecceeee 00 46 2.1.1 Modes of Operation ............... . NRNYUNNNNNNNNNNNYNYNNN 1.2 Line FOrmat 2... ec c cece eee e reece ccs ee ce eenecec ec cAT 1.3 Character Set ....... wee A] 1.4 Constants .... weAB 1.5 Variables ....... 200250 1.6 Type Conversion .........eeeeee 1.7 Expressions and Operators ..... 1.8 Program Editing ...........ee0e «1.9 Special Keys ........... e1.10 Error Messages 22... ccc cc cence cece cece ee cacceer 63 +1.11 Commands and Statements except those doing I/O .. -63 +1.12 Functions except those doing I/O ....... eee .c eeee -79 +1.13 Device Specific Statements ........ . «1.14 I/O Functions .............. . e1.15 Special Variables 2... . cece eee cece eee -1.16 Machine Dependent Statements and Functions . -1.17 Summary of Error Codes and Messages ........ -1.18 MSX BASIC Reserved Words ...........4. 2.2 Advanced Programming Guide ........... 2.2.1 BIOS Entry List ........ 2.2.2 Work Area .........-.-- 2.2.3 Slot Control 2... .. cee cece c cece e eee 2.2.4 Cassette I/O Mechanism ........ 2.2.5 MSX Printer Specifications ......ceccceecsuuencs PART C EXPANDED MSX SYSTEM SOFTWARE 3. MSX~-DOS System RequirementS ............-06 Getting Started ........ cece eens Wild Cards ............ Illegal File Names .... we weccees DiLeECtOrieS 2... eee cece cece ee eeees Types of MSX-DOS Commands ......... seer Command Options .eeeceececvccccecccccecevcee Information Common to All MSX-DOS Commands . Batch Processing ...... PRWHrO MSX~DOS Editing and Function Keys ........ Instructions for Users with Single-drive Systems HNN DiSk ELLOrs eee ec cece eee cece en cece eevee ceseeeee s20L X-DOS Command Guide .........- X Disk BASIC Reference Guide Commands and Statements ....... FUNCLIONS .e eee e ee eee eee ccc eeee . Error Codes and Error Messages .... ISX-DOS and Disk BASIC Boot Procedure iSX~DOS and Disk BASIC Disk Drivers .. 4. Other Expansion 4.1 MSX-RS232C Support 2... cccc cee s ccc ec cece rnc rncceccn nee 290 4.1.1 Extended BASIC for RS-232C Communication «291 4.1.2 Extended BIOS Calls Handling RS-232C .... 300 4.2 Other MSX Extended BIOS Calls ... «309 4.2.1 Extended BIOS Calls .......... +309 4.2.2 Extended BIOS Maker ID Number +313 4.3 Tenkey Support On MSX ceeececcccccccccecccccccceeceeee ssl PART D SOFTWARE DEVELOPMENT GUIDE 5. International MSX Versions and their Differences 5.1 Introduction . nere Ss ) 5.2 Keyboard ..... +316 5.2.1 Keyboard Hardware ..... wee 316 5.2.2 Character Set ..-eeeeceeeeees 317 5.2.3 Keyboard Layout ...........- +319 5.2.4 CAPS Lock ..... . 319 5.2.5 DEAD-Key Functions . 331 5.3 Screen Mode ........ccceecescece . -333 5.4 Other Differences among Versions .... +334 5.5 ID BYt€S cece cece ccc cree cece cece rece eee ec cece raeseeee es ddD 6. Notes for MSX Software DeveloperS ....ceeeeececececeeeeee e336 PART A MSX HARDWARE SPECIFICATIONS MSX HARDWARE SPECIFICATIONS 1. Hardware Specifications 1.1 MSX Standard o CPU 280A compatible oO MEMORY ROM: 32K bytes (MSX system software) RAM: 16K bytes (Minimum) © SCREEN DISPLAY Text display: 32 x 24 (See Section 2.4) Graphics: 256 x 192 Colors: 16 o CASSETTE TAPE FSK format, 1200/2400 Baud o SOUND 8 Octaves, 3 Voices © KEYBOARD VERSIONS Alphanumerics, Japanese, Graphics (Japanese) Alphanumerics, European, Graphics (International) © FLOPPY DISK DRIVES Hardware depends on the manufacturer Disk format MS-DOS-compatible © PRINTER * 8 bit parallel © ROM CARTRIDGE AND I/O BUS Software cartridge and expansion BUS slots o JOYSTICKS * 1 or 2 © CHINESE CHARACTERS * At manufacturer's disgression * The items with asterisks may not be provided in the basic system configuration. MSX HARDWARE SPECIFICATIONS 1.2 MSX System Configuration o MINIMUM CONFIGURATION SOUND OUTPUT VIDEO OUTPUT CARTRIDGE SLOT x 1 ZB0A ROM 32K PSG RAM 16K VDP PPI KEYBOARD JOYSTICK CASSETTE x1 © SOFTWARE SUPPORT LIMIT SOUND OUTPUT VIDEO PRINTER CARTRIDGE OUTPUT OUTPUT SLOTS x 15 | 280A ROM 32K PSG PPI VDP RAM 32K for BASIC 64K for DOS KEYBOARD ! JOYSTICK CASSETTE x 2 MSX HARDWARE SPECIFICATIONS 1.3. Main Unit 1.3.1 LSIs o CPU Z80A compatible Clock 3.579545MHz (NTSC Color sub-carrier frequency) 1 WAIT in Ml CYCLE o VDP TI TMS-9918A compatible o PSG GI AY-3-8910 compatible oO PPI Intel i-8255 compatible 1.3.2 Memory o ROM MSX-BASIC, 32K bytes o RAM Minimum 16K bytes NOTE Since the minimum sy stem configuration contains four slots, the memory area may be expanded up to 256K bytes. Each slot can be further expanded to have four slots, for a total of 16 slots. Thus the maximum memory space is 1 megabyte. The BASIC ROM interpreter occupies addresses 0000 to 7FFF, and the RAM addresses Start at FFFF and grows down- ward on the memory map. See the memory map in Section 1.7 for details. MSX HARDWARE SPECIFICATIONS 1.3.3 Interrupts o NMI Not used. MSX ROM only provides a RAM hook. o «INT Interrupts are accepted from the VDP and the cartridges. The interrupt mode is 1. (Branch to 38H} The MSX system software uses an interrupt from the VDP. The interrupt intervals are 60 Hz in the NTSC version and 50 Hz in the PAL/ SECAM version. VDP Z80 NOTE It is not possible to support NMI under MSX-DOS because the address 66H (an entry vector for the NMI) is used by the MSX-DOS FCB data. " MSX HARDWARE SPECIFICATIONS 1.3.4 Screen o LSI TI TMS9918A Compatible o Character set Alphanumerics + Japanese (European) + Graphics 256 patterns, 8x8 dots o Color 16 colors Oo Sprites 32 sprites, with a maximum of four sprites on the same horizontal line. o Display modes proce renn ne --- er y------ ----- peewee Hn yore S eatetateeated . ( | | | NO! ISPRITEINO. OF] | MODE | RES. | SIZE 1! * [COLOR IAVAIL. !CHARS. fo------Saaiatatatetetatetee t------- tennn-- te---t------ t------ +------ 4 | ! LSI | 256 ! I ! | | | IGraphicl Spec. | x192 1 i] | 16 1 | 32x24] | bean enn --te------ 4.8 x 8] 256lcolors! Yes) r+-=--- 4 | I ISuggestedi 240 | | | | | | t ! value | x192 1 | | I t 29x24! f------- +--------- tennH--- te---~-5atutatetmeetataned teen -- Sa 4 | ! LSI | 256 | | i | ! 1 IGraphicl Spec. | x192 | i] 1 16 1 | 32x241 | beeen nnn5cateteetenanel 4+ 8 x 8! 768icolorsi Yes +-----~ 4 I II ISuggested! 240 | i] | 1 I | 1 | value | x192 | | i | 29x24] te------Saatetaatetetaatel tennnnn- te-~--- tenn tenn -- focc-o- teno--- 4 | | LSt | 64 | | | | | | {| Multi-| Spec. | x48blki | | 16 1 | 32x24] | color +--------~ +------ + 4x 41 - |colorsl Yes +------ + | ISuggestedl 64 |/BlockI | ! | ! | value | x40bikl I ! | | 29x24! feanneee t--------- te------ te----- t--- +--+ - 4------S cateteeteted 4 1 | LSI | 256 | | I | | | { | Spec. | x192 | | | 2 ! | 40x24] | Text t--------- te------- 4.8 x 61 256lout of! No t------4 i !Suggestedi 240 I | ! 16 1 | i | | value | x193 | | Icolors| | 39x24] ne te --- ae dean waa denned denen ee 4+ --- He 4 * Number of patterns Suggested : The eight pixels from the left and right of the values horizontal line are not used by the software. 12 MSX HARDWARE SPECIFICATIONS 1.3.5 Keyboard o Layout Alphanumerics oe ASCII standard Japanese syllables oe JIS standard syllable layout European Oe International versions Graphic Characters we Depending on international version (Selected by jumper connection) o Scanning Software scanning driven by VDP interrupt o Number of keys 72 See section 5.2.2/5.2.3 for details. o Matrix diagram x7__|xe_|x5_}xa_ [x3 [x2 | x1 [xo PBL “1 7/6/5}4/3]2]/1]0 >|Cl@]* 9/8 v1 PBS PB4 ; al- PB6 PB7 Zeal al* |], j . 2 , : ° By; 1tHIGl|Fle| oie Pco a OR rca} PC2 cte 23 2——'] I R/]Q|P o|N|Mi[L|K PC3 D3 5 p>——*) 7 X|W] Vi UTTIS 6 A os Y6) 3 | F2 | F1 |KANA| cap iGrapH! crRL | SHIFT 9b {x%) 10 LY? trerurn|sevect] 8s |stop| tas | esc | 5 | Fa YS} = | 2 | @ | © | vet | ins |Home|sPace yg y10 x* Underscore character. ** Code Lock key in international versions. 13 MSX HARDWARE SPECIFICATIONS 1.3.6 Sound o LSI GI AY-3-8910 Compatible.Clock 1.7897725 MHz (1/2 CPU clock) o OCTAVES 8 Octaves (3 Voices) o SOUND EFFECTS Available o SOFTWARE SOUND OUTPUT 1 bit from output port o OUTPUT LEVEL -5dbm (Providing the system has an output connector) o CONNECTOR RCA 2 pins (Providing the system has an output connector) 14 MSX HARDWARE SPECIFICATIONS 1.4 Interfaces 1.4.1 Cassette Interface o INPUT From the earphone terminal of the tape recorder o OUTPUT To the microphone terminal of the tape recorder o SYNCHRONIZATION Asynchronous, software-controlled oO BAUD RATES 1200 baud (1200Hz - 1 wave "0", 2400Hz - 2 waves "1") (Default) 2400 baud (2400Hz - 1 wave "0", 4800Hz - 2 waves "1"), software-selected (The tape recorder to be used may have to be speci- fied by the manufacturer when using 2400 baud) © MODULATION FSK (Frequency Shift Keying), software-controlled © DEMODULATION Sof tware-controlled. The system software automatically detects the baud rate upon receiving the data. © MOTOR CONTROL Available o CONNECTOR DIN 45326 (8 pins) 1 MSX HARDWARE SPECIFICATIONS o TABLE OF SIGNAL PINS preowee i pe e+ e y PIN SIGNAL | | No. NAME IDIRECTION| PIN CONNECTION fen pe pe nnn pn nnn nnn nn nnn nnd Noe ne chi a oe re ce en ee eee nnd 16 MSX HARDWARE SPECIFICATIONS o SAVE Level The constants in the SAVE circuit should be adjusted so as to perform the output level as follows: Output level -45 dBm + 5 dBm (0 dBm = 0.775 V) The output should be 22 mVp-p ~ 7 mVp-p at 1200 Hz input signal. | 22MVe_p~7MWV pe o Sample Circuit for SAVE Ic it My [ Ay t Output to CMT 1uF 4.7kQ 4.7kQ Standard Value ( *)} 0.022.F 100Q o Frequency Characteristics 6dB /oct r 6aB /oct H i 1 1 H H 1 t i) ! ! 1 I i ‘ ' 1 1 MIN16Hz MAX200Hz 3kHz Lower Cutoff Frequency (*) Higher Cutoff Frequency * Note that the lower cutoff capacitor is to protect the IC of MSX. Cassette tape recorders themselves will not be harmed even if it is not there. The capacitance may be in the range 0.1 ~ 2.2uF. Adjust the capacitor to limit the lower cutoff frequency in the range 16 ~ 200Hz, if the output inpedance of the IC is too high. W MSX HARDWARE SPECIFICATIONS 1.4.2 Floppy Disk Interface ° The Floppy Disk Interface contains 16K bytes of ROM beginning at 4000H that includes the following modules: * MSX-DOS KERNEL * MSX DISK BASIC * PHYSICAL DISK I/O DRIVER (Supplied by manufacturer) The hardware interface is not specified. The physical disk 1/0 driver supplied by the manufacturer should resolve the hardware differences. Ideally, the mechanism in the disk drive should detect that the drive door has been opened. This reduces the number of disk accesses required to check if the system disk been replaced. ie] Floppy disk format: MS-DOS compatible 8-inch Single~density 128 Bytes/Sector 8-inch Double-density 1024 Bytes/Sector 5.25-inch Double-density 512 Bytes/Sector 3.5-inch CFD 512 Bytes/Sector 3-inch CFD $12 Bytes/Sector 18 MSX HARDWARE SPECIFICATIONS 1.4.3 Printer Interface oO SPECIFICATIONS 8 bit parallel, handshakes by BUSY and STROBE o LEVEL TTL © CHARACTER CODES Same as the MSX display codes © CONNECTOR 14-pin AMP compatible o LIST OF PINS preennna ne7a ------ Tree nnn ane == = 4 | | SIGNAL | ! | | PIN NO. | NAME |I/ol PIN CONNECTION | ha-------- te------- trend -- ++ ------- ------ = +--+ 4 \ 1 | Pste i101 ----+--- te---~--- +---4 i 2 | Popo lol peew - ee fee +-~-+1 | 3 | PDBl | 0! Lcesteetetestettetads etait +---4 | 4 | Ppp2 !ot pe---~~---4----~--~4---4 i 5 | PpB3 101 penalotahetenhaaletetetetetetet tate | | 6 | PpB4 10} en aa fee] 7/}6/5)/4)/3/]2)]1 | 7 | PDB5S 19 MSX HARDWARE SPECIFICATIONS 1.4.4 RS-232C Interface o LSI COMPONENTS i-8251 Communications Interface i-8253 Programmable Interval Timer At least 4K bytes of ROM is required for software support. o PORT ADDRESSES 80H R/W 8251 Data Port 81H R/W 8251 Command/Status Port 82H R Status Sense Port for CTS, Timer/Counter 2, RI, and CD 82H Ww Interrupt Mask Register 83H Reserved 84H R/W 8253 Counter 0 85H R/W 8253 Counter 1 86H R/W 8253 Counter 2 87H WwW 8253 Mode Register * The port at address 83H is reserved for use by the manufacturer. 20 MSX HARDWARE SPECIFICATIONS o USING THE PORT AT ADDRESS 82H 82H Read: Get System Status peseen---|sstacuheiaiatetateteteieteneteneteatatetenenamtetetaetetateateetetatetetet 4 | Data | | | Bit | Description ( fe-nene-- 4---------~-~---- +--+ = -- == == -- ===4 t D7 i CTS (Clear To Send) | I I 0: CTS Asserted J ! | 1: CTS Negated | l D6 I Timer/Counter Output-2 from i8253 | | D5 | --5 | | D4 | I l | D3 | | Reserved | | D2 | wes | ! D1 | + RI (Ring Indicator) i | | O: RI Asserted l I i 1: RI Negated I | DO | + CD (Carrier Detect) | ! | 0: CD Asserted | | | CD Negated | Leena too -- 3+ a NOTE: The signals with the plus (+) sign are optional. If only one signal is chosen, it must be 'CD'. NOTE The CTS signal is sensed through the port instead of through the 8251 because of a problem in the CTS logic in some versions of the 8251. Software handling is thus made possible. MSX HARDWARE SPECIFICATIONS 82H Writ es Interrupt Mask Register 4 I { I l | | Reserved i i --4 | 1 + Timer Interrupt from i8253 channel-2 | | 1: Mask Interrupt (Initial value) | I 0: Enable Interrupt ! | + Syne character detect/Break detect | | 1: Mask Interrupt (Initial value) ! ! 0: Enable Interrupt 1 D1 | + Transmit Data Ready (Tx Ready) | | 1: Mask Interrupt (Initial value) ' | 0: Enable Interrupt ! DO | Receive Data Ready (Rx Ready) ! | 1: Mask Interrupt (Initial value) I | 0: Enable Interrupt | a NOTE: The signals above with the plus (+) sign are optional. The minimum requirement for the interrupt signal is thus Rx Ready. 22 MSX HARDWARE SPECIFICATIONS o USING THE 8253 TO GENERATE BAUD RATE CLOCK FOR THE 8251 A. CRYSTAL FREQUENCY The crystal frequency is 1.8432 MHz. Po ern mn nnPr rn nnn nn nnn nnn nn 7 | Baud rate (Baud) | Scale Factor and Error (x16) |! }e----------------- tennn-~------------------------ 4 | 50 1 2304 ! ( 715 | 1536 | | 110 i] 1047) 110.0287 +0.3% ! | 150 1 768 ( | 300 { 384 | | 600 ! 192 I | 1200 | 96 | | 1800 | 64 | I 2000 | 58 1986.2 ~0.7% I | 2400 ! 48 | 1 3600 | 32 | | 4800 | 24 ! I! 7200 | 16 | ! 9600 I 12 | | 19200 | 6 ! 4 B. USING THE COUNTER CHANNEL CHO: Rx Baud rate clock CH1l: Tx Baud rate clock CH2: Used by application (Interrupt generated optionally) 23 MSX HARDWARE SPECIFICATIONS o PINS OF DB25 CONNECTOR r prone Eaiantataentatetmtatetetateteedmates 2 I | Pin I Signal | f------- 4 etetaeteteted +------------+------- 4 | 1 | Frame Ground | 1 14 1 | | 2 | Transmit Data | [15 | | | 3 | Receive Data i] | 16 1 I | 4 | Request To Send | 1 17 | I | 5 | Clear To Send 1 ! 18 | t i] 6 | Data Set Ready | 1 49 | | | 7 | Signal Ground | | 20 | Data Terminal Ready| ! 8 | Carrier Detect | ! 21 | ! I 9 | | | 22 | Ring Indicator | | 10 | i | 23 | I | 11 | | | 24 | ! | 12 | | } 25 | | 1 13 | | t 1 | bee dee enn a benee ae ee 4 24 MSX HARDWARE SPECIFICATIONS 1.4.5 Peripheral I/O Port(s) (1 or 2)* o LSI AY-3-8910 compatible ° I/0 Input 4 bits, Output 1 bit, Bidirectional 2 bits per port o LOGIC Active high o LEVEL TTL o CONNECTOR 9-pin AMP compatible o LIST OF PINS r | PIN | SIGNAL | | I | NO. | NAME IDIRECTION | PIN CONNECTION | t-----4-------- tonne $e ----------- $= + eee 4 | | | ' ! {( 2 | FWD | Input | | beeen nfeennnnee +-------- 4 | | ! ! ! | { 2 | BACK ( Input i ! caieieiaied putetamenenetetan $--------- 4 | | | I | ! ( 3 | LEPr | Input | ! breee-f------ te-------- 4 ! | | | | 1 { 4 | RIGHT | Input I I bennett OOM OMOMEC) | I | 5 | +5V ! beeen 4-------- ® @ ©) ! | b 6 (TRG 1 | Output | ! ! ! | ! ! | 1 5 ! | | * Current capacity: 5QmA each 25 MSX HARDWARE SPECI FICATIONS o Circuit Diagram , +5V AY3-8910) 74LS157 3 33 zJ& 3 10A0 yo1A fe) OONATARWN HE 1OA1 2Y 2A fe) 1OA2 3Y 3A ° 10A3 ay 4A fe) 18 Llo 2B fe) s 3B fe) Ss G 4B O 7 ie) or +5V +N 4 T 1e) OMNATRWNE 4 e) 74LS157 fe) (2) 1A — 0 10A4 1y 2A te) (OAS 2v 1B ie) s 28 fe) Ae7407x4/6 Zr ° 10B0 > +5V 10B1 —> 10B2 Pe $ 3 10B3 t>— 10B4 10B5 10B6 All resistors are 10k ohm typically. 26 MSX HARDWARE SPECIFICATIONS 1.4.6 Joysticks ° There are two types of joysticks. Joystick Type A has one trigger button, or if there is more than one trigger button, the software cannot distinguish between them. Joystick Type B has two independent trigger buttons. The joysticks produced from now on should show which type they are and software that needs to have Type B should say so on the package. o Circuit Diagram AMP OPIN FWD 1 O-——O BACK 20——O LEFT 3 RIGHT 40——0 ~o—+4 TRG A 6 TRG B 7 O——O Option as described above. 8 __ OA 27 MSX HARDWARE SPECIFICATIONS 1.4.7 Paddles o A trigger pulse is sent to the 8 pin of the peripheral I/O port every time the PDL function is called. The paddle circuit, triggers the monostable multivibrator with this pulse. A pulse of the length corresponding to the level of the volume is returned to the port. A maximum of 6 channels of paddles can be attached to each 1/0 port. Paddle timing diagram FWD1 r] TA ol bo r=10xs to 3ms Circuit diagram (for 1 channel) vec 150K QVR 5 O—— ot 8 0 [>o A 9} ——012,3,46,7) B 9 CLR LS 123 or EQUIV. NOTE: The volume (or the capacitance) should be adjustable as to justify the function of the paddle. 28 MSX HARDWARE SPECIFICATIONS 1.4.8 Connectors | f 1 | | 1. Video output and | DIN 5-Pin Connector *, or ! composite video ! RCA 2-Pin Connector | | | 2. RF modulated signal| RCA 2-Pin Connector | | | Audio | RCA 2-Pin Connector | beeen eee ee een te ee e e4 MSX HARDWARE SPECIFICATIONS 1.4.9 Slots °o CONCEPT OF SLOTS For computers having 64K bytes of memory, the concepts of slots and memory banking are nearly identical. The CPU can directly choose the cartridge by its slot number. The slot concept originated from a desire to support the maxi- mum amount of software. Using the slots, the software can be run, regardless of the number of physical slots available to the computer. ADVANTAGES OF SLOT STRUCTURE In a common bus structure, when there is an even number of memory banks, the device select signal connected to the bus cannot distinguish between the different devices by using the same memory area. If this were to occur, the system would not only be unusable, but the hardware would quickly deteriorate. By using the slot select signal to choose the memory devices, the above problem is avoided, and programs that handle two or more devices having the same memory area are made possible. This is a favorable point, considering the system's flexibili- ty and expandability. Circuit diagram B255 7ALS153 7ALST39 STSt paot SS _lico iy A pai} —SS0H__Jaco vif SITsL1 pag}—SS1L_tic) ay B pa3}—CS14_ _loc1 yo SLTSL2 pag CS2l__lica a pas|—CS2H__loca y3{o>——- SITSI3 pag}—SS3L__licg __ pa7}-SS3H__toc3 Ss 055 Al4 A MREQ Chip Select Al15 B _ Te RFSH 2G RESET MSX HARDWARE SPECIFICATIONS 1.5 Cartridges 1.5.1 Physical Cartridge Specifications o Physical dimension of the standard cartridge ( ~ INSERT DIRECTION (FRONT) e g PS CO rho | | | Li b~>-~~-~~~-~-~-~~~ 2 2 109 | r LA ] ° oO [ 1 Physical dimension of the expanded cartridge | 109, 75 3 MSX HARDWARE SPECIFICATIONS 1.5.2 Cartridge Bus o LIST OF SIGNAL PINS ne) ne) cs12 1 o SLTSL Io | Reserved # | - RFSH to f WAITS 1 oI INTS ) or ot MI ane) BUSDIR a | | o MERO to t WR lo RD Io | RESET ne) Reserved # | - | AQ n°) Al5 iol All lo AlO lo l AT ae) A6 | o t Al2 ne) A8& [ot Al4 ae) Al3 { o | Al { oO AO !o4 A3 ne) A2 lol AS to a4 to lt D1 | 1/0 DO 1 I/o | D3 | 1/0 D2 1 I/o 1 DS | 1/0 D4 | I/O | D7 | 1/0 Dé 1 I/o | GND I o- CLOCK 1 ot GND I o- sw1 1-4 +5V 1 = sw2 I o- | +5V lo- +12V t - | SOUNDIN lor ~12V Io- 4 wee e ee deen * The Input/Output directions are relative to the main unit. # Do not use the Reserved PINs. % OPEN COLLECTOR output 32 MSX HARDWARE SPECIFICATIONS o LIST OF SIGNAL PINS ! 1 | csl | ROM 4000 to 7FFF, selected signal | | 2 I Ccs2 1 ROM 8000 to BFFF, selected signal | | 3 | €si2 | ROM 4000 to BFFF, selected signal 1 | I I (for 256K ROM) | | 4 | SLTSL | Slot select signal | | 5 | Reserved | Reserved for future expansion. Do | | | | not use this pin. | 6 | RFSH | Refresh signal I | 7 | WAIT | Wait signal to CPU | | 8 | INT | Interrupt request signal | | 9 | M1 | Fetch cycle signal of CPU | 10 | BUSDIR | This signal controls the direction | | | of the external data bus buffer when | I | | the cartridge is selected. It ! | | is LOW when the data is sent by the | | | | cartridge. | ! 11 | TORQ | I/O request signal | | 12 | MERQ | Memory request signal | | 13 | WR | Write signal | 1 14 | RD | Read signal ! ee) | RESET | System reset signal | ( 16 | Reserved | Reserved for future expansion. Do i ! | not use this pin. | 117732 | AO~AL5 | Address bus | | 33740 | DO~D7 | Data bus | 1 41 | GND | Ground | 1 42 | CLOCK | CPU clock, 3.579 MHz t 1 43 | GND | Ground | | 44, 46 | SWl, SW2 | Detect Insert/Remove for protection | | 45, 47 | +5V | +5V power supply t | 48 | +12V | 4+12V power supply i | 49 | SOUNDIN | Sound input (-5 dbm) ! | 50 | -12V | -12V power supply | Wee donee eee 4 --- +8 a NOTE The CS signals imply a memory request anda read signal. Thus they cannot be used as chip select for writable devices such as RAMs. MSX HARDWARE SPECIFICATIONS 1.5.3 Cartridge Bus Connection Conditions o FAN-IN, FAN-OUT (LS-TTL load) Data and Address bus Main unit | Cartridge | Below 2 | Above 5 (Pan-in) 1 {Fan-out) | Above slot 1 | Below 1 (Fan-out) { (Pan-in) © CONTROL SIGNALS Above slot 2 | Below 2 —_— | (Fan-out) | (fan-in) o VOLTAGE LEVEL TTL level 1.5.4 Cartridge Power Capacity +5V 300 mA/slot +12V 50 mA -12V 50 mA 34 MSX HARDWARE SPECIFICATIONS 1.5.5 Sample Circuit Diagram of Expanded Slot Select Signal Expanded slot adapter BUSDIR: BUSDIR from other expanded slots DATA BUS —_— Do~Di USDIR po ° TM i) | i qo TORO 7 ADDRESS BUS AAs VO adds address O-) Decoder arar SLTSL SLTSL| D—+O Expanded Te 1/0 Cartri eee dge strst} SUTSt generator [p>—~ To other expanded slots SLTSL (access FFFF)-RDto -SLTSEL (access to FFFF)-WR-SLTSEL 8 74l$ 74LS 74S 273 153 139 CLK’ 1y A Yoo DATA BUS—f 2 ty 2y B Yip Y2p-——~ pic G Y3p— aR 26 — RESET ea Aw As SLTSL MSX HARDWARE SPECIFICATIONS 1.6 Notes for System Expansion 1.6 «1 RAM Expansion ° Since MSX-BASIC needs a contiguous RAM area from 8000 to FFFF, the additional RAM should be added to the existing RAM so as to be contiguous. ° Since the MSX-BASIC software requires only RAM from 8000 to FFFF, RAM installed from 0000 to 7FFF cannot be used by it. 1.6 +2 Slot Expansion 0 When slots are expanded, the expanded slots must be expanded from a primary slot. Primary slots are those slots managed by the slot select register provided in port A of the 8255. Thus, to select an expansion slot, first select the primary slot to which the expansion slot is connected, then select the desired slot. ° The slots directly attached to the MSX computer itself must be primary slots. Because there are significant differences between the primary and secondary slots, there must be a clear indication of which kind of slot is placed in an expansion adapter. ° The location of the slot select register for the additional slots is address FFFF of the primary slot. To make it possible to differentiate the register from ordinary RAM, take the complement of the output of the register. That is, when the register is read, the data is the complement of the value of the register. ° A maximum of four cartridges can be connected to the cartridge bus. Therefore, buffers are necessary if the system is to Support more than five slots. The BUSDIR signal controls the direction of those buffers. Devices placed in expansion slots that send signals to the CPU must also send the BUSDIR signal to change the direction of the expansion slots to the CPU. However, for memory accesses, it is possible to determine the direction of the bus by using the slot select signal sent to the primary slot, the memory request signal, and the read/ write signal. The direction of the buffer should thus be controlled around the buffer circuit; cartridges containing only ROM or RAM thus do not have to manage the BUSDIR signal, and expansion RAM cartridges do not have to be expensive. Cartridges containing devices to send signals to the CPU (those devices responding to the INP instruction or supplying an address in response to mode 2 interrupts) must force BUSDIR to the 'L' level when sending data to CPU. MSX HARDWARE SPECIFICATIONS 1.6.3 I/O Expansion ° In 2-80 based system, it is common to place I/0 devices in the I/O address space. Since the MSX system was designed to be flexible and expandable, it is possible to add I/0 devices using cartridges that share the same address space. If this is the case, those devices will not be able to be accessed properly. To avoid the above situation, the I/O devices should be placed in the memory area because they will be managed by slot select logic and the memory cannot be accessed simultaneously when placed in different slots, since devices placed in the memory area cannot be accessed by software running in different slots. General devices such as the VDP must therefore be placed in the I/O address space. Note also that in some cases it is more economical to use the I/O address space, because only eight bits of address information have to be decoded. The MSX system specifications define the system device I/0 address space to be addresses from 40 to FF. The addresses below 3F are left free. While other devices may use this address space, other manufacturers may use the same addresses for other purposes. Thus, we recommend that memory addresses be used instead of the I/O area. In later MSX versions it is possible that standard devices will use the unassigned (reserved) addresses. 37 MSX HARDWARE SPECIFICATIONS 1.7 Address Maps 1.7.1 Memory Map o The following is an example memory map. PFFF ------4 pooaoe4 oe 4 oe oe . ! | | | 1 i i | | | [3 1 | RAM | | | | I ( 1 | | | | ! | | t | | C000 +-----4 Fema a4 beennn4 tema =4 tennne 4 | | | | | | | | 1 | | I 1 | | 1 RAM | | | ! 1 | I I | | I | i 8000 t-----4 beeen 4 to---~4 feo 4 t----~ q | | | t | i] IDISK | IBASICI oe on i 1 | | ISoft-| lExpan| | | | 32K | | | | warel | sionl 4000 +----~4 t 4 t-----4 te---- 4 beeen 4 1 | | ROM | | | | 1 1 | 1 o | | | I I I i ! | | | | 1 | | | ! | | 0000 +----~+ ey beeen ed te 4 Le 4 CPU 0 1 2* 3* Memory System Cartridge area slot slot MSX BASIC uses the largest contiguous available RAM area installed from 8000 to FFFF for its system working RAM area. This RAM may be placed in any slot, including the expansion slots. The slot select register, port A of the 8255, maps the physical memory space to the logical CPU memory space in 16K-byte units (pages). For example, the following value in the slot select register allocates pages 0 and 1 from slot 0, page 2 from slot 2, and page 3 from slot 0. (MSB) 7 6 54 32 10 (LSB) | | | | +-~ Allocate slot 0 for page WNHHO \atataietetetened Allocate slot 0 for page ane eeetetetetateed Allocate slot 2 for page fem manne nnn nn nnn nnn Allocate slot 0 for page The physical memory is always allocated to the same memory page in the CPU memory space. It is not possible to allocate it to a different page, as in allocating page 3 of slot 3 to page 0 of the CPU memory space. MSX HARDWARE SPECIFICATIONS o The minimum system must have two slots, one for the system, and the other for the cartridge. NOTE The meaning of "slot" does not imply that it must have a car- tridge connector; however, the cartridge slot must have the cartridge connector. MSX HARDWARE SPECIFICATIONS 1.7.2 I/O Address Map F7 FO EO | ROM for Chinese | | Characters | | Light Pen Interface | BS } ene 4 B5 -~----~------ eee cenn-n--- 4 | Calendar Clock | B4 }-~-----~---------~------ 4 | external Memory ! BO t-~-----~----- ~~----------- 4 | PPI (8255) l Ag +~-------- ~ee-----~-------- 4 | PSG (AY-3-8910) | AQ ----- | vDP (991 8a) | 98 }----~-----~---------~---- 4 | Printer Interface t 90 }--+---~-----~------------- 4 | | 88 }-----------------~-------- 4 | RS-232C Interface | 80 -----------~~----~-------- 4 | | | Reserved 40 -------~------~---------- 4 | I | Unspecified i I 00 wH----------~----~-- 4 40 MSX HARDWARE SPECIFICATIONS 1.7.3. Printer Port 908 RR Busy state: Bit 1 90H Ww Strobe output: Bit 0 91H W Print data 1.7.4 VDP Port 98H R/W Video RAM data 99H R/W Command and status register 1.7.5 PSG Port AOH W Address latch AlH W Data write A2H R Data read 1.7.6 PPI Port A8H R/W Port A ASH R/W Port B AAH R/W Port C ABH R/W Mode register 1.7.7 External Memory (Sony) BOH thruogh B3H 1.7.8 Light Pen (Sanyo) B8H through BBE a MSX HARDWARE SPECIFICATIONS 1.7.9 Audio/Video Control F7H W BIT4 - AV Control L- W Ww BITS - Ym Control L- WV W BIT6 - Ys Control L - Super W BIT7 - Video select L- 1.7.10 Notes on I/O Address Assignments ° I/O addresses 40-FF are assigned for system use. The unused empty area is also reserved for system use. Although I/O addresses are defined above, the software must hot access those devices directly using the above ports. All I/O accesses must be done using BIOS calls, in order to make the software independent of hardware differences. MSX manufacturers may change some of the hardware from the Standard MSX system and maintain software compatibility by rewriting BIOS. The hardware differences would thus be trans- parent to the software. The only exception to the above is the access to the VDP. Locations 6 and 7 of the MSX system ROM contains the Read and Write addresses of the VDP register. Software that must access the VDP quickly may access the VDP directly by using the addresses stored in ROM. Addresses 00 to 3F are free. Different devices using the same address must not be accessed simultaneously. In general, the I/O devices that are not defined here should be placed in the memory space as memory-mapped I/O. See section 1.6.3 for fur- ther details. The FDC may be placed in the I/O area; however, it must have a mechanism to disable it, and it must be enabled only if the system does accesses to the FDC. This makes it possible for the system to have more than one FDC interface for handling different media types. 42 MSX HARDWARE SPECIFICATIONS 1.7.11 8255 (PPI) Bit Assignments ee e e + I SIGNAL | IPORTIBITII/Ol NAME DESCRIPTION fens te nn pone pn -- -- - -n ee ! -# Ola o ODpo VOI0VDOHWAIHN tiey) |«Muos1}]uSo1}woowtoJv WtaWoWtmw |aoatwo ypotow O|@o!otia)4o@$ e| n1a&gJoe©1oaload ! o 1f <7) I 4 ! ! | a) en J~ 41 °m 1 o i 8 o 1 6 1 o 4 1 6|o DtoyO 1 Syo ! Keyboard return signal fend Uo beo----4$--------- +--+ --------------- + | {4 | fT ICASON | Cassette control signal (L=ON) fone een p------ ann -~---------- ---- + ------- 4 P ! ICASW | Cassette write signal ! beoa4 Uo ben -n-- +--+ = $$ $5 ee en | ! 6 | fT [CAPS | CAPS lamp signal (L=ON) boo-4 peo----4+--~-+--------------- +--+ = = === 4 | IsOUND | Software-controlled sound output MSX HARDWARE SPECIFICATIONS 1.7.12 PSG Bit Assignments poneqo one nnn === qo one -------- =1 | PORTI BIT | I/O | CONNECTOR PIN NO. 1 NOTES te---- +----- fern nn tenn ------------ 4----------------- 4 I At o | | J3-PIN 1 #1=+/ FWDL | | | | J4-PIN 1 * #2 «1 FWD2 | | 1 lt I st J3-PIN 2 #161 BACK1 | | | | J4-PIN 2 * #25 BACK2 i 1 2 1 N {I J3+PIN 3 #14 LEFT1 | ! | | J4-PIN 3 * #2 «(| LEFT2 1 | } 3 $ P | J3-PIN 4 #11 RIGHT1 t | | | | J4-PIN 4 * #2 | RIGHT2 ! { 4 | U Ll J3-PIN 6 #11 TRGAL | | | | | J4-PIN 6 * #2 «| TRGA2 | | | 5 | &T | J3+PIN 7 #1 ~/ TRGB1 | 1 | | | J4-PIN 7 * #2 1 TRGB2 i i H 6 1 | KEY LAYOUT Select #4 | Japanese I | | | | version only ! | 1 7 4 | CSAR | | | i 1 | (Cassette tape READ) | | teetaS alsteslestanh sutetentatet aaletetetetatatatatetatatetatteataaatated denne nn nnn 4 i ptol | J3-PIN 6 #3 I-- | l 1 2 1 0 | J3-PIN 7 #31 | "H" Level | | 1 2 1 vu | J4-PIN 6 * #3 1 | | ! 3 | @ | g4-PIN7 * #3 ~«I-- | 1 1 4 | P | g3-PIN 8 | | ( i 5 | U | J4-PIN 8 * i | ! { 6 | © | PORT A INPUT SELECT | Selects J3 or J41 1 1 7 4 | KLAMP I Japanese i i | | | (KANA LAMP L=ON) | version only | — ee he ne me a ae a a #1 Available if bit 6 of port B is LOW and is used by JOYSTICK1 #2 Available if bit 6 of port B is HIGH and is used by JOYSTICK2 #3 Set these pins to "H" when using them as an input port. Connect an open collector buffer to the output. #4 JIS layout - "H", syllable layout - "L" PIN 5: +5V PIN 9: GND o On the minimum MSX system, there is no J4 connector. 44 PART B MSX SYSTEM SOFTWARE MSX BASIC REFERENCE GUIDE 2. Language Specifications 2.1 MSX-BASIC Reference Guide MSX-BASIC is an extended version of Microsoft Standard BASIC Version 4.5, and includes support for graphics, music, and various peripherals attached to MSX Personal Computers. Generally, MSX- BASIC is designed to follow GW-BASIC, which is one of the standard BASICs running on 16-bit computers. During the creation of MSX- BASIC, a major effort was made to make the system as flexible and expandable as possible. MSX-BASIC also features a BCD-arithmetic function with a double- precision accuracy of up to 14 digits. Arithmetic operations thus do not generate rounding errors that tend to confuse new program- mers. In addition, all trancendental functions are calculated with 14-digit accuracy. 16-bit, signed, integers are also availa- ble for faster execution. 2.1.1 Modes of Operation When MSX-BASIC is initialized, it displays the "OK" prompt. "Ok" indicates MSX-BASIC is at command level; that is, it is ready to accept commands. At this point, MSX-BASIC may be used in either of two modes: direct mode or indirect mode. In the direct mode, MSX-BASIC statements and commands entered as they are without preceeding line numbers. They are executed imme~ diately, and the results of arithmetic and logical operations may thus be determined quickly. While these results may also be stored for later use, the instructions themselves are lost after execution. Direct mode is thus useful for debugging and for using MSX-BASIC as a "calculator" for quick computations not requiring a complete program. The indirect mode is used for entering programs. Program lines are preceded by line numbers and are stored in memory. The program stored in memory is executed by entering the RUN command. MSX BASIC REFERENCE GUIDE 2.1.2 Line Format The program lines of MSX-BASIC programs must be in the following format. Square brackets denote statements that are optional. nnnnn BASIC statement [:BASIC statement...] An MSX-BASIC program line always begins with a line number and ends with a carriage return. A logical line may contain a maximum of 255 characters. More than one BASIC statement may be placed on a logical line, but the statements must be separated by a colon. The line numbers indicate the order in which the program lines will be stored in memory, and in MSX-BASIC, they must be between 0 and 65529. They are also used as references during branching and editing. During editing, a period (.) may be used with the LIST, AUTO, and DELETE commands to refer to the current line. 2.1.3 Character Set The MSX-BASIC character set consists of alphabetic characters, numeric characters, special characters, graphic characters, and both (Japanese) hiragana and katakana characters. See section 5.2.2 for details. The alphabetic characters in MSX-BASIC are the uppercase and lowercase letters of the alphabet. The MSX~BASIC numeric characters are the digits 0 through 9. In addition, the following special characters are recognized by MSX-BASIC: Character Action Blank Equals sign or assignment symbol + Plus sign Minus sign ON HE Asterisk or multiplication symbol Slash or division symbol Up arrow or exponentiation symbol HOM HR Left parenthesis Right parenthesis Percent Number (or pound) sign Dollar sign Se Exclamation point Left bracket Right bracket Comma ee Period or decimal point 47 MSX BASIC REFERENCE GUIDE Single quotation mark (apostrophe) Semicolon HE Ay Roe te Colon Ampersand Question mark Less than Greater than Yen sign or integer division symbol (back slash in international versions) @ At sign - Underscore Deletes last character typed. Escapes Moves print position to next tab stop. Tab stops are set every eight columns. Moves to next physical line. Terminates input of a line. 2.1.4 Constants Constants are the values MSX-BASIC uses during execution. There are two types of constants: string and numeric. A string constant is a sequence of up to 255 alphanumeric characters enclosed in double quotation marks. Examples: "HELLO" "$25,000.00" “Number of Employees” Numeric constants are positive or negative numbers. MSX-BASIC numeric constants cannot contain commas. There are six types of numeric constants: 1. Integer constants Whole numbers between -32768 and 32767. Integer constants do not contain decimal points. 2. Fixed-point Positive or negative real numbers, i.e., constants numbers that contain decimal points. 3. Floating-point Positive or negative numbers represented constants in 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 letter E and an optionally signed integer (the exponent). The allowable range for floating-point constants is 10E-64 to 10E+63. 48 MSX BASIC REFERENCE GUIDE Examples: 235.988E-7 = .0000235988 2359E6 =2359000000 (Double-precision floating-point constants are denoted by the letter D instead of E.) 4. Hex constants Hexadecimal numbers, denoted by the prefix &H. Examples: &H76 &H3 2F 5. Octal constants Octal numbers, denoted by the prefix 60. Examples: &03 47 &01234 6. Binary constants Binary numbers, denoted by the prefix &B. Examples: &B01110110 &B11100111 o Single- And Double~Precision Numeric Constants Numeric constants may be either single-precision or double- precision numbers. Single-precision numeric constants are stored with 6 digits of precision, and are printed with up to 6 digits of precision. Double~precision numeric constants are stored with 14 digits of precision and printed with upto 14 digits. Double- precision is the default for constants in MSX-BASIC. A single-precision constant is any numeric constant that has one of the following characteristics: 1. Exponential form using E. 2. A trailing exclamation point (!). Examples: -1.09E-06 22.5! A double-precision constant is any numeric constant that has one of these characteristics: 49 MSX BASIC REFERENCE GUIDE 1. Any digits of number without any exponential or type specifier. 2. Exponential form using D. 3. A trailing number sign (#). Examples: 3489 345692811 -1.09432D-06 3489 .0# 7654321.1234 2.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. © Variable Names And Declaration Characters MSX-BASIC variable names may be of any length. Up to 2 characters are significant. Variable names can contain letters and numbers; however, the first character must be a letter. Special type declaration characters are also allowed--see the discussion below. A variable name may not be a reserved word and may not contain embedded reserved words. Reserved words include all MSX-BASIC commands, statements, function names, and operator names (See appendix for the list). If a variable begins with FN, it is assumed to be a call to a user-defined function. Variables may represent either a numeric value or a string. String variable names are written with a dollar sign ($) as the last character, for example: A$ = "SALES REPORT". The dollar sign is a variable type declaration character; that is, it "declares" that the variable will represent a string. Variable names may also inherently declare the variables to be integer, single-precision, or double-precision. The last character in these variables must be one of the following variable-type declaration characters: % Integer variable ! Single-precision variable # Double-precision variable The default type for a numeric variable name is double-precision. MSX BASIC REFERENCE GUIDE Examples of MSX-BASIC variable names: PIé Declares a double-precision value. MINIMUM! Declares a single-precision value. LIMITS Declares an integer value. Ns Declares a string value. ABC Represents a double-precision value. Variable types may also be declared within a program by using the MSX-BASIC DEFINT, DEFSTR, DEFSNG, and DEFDBL statements. For de~- tails, refer to the descriptions of these statements. o Array Variables An array variable is a group or a table of values that is organi- zed with the same variable name. Each element in an array is ref- erenced by an array variable (having an integer or an integer ex- Pression as a subscript). Names for array variables may have as Many subscripts as there are dimensions in the array. For example, v(10) would be the name of a variable in a one-dimension array, T(1,4) would be the name of a variable in a two-dimension array, and so on. MSX-BASIC supports a maximum number of 255 dimensions for an array. The maximum number of elements depends on the size of the computer's memory. o Space Requirements The following table lists the number of bytes that each variable occupies in memory. Variables: Type Bytes Integer 2 Single-Precision 4 Double-Precision 8 Arrays: Type Bytes Integer 2 per element Single-Precision 4 per element Double-Precision 8 per element Strings: 3 bytes for bookkeeping plus the length of the string. 2.1.6 Type Conversion When necessary, MSX-BASIC will convert a numeric constant from one type to another. The following rules and examples should be kept in mind. ot MSX BASIC REFERENCE GUIDE 1. If a numeric constant of one type is set to a numeric vari- able of a different type in a LET statement, the number is converted and stored as the type declared by the new varia- ble name, unless an attempt to set a string variable to a numeric variable is done. The latter case results the oc- currence of a "Type mismatch" error.) Example: 10 A%=23.42 20 PRINT A% RUN 23 During the evaluation of an expression, all operands of the arithmetic or relational operation are converted to a uni- form precision to match the most precise operand. The op- eration also results in the precision of the most precise operand. Examples: 10 D=6/71 The operation was done in double- 20 PRINT D -precision and the result, returned RUN in D, is double-precision. - 857142857142 86 10 D!=6/7 The operation was done in double- 20 PRINT D! ~precision and the result, returned RUN to D! (a single-precision variable) 857143 was rounded and printed as. single- precision. Logical operators convert their operands to integers and return integer results. Operands must be between -32768 and 32767, or an "Overflow" error occurs. When a floating-point value is converted to an integer, the fractional portion is truncated. Example: 10 C%=55.88 20 PRINT C% RUN 55 If a double-precision variable is set to a single~preci- sion value, only the first six digits of the double-preci- sion are valid. Single-precision variables support only a maximum of six digits. 52 MSX BASIC REFERENCE GUIDE Example: 10 Al=sQR(2) 20 B=Al 30 PRINT Al,B RUN 1.41421 1.41421 2.1.7 Expressions and Operators An expression may be a string or numeric constant, a variable, or a combination of constants and variables with operators which produces a single value. Operators perform mathematical or logical operations on values. MSX-BASIC operators may be divided into four categories: 1. Arithmetic 2. Relational 3. Logical 4. Functional These categories will be described in the following sections. o Arithmetic Operators Arithmetic operators in MSX~BASIC have a defined order of prece- dence. The operators are listed below in order of precedence. Operator Operation Example . Exponentiation x*y - Negation -xX *,/ Multiplication, Floating- X*Y point Division X/Y +,- Addition, Subtraction X+¥ To change the above order of evaluation of operations, use paren- theses. The operations embedded within parentheses will be evalu- ated first. Within the parentheses themselves, the above evalua- tion order is followed. o Integer Division And Modulus Arithmetic The following two additional operations, integer division and mod- ulus arithmetic, are also available in MSX-BASIC: Integer division is denoted by the yen symbol (or the backslash in international versions). The operands are truncated to integers (between -32768 and 32767) before division is done. The quotient MSX BASIC REFERENCE GUIDE is truncated to an integer. Examples: 10¥4=2 25.68¥6.99=4 Integer division follows both multiplication and floating-point division in the above order of precedence. Modulus arithmetic is denoted by the operator MOD. Modul us arithmetic yields the (integer) remainder of integer division. Example: 10.4 MOD 4=2 (10/452 with a remainder of 2) 25.68 MOD 6.99=]1 (25/6=4 with a remainder of 1) Modulus arithmetic follows integer division in the above order of precedence. © Overflow Or Division By Zero During the evaluation of an expression, if a division by zero is attempted, a "Division by zero" message is displayed, and the ex- ecution of the program is terminated. Also, if an overflow occurs during the evaluation of an expression, an "Overflow" message is displayed and the execution of the program is terminated. o Relational Operators Relational operators are used to compare two values. The result of the comparison is either "true" (-1) or "false" (0). The result can then be used to make decisions for program logic. (See the description on the "IF" statement.) The relational operators are as follows: Operator Relationship Example = Equality X=¥ <> Inequality XOY < Less than X Greater than XY <= Less than or equal to X= Greater than or equal to X>=¥ (The equals sign is also used to assign a value to a variable.) MSX BASIC REFERENCE GUIDE When both arithmetic and relational operators are used in a single expression, the arithmetic operation is done first. For example, X+¥<(T-1)/Z is true if the value of X + Y is less than the value of T-1 divided by 2. More examples: IF SIN(X)<0 GOTO 1000 IF I MOD J<>0 THEN K=K+1 © Logical Operators Logical operators test multiple relationships, bit manipulation, or Boolean operations. The logical operator returns a one-bit re- sult which is either "true" (not zero) or "false" (zero). Logical operations are performed after arithmetic and relational opera- tions in expressions. The outcome of a logical operation is de- termined as shown in Table 1. The operators are listed in their order of precedence. Table 1. Truth Table of MSX-BASIC Relational Operators NOT x NOT X 1 tt) 0 1 AND x XY X AND Y 1 1 1 1 0 0 0 1 0 0 0 0 OR x Y X OR Y 1 1 1 1 0 1 0 1 1 0 0 0 XOR x Y X XOR ¥ 1 1 0 1 0 1 0 1 1 0 0 0 EQV x Y X EQV Y 1 1 1 1 0 it) 0 1 0 0 0 1 MSX BASIC REFERENCE GUIDE IMP x Y X IMP Y 1 1 1 i 0 0 0 1 1 0 0 1 Besides using relational operators to make decisions on program flow, logical operators can connect two or more relations and re- turn true or false to be used in decisions. Examples: IF D<200 AND F<4 THEN 80 IF I>10 OR K < > <= >= Strings are compared by comparing the ASCII codes of both strings, comparing one character at a time. If all of the ASCII codes are the same, the strings are considered equal. If some of the ASCII codes are different, the string having the ASCII code with the lower code number will precede the other string. If the end of one of the strings is reached before the end of the other string is reached, the shorter string precedes the other string. During comparison, leading and trailing spaces are significant. Examples: "AA" CAB" "PILENAME"="FILENAME" "XE"D>"XETM "CL ">"cL" "kg">"KG" "SMYTH "<"SMYTHE" BS$<"9/12/ 83" where B$="8/12/ 83" Strings can thus be compared for alphabetization or for determi- ning branching of program logic. Note that when string variables are compared, the expressions must be enclosed in quotation marks. 2.1.8 Program Editing MSX-BASIC also includes a Full Screen Editor to allow the program- mer to enter program lines and edit them using the entire screen. 57 MSX BASIC REFERENCE GUIDE The MSX-BASIC Full Screen Editor supports special keys for moving the cursor, for inserting or deleting characters, and for erasing lines or screens. These time-saving special functions and their key assignments will be discussed in the following sections. With the Full Screen Editor, programmers can move the cursor any- where on the screen and make the necessary corrections. To make changes, the cursor is placed on the first line to be changed, and after the changes are entered, the key is pressed at the beginning of each line. Lines in the stored programs will not be changed unless a is entered somewhere within the line. Writing Programs When MSX-BASIC is used and the "Ok" prompt is issued, the system is in the direct mode and is ready to receive a RUN command to ex- ecute the program or Editor commands. Except for commands to exe- cute programs, lines that are entered are processed by the Full Screen Editor. All lines of text beginning with numbers are con- sidered as program statements. The Editor processes the program statements in one of the following ways: 1. A new line is added to the program if the line number is valid (between 0 and 65529) and at least one non-blank character follows the line number. 2. An existing program line is modified if the line number already exists in the program and at least one non-blank character follows the line number. The new line replaces the text of the previously existing line. 3. An existing program line is deleted if the line number already exists in the program and the new line contains only a line number. 4. An error is generated. Am attempt to delete a non-existent line will result in an "Undefined line number" error. If the new line causes the program memory to be entirely filled, no line is added and "Out of memory" is displayed. More than one statement may be placed after a line number, except the statements must be separated by colons (:). (These colons do not require spaces.) A logical program line may have a maximum of 255 characters, including the line number. Editing Programs The LIST command displays all or a part of the program currently residing in memory on the screen so that they can be edited with the Full Screen Editor. To modify the program, move the cursor to the location requiring change and do one of the following: 58 MSX BASIC REFERENCE GUIDE 1. Type over existing characters 2. Delete characters to the right of the cursor 3. Delete characters to the left of the cursor 4. Insert characters 5. Append characters to the end of the logical line These actions are performed by special keys assigned to the Pull Screen Editor (see the next section). Program lines are changed if a carriage return is entered while the cursor is located somewhere on the line. This action changes all editing done to the logical line, regardless of the number of physical lines the program line encompasses. The cursor can be located anywhere in the program line. Pull. Screen Editor Functions The following table lists the hexadecimal codes for the MSX~BASIC control characters and summarizes their functions. The Control-key sequence normally assigned to each function is also listed. These conform as closely as possible to ASCII standards. A discussion of the individual control follows the table. Table 1. MSX~BASIC Control Functions. Control characters are entered by holding down CTRL and pressing the character key. Hex Control Special Code Key Key Function ol A Ignored 02 * B Move cursor to start of previous word 03 * Cc Break if MSX-BASIC is waiting for input 04 * D Ignored 05 * E Erase text to end of logical line 06 * F Move cursor to start of next word Q7 * G Beep 08 H Back Space Backspace, deleting characters passed over 09 I Tab Tab to next TAB stop OA* J Line feed OB * K Home Move cursor to home position oc * L CLS Clear screen OD * M Return Carriage return (enter current logical line) OE * N Append at end of line OF * ° Ignored 10 * P Ignored 11 * Q Ignored 12 * R INS Toggle between insert and typeover modes 59 MSX BASIC REFERENCE GUIDE 13 * s Ignored 14 * t Ignored 15 * U Erase logical line 16* V Ignored 17 * W Ignored 18 * x Select Ignored 19 * XY Ignored 1A * Z Ignored 1B T ESC Ignored ic * ¥ Right arrow Move cursor right(back slash in int. ver.) 1D * ] Left arrow Move cursor left 1E * . Up arrow Move cursor up 1F * — Down arrow Move cursor down 7F DEL DEL Delete character at cursor Note: The keys marked with asterisks (*) cancel the insert mode if the Full Screen Editor is in insert mode. PREVIOUS WORD The cursor is moved left to the first character of the previ- ous word. A word is defined as a character string composed Of A-Z, a-z, or 0-9. BREAK Returns the control to MSX-BASIC direct mode without changing the line that was being edited. ERASE TO END OF LINE The cursor is moved to the end of the logical line, and the characters passed over are deleted. Additional characters at the new cursor position are appended to the line. NEXT WORD The cursor is moved right to the first character of the next word. A word is defined as a character string composed of B-2, a-z, or 0-9. BEEP Produces the beep tone. BACKS PACE Deletes the character to the left of the cursor. All characters to the right of the cursor are moved to the left one position. Any subsequent characters and lines within the current logical line are moved up (wrapped). TAB TAB moves the cursor to the next tab stop, overwriting all spaces. Tab stops occur every 8 characters. CURSOR HOME Moves the cursor to the upper left corner of the screen. The screen is not erased. MSX BASIC REFERENCE GUIDE CLEAR SCREEN Moves the cursor to home position and clears the entire screen, regardless of where the cursor is positioned when the key is entered. CARRIAGE RETURN A carriage return ends the logical line and saves it as part of the MSX-BASIC program. APPEND Moves the cursor to the end of the line, without deleting the Characters passed over. All characters typed at the new position are appended to the logical line until a carriage return is encountered. INSERT Toggle switch for insert mode. When insert mode is on, the cursor size is reduced and characters are inserted at the current cursor position. Characters to the right of the cursor move right as new characters are typed. Line wrap is done on characters going beyond the physical line. If the insert mode is off, the size of cursor returned to normal, and the typed characters replace any existing characters on the line. CLEAR LOGICAL LINE Erases entire logical line when this key is entered anywhere in the line. CURSOR RIGHT Moves the cursor one position to the right. Line wrap is done on characters going beyond the physical line. CURSOR LEFT Move the cursor one position to the left. Line wrap is done on characters going beyond the physical line. CURSOR UP Moves the cursor up one physical line at the current position. CURSOR DOWN Moves the cursor down one physical line at the current position. o Logical line Definition with INPUT A logical line ordinarily consists of all the characters on all of its physical lines. During the execution of an INPUT or LINE INPUT statement, however, this definition is modified slightly to allow for formatted input. When either statement is executed, the logical line is restricted to characters typed or passed over by the cursor. The insert mode and the delete function only move characters within the logical line, and DELETE decrements the size of the line. 61 MSX BASIC REFERENCE GUIDE The 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. If this occurs, the non-blank characters that are not part of the logical line are preserved, and the characters at the end of the logical line are erased. This is to preserve labels existing prior to the INPUT statement. If an incorrect character is entered as the line is being typed, it can be deleted using the key or with a Control-H. Once the undesired character(s ) have been deleted, simply continue typing the line. To delete the current line being typed, type Control-vU. To correct program lines of the program currently in memory, simply type a new line using the same line number. MSX-BASIC will automatically replace the old line with the new line. To delete the entire program currently in memory, enter a NEW command. Usually the NEW command is only used to clear the memory before entering a new program. 2.1.9 Special keys MSX-BASIC supports several special keys (function keys and the STOP key) as follows. © Function Keys MSX~BASIC has ten predefined function keys. The current settings of these keys are displayed on the last line on the screen and can be redefined within a program with the KEY statement. The initial settings for the keys are as follows: Fl color [b] F2 auto[b] Meanings of abbreviations: F4 gotolb] FS list [bl] [b] = blank character F5 run(cr] {erJ= carriage return F6 color 15,4,7[cr] {ul = cursor up character F7 cload" [cls]=clear screen character F8 cont{er] F9 list. [er][fullul (F6 color 15,4,4ler} F10 CclsIrunlcr] in international versions) The function keys can also be used as event trap keys. Refer to the ON KEY GOSUB and KEY ON/OFF/STOP statements for details. o STOP key When MSX-BASIC is in the direct mode, the STOP key has no effect on the current operation, and MSX-BASIC simply ignores its input. 62 MSX BASIC REFERENCE GUIDE If MSX-BASIC is executing a program and the STOP key is pressed, Program execution is suspended and the cursor is displayed to indicate that execution was suspended. If the STOP key is pressed again, execution is resumed. If the CTRL key is held down and the STOP key is pressed, MSX-BASIC stops executing the program and returns to the direct mode with the following message. Break in nnnn The nnnn is the line number of the program that was being executed when the execution was aborted. 2.1.10 ERROR MESSAGES If an error is encountered during program execution, execution terminates, and the appropriate error message is displayed. Refer to 2.1.17 for a complete list of MSX-BASIC error codes and error messages. 2.1.11 Commands and Statements except those doing I/0 AUTO [{,]] Automatically generates line numbers after each carriage return, AUTO begins numbering at and increments each subsequent line number by . The default for both values is 10. If is followed by a comma and is not specified, the last increment specified in an AUTO command is assumed. If AUTO generates an existing line number, an asterisk is printed after the line number as a warning that the existing line will be replaced. If a carriage return is instead immediately entered, the existing line is preserved and the next line number is generated. The AUTO command is terminated by typing Control-C or Control- STOP, and MSX-BASIC returns to the direct mode. The line being input when Control-C is typed is not saved. CONT Continues program execution after a BREAK or STOP. DELETE [][-] Deletes program lines. BASIC always returns to the direct mode after a DELETE is entered. If the does not exist, an ‘Illegal function call' error occurs. LIST [{-[]]] Lists all or a part of the program. MSX BASIC REFERENCE GUIDE If both parameters are omitted, the program is listed beginning at the lowest line number. If only the first parameter is specified, only that line is listed. If the first parameter and a "~" are specified, that line and all lines following it are listed. If "-" and the second parameter are specified, all lines beginning at the lowest line number are listed until the specified number is reached. If both parameters are specified, the lines in the range from the first through the second are listed. The displayed listing can be terminated by holding down "CTRL" and pressing the "STOP" key. The listing can be temporarily suspended by pressing the "STOP" key, and resumed by pressing the "STOP" key again. LLIST [[-[]]] Lists all or part of the program on the printer, with the use of the parameters being identical for the LIST command. NEW Deletes the current program in memory and resets all variables. RENUM [[][,[][,]]] Renumbers program lines. The parameter is the first line that will be used in the renumbered program, with the default being 10. The is the line of the current program where renumbering is to begin, with the default being the first line of the program. The is the increment used in renumbering, and 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 the above statements, an ‘Undefined line nnnn in mmmm' is displayed. The reference to the incorrect line number (nnnn) is not changed by RENUM, but line number mmmm may be changed. NOTE: RENUM can neither be used to change the order of program lines (for example, entering RENUM 15,30 for a program having the three lines numbered 10, 20 and 30), nor can it be used to generate line numbers greater than 65529. In either case, an "Illegal function call' error results. RUN [] Executes the current program. MSX BASIC REFERENCE GUIDE Execution begins at the first line of the program unless the parameter is specified, in which case, execution begins at that line. TRON/TROFF Traces the execution of program statements. The TRON statement can be executed in either the direct or indirect mode to print the line number being execut ed when the program is RUN. The line numbers are displayed within square brackets. The TRON function continues until a TROFF statement or a NEW command is executed. CLEAR [[,]] Sets all numeric variables to zero, all string variables to null, and closes all open files; and optionally sets the end of memory. The parameter sets the memory size allocated for string variables, with the default being 200 bytes. The parameter sets the highest memory address to be used by MSX-BASIC. DATA Used to set the constants to be used by the program's READ statements. DATA statements are not executable and they may be placed anywhere in a program. If a DATA statement is used to define more than one constant, the constants must be delimited by commas. The maximum number of constants that may be placed on a logical line is limited only by the size of the logical line. READ statements replace the constants for the variables used by the program in the sequence listed in the DATA statement (s). The may contain numeric constants in any format: fixed point, floating point, or integer. Numeric expressions are not allowed in DATA statements. String constants may also be used in DATA statements. If the string contains commas, colons, or significant leading or trailing spaces, the string must be embedded in quotation marks. The variable type required (numeric or string) required by a READ statement must match the type specified in its DATA statement. The RESTORE statement may be used to set the data to be read from a specific line. If the RESTORE statement is not used, the data is read from the program's first DATA statement. DIM Specifies the maximum size of array variables. If no DIM statement is specified, the maximum size allocated in memory for the array is 10. If a subscript greater than the maximum size is used, a ‘Subscript out of range' error occurs. The subscripts always begin at 0. MSX BASIC REFERENCE GUIDE DEFINT DEFSNG DEFDBL DEFSTR Declares the variable type to be integer, single-precision, double-precision, or string. The DEFINT/SNG/DBL/STR statements declare that variable names beginning with the letter(s) specified will always be that type of variable. An exception to this rule is when a variable type declaration character is used for a variable. Section 2.1.5 lists the variable declaration characters. DEF FN[ ()]= Defines and names a user-programmed function. The must be a legal variable name and is preceded by FN. The becomes the name of the defined function. The comprises the variable names in the function definition that are replaced when the function is called, and they must be separated by commas. The is an expression performing the function, and is limited to to one line. Variable names appearing in the expression serve only to define the function; they do not affect program variables having the same name. The may have a variable name used, and if so, the value of the variable is supplied when the function is called, otherwise, the current value of the variable is used. The variables in the parameter list represent, on a one-to-one basis, the argument variables or values that will be given in the function call. If the function specifies a variable type, the expression's value takes on that type befor being returned to the calling statement. If the types specified in the function name and its argument do not match, a ‘Type mismatch’ error occurs. The DEFFN statement must be executed before the defined function is used, if not, an ‘Undefined user function’ error occurs. Note that DEFFN cannot be used in the direct mode. DEFUSR{]= Specifies the entry point of a machine language subroutine. The may be any digit from 0 to 9, and corresponds to the number of the USR routine whose address is being specified. If is omitted, DEFUSRO is assumed. The value of is the entry point of the USR routine. MSX BASIC REFERENCE GUIDE DEFUSR statements may be reused as many times as necessary within a program to redefine the entry points of subroutines. ERASE Eliminates arrays from a program. ArrayS may be reDIMensioned after they are ERASEd, or the previously allocated array space in memory may be used for other purposes. If an attempt is made to reDIMension an array without a prior ERASE, a 'Redimensioned array' error occurs. Terminates program execution, closes all files and returns to direct mode. An END statement may be placed anywhere in a program to end its execution. Unlike STOP, the END statement does not cause a BREAK message to be displayed. An END statement located at the end of a program is optional. ERROR Simulates the occurrence of an error or allows error codes to be defined by the user. The value of must be greater than 0 and less than 255. If the value of equals an error code already in use by BASIC, the ERROR statement will simulate the occurrence of that error, and the corresponding error message will be printed. To define an error code, use a value that is greater than that used by BASIC. Section 2.1.17 lists the error codes and messages. Use the highest available codes to maintain compatibility in case more error codes are added to later versions of BASIC. The new user-defined error code may then be handled in an error trap routine. One such example follows. 10 ON ERROR GOTO 1000 120 IF A$="Y" THEN ERROR 250 1000 IF ERR=250 THEN PRINT "Sure?" If an ERROR statement specifyinge a code for which no error message is defined or an ERROR statement having no error trap routine is executed, MSX-BASIC will respond with an ‘Unprintable error', and execution will be terminated. 67 MSX BASIC REFERENCE GUIDE FOR =x TO y [STEP z] NEXT [][,...] Allows a series of instructions to be performed in a loop a given number of times. The is used as a counter for the FOR...NEXT loop. It may be integer, single-precision, or double-precision, where X, yy, and z are numeric expressions. The first numeric expression (x) is the initial value of the counter. The second numeric expression (y) is the final value of the counter. The program lines following the FOR statement are executed until the NEXT statement is encountered. Then the counter is incremented by the value of STEP. The value of the counter is then compared with the final value (y), and if it is not greater, execution is branched back to the statement immediately following the FOR statement and the statements within the loop are repeated. If the counter is exceeded, execution continues with the statement following the NEXT statement. If STEP is not specified, the default is one. If STEP is negative, the final value of the counter must be less than the initial value. The counter is decremented each time through the loop, and the loop is executed until the counter is less than the final value. The loop is executed at least once if the initial value of the loop times the sign of the step exceeds the final value times the sign of the step. FOR...NEXT loops may be nested, that is, a FOR...NEXT loop may be placed within another FOR...NEXT loop. When loops are nested, each loop must have a different variable name for its counter. The NEXT statement for the inside loop must appear before the NEXT for the outside loop. If nested loops share the same end point, a single NEXT statement may be used for all of them. The depth of nesting of FOR...NEXT loops is limited only by the available memory. The variable(s) in the NEXT statement may be omitted, in which case the NEXT statement will match the most recent FOR statement. If a NEXT statement is encountered before its corresponding FOR statement, a 'NEXT without FOR’ error message is issued and execution is terminated. GOSUB RETURN [] Branches to the subroutine beginning at and returns from a subroutine. The is the first line of the subroutine. A subroutine may be called any number of times in a program, and MSX BASIC REFERENCE GUIDE a subroutine may be called from within another subroutine. Nesting of subroutines is limited only by the available memory. RETURN statements in subroutines cause BASIC to branch back to the statement following the most recent GOSUB statement. A subroutine may contain more than one RETURN statement if it is required by the program logic. Subroutines may be placed anywhere in the program, but should be readily distinguishable from the main program for greater understandability. To prevent accidental entry into a 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 will occur and execution terminates. GOTO Branches unconditionally out of the normal program sequence to a specified . If is an executable statement, that statement and those following are executed. If it is a nonexecutable statement, execution proceeds at the first executable statement encountered after . IF THEN [ELSE ] IF GOTO {ELSE ] Changes the program flow based on the result returned by an expression. If the result of 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 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=1 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, the following statement will not print "A<>C" when A<>B. IF A=B THEN IF B=C THEN PRINT "A=C" ELSE PRINT "A<>CTM The statement will print "A<>C" when A=B and B";]} Allows input from the keyboard during program execution. When an INPUT statement is encountered, program execution pauses and a question mark is printed to indicate that the program is waiting for data. If a "“" is included, the string is printed before the question mark. The required data is entered by the keyboard. The data that is entered is assigned to the variable(s) given in . The number of data items supplied must be the same as the number of variables in the list. The data must be separated by commas. The variables named in the may be numeric or string variables (including subscripted variables). The entered data type must agree with the type specified by the variable name. Strings entered in response INPUT statements do not need to be embedded in quotation marks. If the wrong variable type is input (a string variable instead of a numeric variable, etc.), a "?Redo from start” message is displayed. No value is assigned until an acceptable response is given. An example of this follows. list 10 INPUT "A and B";A,B 20 PRINT A+B Ok run A and B? 10,00 ?Redo from start A and B? 10,20 30 Ok If the response to the INPUT statement has too many items, an "?Extra ignored" message is displayed, and the next statement is executed. One such example follows. list 10 INPUT "A and B";A,B 20 PRINT A+B Ok run A and B? 10,20,30 ?Extra ignored 30 Ok 70 MSX BASIC REFERENCE GUIDE Responding to an INPUT statement with too few items 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) ?? 20 (The 20 was typed in by the user) 30 Ok The program can be suspended at the INPUT statement by typing Control-C or by holding down the "CTRL" key and pressing "STOP". MSX-BASIC will return to the direct mode and respond with "Ok". To resume execution, type CONT. LINE INPUT ["";] Inputs an entire line (up to 254 characters) to a string variable, without the use of delimiters. The is displayed on the console before input is accepted. No question mark is printed unless it is a part of the . All input typed to the console before a carriage return is assigned to . The program can be suspended at the LINE INPUT statement by typing Control-C or by holding down the "CTRL" key and pressing "STOP". MSX-BASIC will return to the direct mode and respond with "Ok". To resume execution, type CONT. [LET] = Assigns the value of an expression to a variable. Note that the word LET is optional. LPRINT [] LPRINT USING ; Prints data on the line printer. (Refer to the PRINT and PRINT USING statements below for details.) MID$(),n[,m])= Replaces a portion of one string with another string. The characters in , beginning at position n, are replaced by the characters in . The optional m refers to the number of characters from that will be used in the replacement. If m is omitted or included, the characters replaced does not go beyond the original length of . ON ERROR GOTO Enables error trapping and specifies the first line of the 71 MSX BASIC REFERENCE GUIDE error handling subroutine. Once error trapping has been enabled, all errors detected, including direct mode errors (e.g., Syntax errors), will cause a jump to the specified error handling subroutine. If does not exist, an ‘Undefined line number'§ error occurs. To disable error trapping, execute an ON ERROR GOTO 0. Subsequent errors will then display error messages and halt execution. An ON ERROR GOTO 0 statement appearing in an error trapping subroutine will cause BASIC to stop and display 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 GOTO ON GOSUB Branches to one of several specified line numbers, depending on the value returned when an expression is evaluated. The value of 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 not an integer, 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 either zero or is greater than the number of items in the list (and <= 255), MSX-BASIC continues with the next executable statement. If the value of is either negative or is greater than 255, an ‘Illegal function call' error occurs. POKE , Writes a (decimal) byte to a (decimal) memory location. The is the address of the memory location to be written to (POKEd). The is the data (byte) to be POKEd. It must be in the range 0 to 255. The must be in the range -32768 to 65535. If this value is negative, the address is computed by subtraction from 65536. For example, a -1 is the same as 65535 (65536-1=65535) . Otherwise, an ‘Overflow’ error occurs. PRINT [] Displays data to the console. If the is omitted, a blank line is printed. If the is included, the values 72 MSX BASIC REFERENCE GUIDE of the expressions are displayed on the console. An expression in the list may be a numeric and/or a string expression. Strings must be enclosed in quotation marks. The position of each displayed item is determined by the punctuation used to separate the items in the list. MSX-BASIC divides the line into print zones of 14 spaces each. In the , a comma causes the next value to be displayed at the beginning of the next zone. A semicolon causes the next value to be displayed immediately after the last value. One or more spaces between the expressions are treated as semicolons. If a comma or a semicolon terminates the , the next PRINT statement begins printing on the same line, spacing accordingly. If the terminates without a comma or a semicolon, a carriage return is printed at the end of the line. If the printed line is longer than the console width, MSX-BASIC goes to the next physical line and continues printing. A displayed number is always followed by a _ space. Positive numbers are preceded by a space. Negative numbers are preceded by a minus sign. A question mark may be used instead of the word PRINT. PRINT USING ; Displays strings or numerics using a specified format. The is comprised of the string expressions or numeric expressions that are to be printed, separated by semicolons. The is a string literal (or variable) comprising special formatting characters. These formatting characters (see below) determine the field and the format of the printed strings or numbers. When PRINT USING is used to print strings, one of the following three formatting characters may be used to format the string field: Specifies that only the first character in the given string is to be printed. Example: A$="Japan" Ok PRINT USING "!";A$ J Ok "& n spaces &" (Japanese. Refer to 5.4 for other versions.) 73 MSX BASIC REFERENCE GUIDE Specifies that 2+n characters from the string are to be printed. If the '&' 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: AS="Japan" Ok PRINT USING "& &";A$ Japa Ok "@" (Japanese. Refer to 5.4 for other versions.) Specifies that the whole character in the given string is to be printed. Example: AS="Japan" Ok PRINT USING "I love @ very much.";A$ I love Japan very much. Ok When PRINT USING is used to print numbers,the following special characters may be used to format the numeric field: wae A number sign is used to represent each digit position. The digit positions are always filled. If the number to be printed has fewer digits than positions specified, the number will be right-justified (preceded by spaces) in the field. A decimal point may be inserted at any position in the field. If the format string specifies that a digit is to precede the decimal point, the digit will always be printed (as 0 if necessary). Numbers are rounded as necessary. Example: PRINT USING "###.##";10.2,2,3.456,.24 10.20 2.00 3.46 0.24 Ok aye 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: 74 MSX BASIC REFERENCE GUIDE PRINT USING "+###.##"371.25,-1.25 41.25 -1.25 Ok PRINT USING “###. ##+";1.25,-1.25 1.25+ 1.25- Ok 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 WEED 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 "**#. ##°;2.25,-1.25 *#*1.25*-1.25 Ok "¥¥" (Japanese. Refer to 5.4 for other versions. A double yen sign causes a yen sign to be printed to the immediate left of the formatted number. The ¥¥ specifies two more digit positions, one of which is the yen sign. The exponential format cannot be used with ¥¥. Negative numbers cannot be used unless the minus sign trails to the right. Example: PRINT USING "¥¥###.##"°;12.35,-12.35 ¥12.35 -¥12.35 Ok PRINT USING "¥¥###. ##-"712.35,-12.35 ¥12.35 ¥12.35- Ok "**¥" (Japanase. Refer to 5.4 for other versions. The **¥ at the beginning of a format string combines the effects of the above two symbols. Leading spaces will be filled with asterisks and a yen sign will be printed before the number. **¥ specifies three more digit positions, one of which is the yen sign. Example: PRINT USING "**¥#.##";12.35 *¥12.35 7 MSX BASIC REFERENCE GUIDE Ok won ’ A comma that is to the left of the decimal point ina formatting string causes a comma to be printed to the left of every third digit to the left of the decimal point. A comma that is at the end of the format string is printed as part of the string. A comma specifies another digit position. The comma has no effect if used with the exponential format. Example: PRINT USING "####,.##7;1234.5 1,234.50 Ok PRINT USING "“####. ##,";1234.5 1234.50, Ok Four carats may be placed after the digit position characters to specify exponential format. The four carats allow space for E+xx to be printed. Any decimal point position may be specified. The significant digits are left-justified, and the exponent is adjusted. Unless a leading + or trailing + or - is specified, one digit position will be used to the left of the decimal point to print a space or minus sign. Example: PRINT USING "##.##°°"*"; 234.56 2.35E+02 Ok PRINT USING "#.##°°**-";-12.34 1.23 E+01- Ok PRINT USING "+#. ##°°°°";12.34,-12.34 +1.23E+01-1.23E+01 Ok ug 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 $123.45 Ok PRINT USING ". ##";.999 $1.00 Ok 76 MSX BASIC REFERENCE GUIDE If the number of digits specified exceed 24, an ‘Illegal function call' error will result. READ Reads values from a DATA statement and assigns them to variables. A READ statement must always be used in conjunction with a DATA statement. READ statements assign variables to DATA statement values on a one-to-one basis. READ statement variables may be numeric or string, and the values read must agree with the variable types specified. If they do not agree, a 'Syntax error' will result. A single READ statement may access one or more DATA statements (they will be accessed in order), or several READ statements may access the same DATA statement. If the number of variables in exceeds the number of elements in the DATA statement(s), an ‘Out of DATA' error will result. If the number of variables specified is fewer than the number of elements in the DATA statement(s), subsequent READ statements will begin reading data at the first unread element. If there are no subsequent READ statements, the extra data is ignored. To reread DATA statements from the start, use the RESTORE statement. REM Allows explanatory remarks to be inserted in a program. REM statements are not executed but are output exactly as entered when the program is listed. REM statements may be branched to (from a GOTO or GOSUB statement), and execution will continue with the first executable statement after the REM statement. Remarks may be added to the end of a line by preceding the remark with a single quotation mark instead of :REM. Do not use the above ina DATA statement as it would be considered legal data. RESTORE [] Allows DATA statements to be reread from a specified line. After a RESTORE statement is executed, the next READ statement accesses the first item in the first DATA statement in the program. If is specified, the next READ statement accesses the first item in the specified DATA statement. If a nonexistent line number is specified, an ‘Undefined Line number' error will result. 77 MSX BASIC REFERENCE GUIDE RESUME RESUME 0 RESUME NEXT RESUME Continues program execution after an error recovery procedure has been performed. Any one of the four formats shown below may be used, depending upon where execution is to resume: RESUME or RESUME 0 Execution resumes at the statement which caused the error. RESUME NEXT Execution resumes at the statement immediately following the one which caused the error. RESUME Execution resumes at A RESUME statement that is not in an error trap subroutine causes a 'RESUME without' error. STOP Terminates program execution and returns to command level. A STOP statement may be used anywhere in a program to terminate execution. When a STOP statement is encountered, the following message is printed: Break in nnnn (nnnn is a line number) Unlike the END statement, the STOP statement does not close files. Execution is resumed by issuing a CONT command. SWAP , Exchanges the values of two variables. Any type of variable may be SWAPped (integer, single-precision, double-precision, string), but the two variables must be of the same type, or a ‘Type mismatch' error results. 78 MSX BASIC REFERENCE GUIDE 2.1.12 Functions except those doing I/O ABS(X) Returns the absolute value of the expression X. ASC(X$) 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 precisio n. BIN$(n) Returns a string which represents the binary value of the decimal argument. The numeric expression, n, must be between -32768 and 65535. If n is negative, the two's complement is used. That is, BINS(-n) is the same as BIN$(65536-n). CDBL (xX) Converts X to a double precision number. CHR$(I) Returns a string whose one element is the ASCII code for I. CHR$ is commonly used to send a special character to the console. CINT (X) Converts X to an integer number by truncating the fractional portion. If X is not between -32768 and 32767, an ‘Overflow' error occurs. COS (XxX) Returns the cosine of X in radians. COS(X) is calculated to double precision. CSNG (X) Converts X to a single precision number. CSRLIN Returns the vertical coordinate of the cursor. ERL/ERR The ERR and ERL variables are usually used in IF-THEN statements to direct program flow in the error trap routine. When an error handling subroutine is entered, the variabl e ERR contains the error code for error,and the variable ERL contains the line number of the line in which the error was detected. If the statement that caused the error was a direct mode 79 MSX BASIC REFERENCE GUIDE statement, ERL will contain 65535. To test if an error occurred in a direct statement, use the following statement. IF 65535=ERL THEN ....- Otherwise, use the following statements. IF ERL= THEN .... IF ERR= THEN.... Because ERL and ERR are reserved variables, neither may appear to the left of the equals sign in a LET (assignment) statement. EXP (X) 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). FIX(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 programs, text files, and machine language program files. FRE("") returns the number of bytes in memory for string space. HEX$ (X) Returns a string which represents the hexadecimal value of the decimal argument. The numeric expression, n, must be between -32768 and 65535. If n is negative, the two's complement form 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-STOP, which terminates the program. INPUTS (X) Returns a string of X characters, read from the keyboard. No character will be echoed and all characters are passed through, except for Control-STOP, which terminates the program. INSTR(I1I,1]X$,Y$) Searches for the first occurrence of string Y$ in X$ and returns the position at which the match is found. the optional MSX BASIC REFERENCE GUIDE offset I sets the position for starting the search. I must be in the range 0 to 255. If I>DLEN(X$) or if X$ is null or if Y$ cannot be found or if X$ and Y$ are null, INSTR returns 0. If only Y$ is null, INSTR returns I or 1. X$ and Y$ may be string variables, string expressions, or string literals. INT(X) Returns the largest integer <=x. LEFT $(X$,I) 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(X$), the entire string (x$) is returned. If I=0, a null string (length zero) is returned. LE (XN $) Returns the number of characters in X$. Nonprinting characters and blanks are counted. LOG (X) Returns the natural logarithm of xX, X being greater than zero. LPOS (xX) Returns the current position of the line printer print head within the line printer buffer, not necessarily giving the physical position of the print head. xX is a dummy argument. MIDS(X$,I[,J]) 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 g 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 ID>LEN(X$), MID$ returns a null string. OcT $(n) Returns a string which represents the octal value of the decimal argument. The numeric expression, n, must be between -32768 and 65535. I£ n is negative, the two's complement form is used, for example, OocT$(-n) is the same as OCT$(65536-n). PEEK (I) Returns the byte (decimal integer in the range 0 to 255) read 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$, 1} Returns the rightmost I characters of string x$. I£ I=LEN(X$), return XS. Tf I=0, a null string (length zero) is returned. 81 MSX BASIC REFERENCE GUIDE RND(X) Returns a random number between 0 and l. 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) Returns 1 (for X>0), 0 (for X=0), ~1 (for X<0). SIN(X) Returns the sine of X in radians. SIN(X) is calculated to double-precision. SPACE $ (X) ; Returns the string of spaces of length xX. The expression X discards the fractional portion and must be range 0 to 255. SPC (I) Prints I blanks on the screen. SPC may only be used with PRINT and LPRINT statements. I must be in the range 0 to 255. SQR(X) Returns the square root of X. X must be >=0. STR$(X) Returns a string representation of the value of X. STRING $(I,J) STRING $(I,X$) Returns a_ string of length I whose characters all have ASCII code J or the first character of the string x$. TAB (I) 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) Returns the tangent of X in radians. TAN(X) is calculated to double precision. If TAN overflows, an 'Overflow' error will occur. USRI] (xX) Calls the user's assembly language subroutine with the argument X. is in the range 0 to 9 and corresponds to the digit supplied with the DEFUSR statement for that routine. If is omitted, USRO is assumed. VAL (X $} Returns the numerical value of the string X$. The VAL function also strips leading blanks, tabs, and linefeeds from the 82 MSX BASIC REFERENCE GUIDE argument string. The following is an example. PRINT VAL(" -7") +7 Ok VARPTR() VARPTR(#) Returns the address of the first byte of data identified with . A value must be assigned to prior to execution of VARPTR. Otherwise, an ‘Illegal function call' error results. Any type of 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 to 65536 to obtain the actual address. VARPTR is usually used to obtain the address of a variable or array so it may be passed to a machine language subroutine. A function call of the form VARPTR(A(0)) is usually specified when passing an array, so that the lowest-address element of the array is returned. All simple variables should be assigned before calling VARPTR for an array because the address of the arrays change whenever a new simple variable is assigned. If # is specified, VARPTR returns the starting address of the file control block. 83 MSX BASIC REFERENCE GUIDE --- Expanded Statements and Functions for MSX --- 2.1.13 Device Specific Statements SCREEN {]1,]{,] [,][,] Assigns the screen mode, sprite size, key click, cassette baud rate, and printer option. 40x24 text mode, 1 should be set to 0 to select high select 32x24 text mode, 2 to selec t resolution mode, 3 . to select multi-color (low-resolution mode) : 40x24, text mode 32x24, text mode wne high-resolution mode multi-color mode determines the size of sprite. Should be set to select 8x8 magnified 0 to select 8x8 unmagnified sprites, 1 tod sprite sprites, 2 to select 16x16 unmagnifie s, 3 to select 16x16 magnified sprites. NOTE: If is specified, the contents of SPRITE$ will be cleared. QO: 8x8, unmagnified 1: 8x8, magnified 2: 16x16, unmagnified 3: 16x16, magnified determines whether to enable or disable the key click. Should be set to 0 to disable it. 0: disable key click non-zero: enable 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. determines the default baud rate succeeding write operations, 1 for 1200 baud, and 2 for 2400 baud. The baud rate can also be determined using CSAVE command with baud rate option. is automatically Note that when reading cassette, the baud rateknow determined, so that users do not need to> determthe baud rate the cassette is written. Sets the width of the display during text mode. Valid values are 1 to 40 in 40x24 text mode, and 1 to 32 in 32x24 text mode. cLs Clears the screen. Valid in all screen modes. LOCATE []I[,],] Locates character the position for PRINT. can be specified only in text mode. 0: Disable the cursor display 1: Enable the cursor display COLOR [][,][,] Defines the color, the default being 15,4,7 in the Japanese version. Refer to 5.4 for other versions. The argument can be in the range of 0 to 15. The color correspondences follow. # PReee HPODRIAUARWNRO Transparent Black Medium green Light green Dark blue Light blue Dark red Cyan Medium red Light red ° Dark yellow mWNH Light yellow Dark green Magenta Gray wn White PUT SPRITE [,] [,][,] Sets up sprite attributes. may range from 0 to 31. always ca come in one of two forms: STEP ( x offset, y offset) or ( absolute x, absolute y) The first form is a point relative to the most recent point referenced. The second, more common, form is directly refers to a point without regard to the last point referenced. The follwing are some examples. 85 MSX BASIC REFERENCE GUIDE (10,10) absolute form STEP (10,0) offset 10 in x and 0 iny (0,0) origin Note that when BASIC scans coordinate values it will allow them to be beyond the edge of the screen, however values outside the integer range (-32768 to 32767) will cause an overflow error. And the values outside of the screen will be substituted with the nearest possible value. For example, 0 for any negative coordinate specification. Note that (0,0) is always the upper left-hand corner. Although numbering y at the top causes the bottom left corner to be (0,191) in both high~ and medium-resolution, this is standard. The above description can be applied wherever graphic coordinates are used. The X coordinate may range from -32 to 255. The Y coordinate may range from -32 to 191. If 208 (&HDO) is given to , all sprite planes behind disappears until a value other than 208 is given to that plane. If 209 (&HD1) is specified to , that sprite disappears from the screen. Refer to the VDP manual for further details. When a field is omitted, the current value is used. At start up, the color defaults to the current foreground color. specifies the pattern of sprite, and must be less than 256 when size of sprites if 0 or 1, and must be less than 64 when the size of sprites is 2 or 3. defaults to the . See also the SCREEN Statement and the SPRITES variable. CIRCLE ,I[,] [,][,][,] Draws an ellipse with a center and radius as indicated by the first of its arguments. specifies the coordinate of the center of the circle on the screen. For details on , see the description of the PUT SPRITE statement. The defaults to foreground color. The and parameters are radian arguments between 0 and 2*PI which allow you to specify where drawing of 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 is for horizontal and vertical ratio of the ellipse. MSX BASIC REFERENCE GUIDE DRAW Draws figure according to the graphic macro language. The graphic macro language commands are contained in the string expression string. The string defines an object, drawn when BASIC executes the DRAW statement. During execution, BASIC ex- amines the value of string and interpre ts single-letter com- mands from the contents of the string. These commands are des- cribed in detail below: The following movement commands begin movement from the last point referenced. After each command, last point referenced is the last point the command draws. Moves up maAymDHoOG posses Moves down Moves left Moves right Moves diagonally up and right Moves diagonally down and right Moves diagonally down and left Moves diagonally up and left The n in each of the preceding commands indicates the distance to move. ‘The number of points moved is n times the scaling factor set by the S command. M x,y Moves absolute or relative. If x has a plus sign(+) or a minus sign(-) in front of it, it is relative. Otherwise, it is absolute. The aspect ratio of the screen is 1. Thus, 8 horizontal points are equal to 8 vertical points. The following two prefix commands may precede any of the above movement commands. B Moves, but doesn't plot any points. N Moves, but returns to the original position when finished. The following commands are also available: An Sets angle n. n may range from 0 to 3, where 0 is 0 degrees, 1 is 90, 2 is 180, and 3 is 270. 0 = 2 Cn Sets color n, being between 0 and 15. 87 MSX BASIC REFERENCE GUIDE Sn Sets the scale factor, n being betwen 0 and 255. The scale factor is n/4. For example, if n=1, the scale factor is 1/4. The scale factor is multiplied by the distance given with U,D,L,R,E, F,G,and H; and relative M commands give the dis- tance moved. The default value is 0, meaning 'no (i.e., it is the same as S4). X: Executes substring. This allows you to execute a second string from within a string. Example A$="U80R80D80L80":DRAW "XA$;" ->Draws a square In all of these commands, the n, x, or y argument can be a constant like 123 or it can be '=;' where is the name of a numeric variable. The semicolon (;) is required if the variable is used this way, or in the X command. Otherwise, a semicolon is optional between commands. Spaces are ignored in string. For example, variables in a move com- mand in this way: X1=40:X2=50 DRAW "M+=x1;,-=X2" The X command can be a very useful part of DRAW, because you can define a part of an object separate from the entire object and also can use X to draw a string of commands more than 255 characters long. LINE []-[,] [,] Draws a line connecting the two specified coordinate. For the details on the , see the description of the PUT SPRITE statement. If 'B' is specified, a rectangle is drawn. If 'BF' is speci- fied, the rectangle is filled. PAINT [,][,] Fills in a bordered figure with the specified fill color from the . See the description on PUT SPRITE for details of the . The PAINT statement does not allow to be off the screen. Note that PAINT must not have a border for high-resolution graphics, border can be specified only in multicolor mode. In high-resolution graphics mode, the paint color is regarded as the border color. PSET[,] PRESETI[,] MSX BASIC REFERENCE GUIDE Sets/resets the specified coordinate. For details of the , see the description on PUT SPRITE. The only difference between PSET and PRESET is that if no is given in PRESET statement, the background color is selected. When a argument is given, PRESET is identical to PSET. REY , Sets a string to specified function key. must be in the range 1 to10. must be within 15 characters. Example: KEY 1,"PRINT TIME$"+CHR$(13) A$="Japan" KEY 2,A$ KEY LIST Lists the contents of all function keys. Example: KEY LIST color auto goto list run color 15,7,7 cload" cont list . run Ok "color" corresponds to key "£1", "auto" with "£2", "goto" with "£3", and so on. Position in the list reflects the key assignments. Note that control characters assigned to function keys are converted to spaces. KEY ONIOFF Turns on/off function key display on 24th line of text screen. ON KEY GOSUB Sets up a line numbers for BASIC to trap to when the function keys is pressed. Example: ON KEY GOSUB 100,200,,400,,500 When a trap occurs, an automatic KEY(n)STOP is executed so receive traps can never take place. The RETURN from the trap routine will automatically do a KEY(n)ON unless an explicit KEY(n)OFF has been performed inside the trap routine. 89 MSX BASIC REFERENCE GUIDE 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). KEY () ON/OFF/STOP Activates/deactivates trapping of the specified function key in a BASIC program. A KEY(n)ON statement must be executed to activate trapping of function key. After a KEY(n)ON statement, if a line number is specified in the ON KEY GOSUB statement then every time BASIC starts a new statement it will check to see if the specified key was pressed. If so, it will perform a GOSUB to the line number specified in the ON KEY GOSUB statement. If a KEY(n)OFF statement has been executed, no trapping takes place and the event is ignored. If a KEY(n)STOP statement has been executed, no trapping will take place, but if the specified key is pressed, this is remembered so trapping is done if KEY(n)ON is executed. KEY(n)ON does not affect the function key assignments displayed at the bottom of the console. ON STRIG GOSUB Sets up a line numbers for BASIC to trap to when the trigger button is pressed. Example: ON STRIG GOSUB ,200,,400 When the trap occurs an automatic STRIG(n)STOP is executed so receive traps can never take place. The RETURN from the trap routine will automatically do a STRIG(n)ON unless an explicit STRIG(n)OFF has been performed inside the trap routine. 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, all trapping (including ERROR, STRIG, STOP, SPRITE, INTERVAL and KEY) is automatically disabled. STRIG () ON/OFF/STOP Activates or deactivates trapping of joystic trigger buttons in BASIC programs. can be between 0 and 4. If = 0, the space bar is used for a trigger button. If is either 1 or 3, the trigger of a joystick 1 is used. When is either 2 or 4, joystick 2 is used. A STRIG(n)ON statement must be executed to activate trapping MSX BASIC REFERENCE GUIDE of the trigger button. After an STRIG(n)ON statement is execu- ted, if a line number is specified in the ON STRIG GOSUB state-— ment, then every time BASIC starts a new statement, it will check to see if the trigger button was pressed. If so, it will perform a GOSUB to the line number specified in the ON STRIG GOSUB statement. If a STRIG(n)OFF statement has been executed, no trapping takes place and the event is not remembered even if it does take place. If a STRIG(n)STOP statement has been executed, no trapping will take place, but if the trigger button is pressed this is remembered so an immediate trap will take place when STRIG(n)ON is executed. ON STOP GOSUB Sets up a line numbers for BASIC to trap to when the Control- STOP key is pressed. When the trap occurs, the STOP STOP statement is executed so receive traps can never take place. The RETURN from the trap routine will automatically do a STOP ON unless an explicit STOP OFF has been performed inside the trap routine. 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, all trapping (including ERROR, STOP, STRIG, SPRITE, INTERVAL and KEY) are automatically disabled. Use caution when using this statement. For example, the follo- wing program cannot be aborted, and the only way out is to reset the system! 10 ON STOP GOSUB 40 20 STOP ON 30 GOTO 30 40 RETURN STOP ON/OFF/ STOP Activates/deactivates trapping of 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 a STOP STOP statement has been executed, no trapping will take place. But if a Control-STOP is pressed,this is remembered, MSX BASIC REFERENCE GUIDE so an immediate trap will take place when STOP ON is executed. ON SPRITE GOSUB Sets up a line number for BASIC to trap to when the sprites coincide. When the trap occurs an automatic SPRITE STOP is executed so receive traps can never take place. The RETURN from the trap routine will automatically do a SPRITE ON unless an explicit SPRITE OFF has been performed inside the trap routine. Event trapping does not take place when BASIC is not executing a program. When anerror trap (resulting from an ON ERROR statement) takes place this automatically disables all trapping (including ERROR, STRIG, STOP, SPRITE, INTERVAL and KEY). SPRITE ON/OFF/STOP Activates/deactivates trapping of sprite in a BASIC program. A SPRITE ON statement must be executed to activate trapping of sprite. After SPRITE ON statement, if a line number is specified in the ON SPRITE GOSUB statement then every time BASIC starts a new statement it will check to see if the sprites coincide. If so, it will perform a GOSUB to the line number specified in the ON SPRITE GOSUB statement. If a SPRITE OFF statement has been executed, no trapping takes place and the event is not remembered even if it does take place. If a SPRITE STOP statement has been executed, no trapping will take place. But if the sprites coincide, this is remembered so an immediate trap will take place when SPRITE ON is executed. ON INTERVAL=