Sharp MZ-700 Series Owner's Manual

Page 1
Personal Computer
im-7/m
OWNER'S MANUAL
SHARP
Page 2
IMPORTANT
The wires in this mains lead are coloured in accordance with the following code:
BLUE: Neutral BROWN: Live
As the colours of the wires in the mains lead of this apparatus may not correspond with the coloured markings identifying the terminals in your plug proceed as follows. The wire which is coloured BLUE must be connected to the terminal which is marked with the letter N or coloured black. The wire which is coloured BROWN must be connected to the ter- minal which is marked with the letter L or coloured red.
This apparatus complies with requirements of EEC directive 76/889/EEC.
Das Gerat stimmt mit den Bedingungen der EG-Richtlinien 76/889/EWG iiberein.
Cet appareil repond aux specifications de la directive CCE 76/889/CCE.
Dit apparaat voldoet aan de vereisten van EEG-reglementen 76/889/EEG.
Apparatet opfylder kravene i EF direktivet 76/889/EF.
Quest'apparecchio e stato prodotto in conformita alle direttive CEE 76/889/CEE.
Page 3
Personal Computer
mz-Tffixo)
Owner's
Manual
© SHARP CORPORATION
Page 4
NOTICE
This manual has been written for the MZ-700 series personal computers and the
> BASIC interpreter which is provided with the MZ-700.
* iwXliffY * m M m ii
| (1) All system software for the MZ-700 series computers is supported in software
packs (cassette tape, etc.) in file form. The contents of all system software and the material presented in this manual are subject to change without prior notice
i for the purpose of product improvement and other reasons, and care should be
taken to confirm that the file version number of the system software used matches
T .
* -
I $ (2) All system software for the Sharp MZ-700 series personal computer has been
f Reproduction of the system software or the contents of this book is prohibited.
t
*
4 | (3) This computer and the contents of this manual have been fully checked for
T i ed by reading this manual, please do not hesitate to contact your Sharp dealer
V $ a result of operation or use of this equipment.
that specified in this manual.
developed by the Sharp Corporation, and all rights to such software are reserved.
completeness and correctness prior to shipment; however, if you should encoun- ter any problems during operation or have any questions which cannot be resolv-
for assistance. Not withstanding the foregoing, note that the Sharp Corporation and its repre- sentatives will not assume responsibility for any losses or damages incurred as
Page 5
Preface
Congratulations on your purchase of a Sharp MZ-700 series personal computer. Before using
your computer, please read and make sure you understand the operating procedures which are described in this manual. The features and general operating procedures are described in
Chapters 1 and 3, so please read those chapters first.
All software for the MZ-700 series computers is distributed on cassette tape. The cassette tape included with the computer contains BASIC 1Z-013B, a high level BASIC
interpreter which enables programming in the BASIC language and makes it possible to utilize the full capabilities of the MZ-700. The BASIC 1Z-013B interpreter and procedures for its use are fully described in this manual.
Page 6
MZ-700 OWNER S MANUAL
CONTENTS
Chapter 1 The world of MZ-700 Series Personal Computer
1. 1 Features of the MZ-700 Series 10
1. 2 Using this Manual 12
1.3 An Introduction to the World of Computers 13
Chapter 2 BASIC
2. 1 Introduction to Programming in BASIC 16
2. 2 An Outline of BASIC 21
2. 3 Frequently Used BASIC Commands and Statements 28
2. 4 Built-in Function 71
2. 5 String Function 76
2. 6 Color display state ment 80
2. 7 Color Plotter-Printer Commands 82
2. 8 Machine Language Program Control Statements 91
2. 9 I/O Statements 95
2. 10 Other Statements 96
2. 11 Monitor Function 99
Chapter 3 Operating the MZ-700
3. 1 Appearance of the MZ-700 Series Personal Computers 104
3. 2 Connection to Display Unit 106
3. 3 Data Recorder 108
3. 4 Color Plotter-Printer 110
3. 5 Key Operation 114
Chapter 4 Hardware
4. 1 MZ-700 System Diagram 122
4. 2 Memory configuration 123
4. 3 Memory Mapped I/O ($E000-$E008) 130
4. 4 Signal System of Color V-RAM 133
4. 5 MZ-700 Circuit Diagrams 134
Chapter 5 Monitor Commands and Subroutines
5. 1 Monitor Commands 146
5. 2 Functions and Use of Monitor Commands 147
5. 3 Monitor Subroutines 151
Page 7
APPENDICES
A. 1 Code Tables 154 A. 2 MZ-700 Series Computer Specifications 157 A. 3 BASIC Error Message List 159 A. 4 Z80A Instruction Set 160 A. 5 Monitor Program Assembly List 164 A. 6 Color Plotter-Printer Control Codes 198 A. 7 Notes Concerning Operation 201
Page 8
INDEX
[BASIC COMMANDS] ( ) is abbreviated format
® ABS
ASC 78 ATN 71 AUTO (A.) 31 AXIS (AX.) 89
® BYE .
CHR$ 78 CIRCLE (CI.) 90 CLOSE (CLO.) 68 CLR 59 COLOR (COL.) 80
CONSOLE (CONS.) .... 98
CONT (C.) 34 COS 71
CURSOR (CU.) .... 61
(B.) .... 35
71
®
HSET (H.) .... 88
s
IFERL 97 IFERN 96 IF-GOSUB (IF-GOS.) 53 IF-GOTO (IF—G.) 53
IF-THEN (IF—TH.) .... 50
INP 95 INPUT (I.) 42 INPUT/T (I./T) 68 INT 71
0
KEY LIST (K. L.)
35
®
DEFFN 56 DEF KEY 57
DELETE (D.) .... 31
DIM 56
END
EXP .
(E.)
59 71
LEFTS LEN 76 LET 36 LIMIT (LIM.) 92
LINE 85
LIST (L.) .... 32
LIST/P (L. /P) .... 84
LN 71
LOAD (LO.) .... 28
LOG 71
FOR-NEXT
GET GOSUB
-RETURN (GOS.-RET.) GOTO (G.) GPRINT (GP.)
(F. ~N.)
47
43
49 48
88
MERGE (ME.) MID$ MODE GR (M. GR) MODE TL (M. TL) MODE TN (M. TN) MODE TS (M. TS) MOVE MUSIC (MU.)
77
32 77 83 83 83 83 87 65
Page 9
®
NEW 32
®
ON ERROR
GOTO (ON ERR. G.) . . . . 96
ON~GOSUB (ON-GOS.) .... 55
ON-GOTO (ON~G.) .... 54
OUT 95
®
SAVE (SA.) 29 SET 63
SGN 71 SIN 71 SIZE 97 SKIP 84 SPC 62 SQR 71 STOP (S.) 59 STR$ 79
®
PAGE 84 PAI 71
PCOLOR (PC.) .... 83
PEEK 93 PHOME (PH.) 87
PLOT OFF (PL. OFF) .... 98
PLOT ON (PL. ON) ... . 98
POKE 92 PRINT (?)••• 37
PRINT USING (?USI.) .... 38
PRINT/P (?/P) .... 84
PRINT/T (?/T) .... 68
PRINT [a,/3] (? [a,0]) 81
©
TAB 62 TAN 71 TEMPO (TEM.) 67
TEST (TE.) .... 84
TI$ 60
©
USR (U.) 93
®
VAL 79
VERIFY (V.) 30
©
®
®
RAD 71
READ-DATA (REA. ~DA.) .... 44
REM 58
RENUM (REN.) .... 33
RESET 63 RESTORE (RES.) 46 RESUME (RESU.) 97 RIGHTS 77
RLINE (RL.) .... 86
RMOVE (RM.) .... 87
RND 72
ROPEN (RO.) .... 68
RUN (R.) .... 34
WOPEN (W.) .... 68
® ®
®
Page 10
3VA2
. zn
P.)
TT
{.A1 - ;v
......
. . i .
......
a/. 3
..
-
Page 11
THE WORLD OF MZ-700
SERIES PERSONAL
COMPUTER
Chapter 1
Page 12
1.1 Features of the MZ-700 Series
In the space of just a few decades, the computer has undergone a dramatic transformation, changing from an intricate, enormously expensive monster weighing several dozen tons into a compact, inexpensive device which can be used by almost anyone. Whereas access to computers used to be limited to a few privileged individuals with special training, the inexpensive, user-friendly machines now available make the world of computing open to people in all different walks of life. The Sharp MZ-700 series computers are representative of such machines.
People use words and expressions to convey meanings.
Computers of the Sharp MZ-700 series, however, convey meaning through an ordinary television set or special printer. Any TV set can be used, either color or black-and-white; or, you may invest in one of the special display screens available if you want greater resolution and sharpness; you will be surprised at the beauty which is provided by such displays.
A tape recorder can be connected to computers of the Sharp MZ-700 series to record programs, the instructions which control the operation of the computer. When printed records of such programs or of
the results of computer processing are desired, they can be obtained on the MZ-700's compact, elegantly
designed 4-color plotter-printer.
MZ-731
Note: In the remainder of this manual, the term "MZ-700" will be used to indicate any of the computers
of the MZ-700 series (the MZ-711, MZ-721, and MZ-731).
10
Page 13
Page 14
1.2 Using this Manual
Before starting to study programming, why not try playing with the MZ-700 a bit? We're sure you want to do that anyway, rather than waiting until after you have read this book. First, read "Operating
the MZ-700" in Chapter 3 (you need read only those parts which apply to the model which you are us- ing). Connect the MZ-700 to a television, read the explanation of procedures for using the keyboard, and
learn which characters are output when each key is pressed.
If you are using the MZ-700 for the first time, read Chapters 1 and 2, in that order. At first, you may
find it difficult to grasp the meanings of the various commands and statements of the BASIC programming
language; however, even if you don't understand the explanations, be sure to key in the examples as
they are encountered. As you do so, you will gradually develop a concept of what BASIC is all about.
You may skip over those portions of Chapter 2 which start with 2. 8 "Machine Language Program
Control Statements"; however, these sections will prove useful when you have completely mastered programming in BASIC, or wish to become more familiar with the computer's internal operation.
If you have used the MZ-80K, you will find that the commands and statements of BASIC for the MZ-700 are used in the same manner as those of the SP-5025 family, so that the MZ-700 can be used in almost exactly the same manner as the MZ-80K. The major difference between the two is in the color statements (applicable to both the television screen and the color plotter-printer) which have been added; however, you should find it easy to become familiar with these by reading sections 2. 6 "Color display
statement" and 2. 7 "Color Plotter-printer Commands." Having done this, you will quickly be captivated by the power of expanded BASIC.
This manual also includes a discussion of "Operating the MZ-700" (Chapter 3), a reference section entitled "Hardware" (Chapter 4), a discussion of the "Monitor Commands and Subroutines" (Chapter 5),
and appendices of other information.
Now go ahead and learn everything you can about the MZ-700. We hope that you will find this manual helpful.
12
Page 15
1.3 An Introduction to the World of Computers
1.3.1 What is BASIC?
People use language to communicate with each other, and specially designed languages are also used for
communication with computers. BASIC is one such language.
Beginner's All-purpose Symbolic Instruction Code
Just as human beings use languages such as English, French, German, and Japanese for communication, there are also many different languages which are used for communication with computers. Among these are BASIC, FORTRAN, COBOL, and PASCAL. Of these, BASIC is the computer language whose struc- ture is closest to that of the languages used by humans, and therefore is the easiest for humans to under- stand.
1.3.2 Loading BASIC into the MZ-700
The BASIC language must be loaded into the MZ-700 before it can be used to do any work. A cassette tape containing this language has been included in the case containing the MZ-700. Now let's teach the language to the computer; procedures for doing this are described below. (The explanation assumes that you are using an MZ-731; however, the procedures are basically the same for all computers of the MZ-
700 series.)
(1) Connect the display as described on page 106. (2) Turn on the power switch located on the back of the computer. (3) The following characters are displayed on the screen and a square, blinking pattern appears. This
pattern is referred to as the cursor.
X* MON I TOR 1 Z-01 3A XX
XSf
t
1
Cursor
(4) Set the cassette tape containing the BASIC language in the computer's data recorder. (5) Type in the word (l][o][a][d| and press the |CR| key. After doing this, the message ± PLAY appears
on the screen.
(6) Press the data recorder's | PLAY | button; the cassette tape starts moving and loading of the BASIC
language begins.
(7) After loading has been completed, the message READY is displayed and the cursor starts to
blink again.
Notes:
* i [IS®!! . . . This is the instruction for loading programs or data from cassette tape.
| CR| This is referred to as the carriage return key, and is mainly used to indicate comple-
tion of entry of an instruction.
13
Page 16
r
** MSNfTOR 1Z-013A**
LOAD J. PLAY L3ADING BASIC '
BASIC INTERPRETER 1Z-01SBVX.XX
CorrKIQHT 1^83 By SHARP COW
XXXXX BYTES
READY
> 8
This completes loading of the BASIC program. You can talk to the computer using BASIC, and the
computer will respond.
1.3.3 Try Executing a Program
Loading BASIC into the computer doesn't cause it to do anything; first, it must be given instructions in BASIC as to what it is to do. Although we will not explain the instructions of BASIC until later, let's go ahead and try executing a BASIC program right now.
Remove the cassette tape from the recorder and turn it over so that the "B" side is up. A sample program is recorded on this side of the cassette tape. Using the following procedures, load this program into the computer and execute it.
(1) After turning the tape over and reloading it into the recorder, press the REWIND button to
rewind it. Next, type in [2[0][a][d] and press the |CR| key; when the message ± PLAY is display- ed, press the I PLAY | button on the data recorder. This begins loading of the sample program.
(2) When loading is completed, the cassette tape stops, READY is displayed on the screen, and the
cursor starts to blink again.
(3) Now that the program has been loaded into the computer's memory, try executing it. This is done
by typing in [r]|u]|n] and pressing the |CR| key.
(4) Now let's take a peek at the program. Hold down the 1 SHIFT key and press the 1 BREAK-]
key. This stops program execution and displays the words BREAK and READY, then the cursor starts to blink again.
(5) Type in [I][T][s][t] and press the | CR| key. This lists the lines of the program on the screen one
after another. (Output of the list can be temporarily stopped at any time by pressing the space bar.)
(6) If you wish to resume program execution, type in [r][u][n] again and hit the |CR[ key. (7) If you want to run a different program, set the cassette tape containing that program in the
recorder, LOAD the program, then RUN it. The previous program is automatically erased from memory when the new one is loaded, so the computer contains only "the BASIC language and the last program loaded.
14
Page 17
BASIC
BASIC Programming
Page 18
2.1 Introduction to Programming in BASIC
2.1.1 Direct Mode
Now that you have made some key entries on the MZ-700, you have reached the point where you are ready to start learning how to program. Before you start, however, try using the MZ-700 as you would an ordinary pocket calculator. (This is called operating the MZ-700 in the "direct mode".) Key in the following, just as you would on a pocket calculator.
f4ll+ll9lFllCRl
As you can see, the computer doesn't do anything when it is presented with a problem in this form;
your computer and an ordinary calculator are completely different in this respect, and instructions must
be entered in a form which can be understood by the computer (i.e, in the form prescribed by the BASIC language). Now try typing in the following.
fpiRimfNim SEEDER]
If you have done this correctly, the number "13" will be displayed and the screen will appear as shown below.
READY PR I NT
1 3
READY
Now let's try doing a somewhat more complex calculation.
With BASIC for the MZ-700, the operators (symbols) for the basic arithmetic operations are as follows.
Addition: + Subtraction: Multiplication: X (the asterisk) Division: / (the slash) Exponentiation: T
When symbols such a " X ", " + ", and " T " are mixed together in a single arithmetic expression,
the order in which calculations indicated by the symbols are performed is referred to as their priority. Just as with ordinary algebra, operations can be included in parentheses, so operations within the inner- most set of parentheses are performed first. Within a set of parentheses, exponentiation is performed
first, followed by multiplication and division (which have equal priority, and therefore are performed
as they are encountered in the expression, from left to right), and then by addition and subtraction.
For example, to obtain the answer to the expression 3 x 6 x C6 + 3 x !9 - 2 x (4 - 2) + II enter the
following.
4 + 9
PRINT is an instruction which tells the computer to display something on the screen. Here, the computer is instructed to display the sum of 4 + 9.
tsemem simsHEmsBEEBEEmHiBEnBfflmm
Now try using the computer to do a variety of other problems in arithmetic.
16
Page 19
[EXERCISE]
[ANSWER]
6 + 4
6-4
2. 3X I5 + 9X (9-2)I +5
PR I NT (6+4)/(6—4)
5
PRINT 3X(5+9X(9-2)-6/(4-2)>+5
200
3. (3 + 4) x (5 + 6)
10+20
4.
5.
6x(2 + 3)
After going through the exercises, try typing in [T][I]@[8] and pressing the [CR| key; the answer "40" is displayed. The reason for this is that BASIC interprets the question mark in the same manner as the instruction PRINT. Remember this as a convenient, abbreviated form of the PRINT instruction.
Now try entering the following. (The quotation marks are entered by holding down | SHIFT and
pressing the [2] key.)
EememmsoEH EH
As you can see, the characters within quotation marks are displayed on the screen, but the answer is not. Now try entering the following.
6
10+20
x (2 + 3)
PRINT (3+4)X(5+6)
77
PRINT (1 0+20) /6X(2+3)
25
PRINT (1 0+20) /(6XC2 + 3))
1
EOfflmOTEOGEElGHEE]
This causes ABCDEFG to be displayed on the screen.
In other words, using the PRINT instruction together with quotation marks tells the MZ-700 to display characters on the screen exactly as they are specified between quotation marks. The characters within any set of quotation marks are referred to as a "character string" or "string".
Now go on to enter the following.
EememEmsBEBmssiHEJEE]
This causes the following to be displayed on the screen.
4 + 9 = ^1 3 (The "i_," symbol indicates a space. Actually, nothing is display-
ed on the TV screen in the position indicated by this symbol.) In other words, the instruction above tells the computer to display both the character string "4 + 9 =" and the result of the arithmetic expression "4 + 9 =". Now try entering the following.
fpiiRimif^mrni^RfoiFiFirTii^i+ifQiicH
After typing in this entry, the following should be displayed on the screen.
4 + 9 =
The reason the screen appears different this time is because the PRINT instruction displays items of information (character strings or the results of arithmetic expressions) differently depending on whether they are separated from each other by semicolons or commas.
Semicolon ( ;) Comma ( ,) .
1 3
Instructs the computer to display items immediately adjacent to each other. Instructs the computer to display the item at the position which is 10 spaces (columns) from the beginning of the display line.
Page 20
If you have the MZ-731 (or a separate plotter-printer), now try appending the characters T/Pj to the
end of the word PRINT.
BemPfflOTHsm^FFimsm^ERi
This time nothing appears on the display screen, but the same result is printed out on the plotter-printer.
In other words, the T/Pj symbols switch output from the display to the plotter-printer.
This completes our explanation of procedures for using the MZ-700 as you would a pocket calculator.
Note: PRINT "5 + 8 ="; 5 + 8 displays 5 + 8=13, while PRINT
The reason for this is that one space is always reserved for a symbol indicating whether the result is positive or negative, but the symbol is only displayed in that space when the result is negative.
11
5 - 8 ="; 5 - 8 displays 5 - 8 = -3.
2.1.2 Programming
Let's try making a simple program. However, first let's make sure that the area in the computer's memory which is used for storing programs is completely empty. Do this by typing in NEW and pressing the|CRlkey. (This instruction will be explained in more detail later; see page 32.)
Type in the following program exactly as shown.
1 0 A = 3EE] Assigns the value 3 to A.
20 B = 6[CR] Assigns the value 6 to B. 30 C=A + Bffl Assigns the result of A + B to C. 40 9 OICRI Displays the value assigned to C.
50 E N PICRI Instruction indicating the end of the program.
The numbers 10, 20, 30, and so forth at the left end of each line are referred to as program line numbers, or simply line numbers; these numbers indicate the order in which instructions are to be executed by the
computer. Instructions on the lowest numbered line are executed first, followed by those on the next
lowest numbered line, and so forth. Line numbers must be integers in the range from 1 to 65535.
The line numbers 1, 2, 3, and so forth could have been used in this program instead of 10, 20, 30. However, it is common practice to assign line numbers in increments of 10 to provide room for later insertion of other lines.
Now let's check whether the lines have been correctly entered. Type in LIST and press the |CR[ key; this causes a list of the program lines to be displayed. Notice that the question mark entered at the beginn- ing of line 40 has been converted to PRINT, the full form of the command for displaying data on the display screen.
Page 21
Novelet's try executing the program.
[RlPfNlfCRl
Enter RUN and press the |CR| key; the result is displayed on line 9 of the screen.
Now we will explain procedures for making changes in programs. First, let's change the instruction on line 20 from B = 6 to B = 8. Type in LIST 20 and press the [CR] key; this displays just line 20 of the program on the screen. Next, use the cursor control keys (the keys at the right side of the keyboard which are marked with arrows) to move the cursor to the number r6j, then press the 00 key and the |CR| key in succession to make the change. Note that the change is not completed until the|CR|key is pressed.
Now type in LIST and press the |CR| key again to confirm that the change has been made.
Next, let's change line 30 of the program to C = 30 X A + B.
Using the cursor control keys, move the cursor so that it is positioned on top of the "A" in line 30, then press the | INST | key three times in succession. This moves "A + B" three spaces to the right.
Cursor position
Now type in [3][o][x] and press the |CR| key to complete the insertion. LIST the program to confirm that the change has been made correctly.
Now change line 30 again so that it reads "C = 30 X A" instead of "C = 30 X A + B". Do this by
moving the cursor to the position immediately to the right of B and pressing the | DEL 1 key two times; this deletes "+B". Press the |CR| key to complete the change.
Now LIST the program and confirm that it appears as shown below.
1 0 A = 3 20 B = 8 30 C=30XA 40 PR I NT C 50 END
To delete an entire line from a program, simply enter the line number of that line and press the |CR| key;
delete line 20 in this manner, then LIST the program to confirm that the line has been deleted.
We could insert the instruction "?A" between lines 30 and 40, by typing in 35_?A and pressing the
|
CR[
key. Try this, then LIST the program to confirm that the line has been added. Now delete line 35 by
entering 35 and pressing the |CR| key.
The process of changing or inserting lines in a program in this manner is referred to as editing, and the program which results from this process is referred to as the BASIC text. Each line of the program can include a maximum of 255 characters, including the line number, but the maximum length is reduced
by four characters if the question mark is used to represent the PRINT instruction.
At this point, the program contained in the computer's memory should be as follows.
1 0 A = 3 30 C=30XA 40 PR I NT C
50 END
Now we will use this program to explain the procedures for recording programs on cassette tape.
Prepare a blank cassette tape (one on which nothing has been recorded) and set it in the data recorder,
19
Page 22
then type in the following from the keyboard.
11
SAVE
CALCULATION" J
Here, "CALCULATION" is the name which is to be recorded on the cassette tape to identify the
program. Any name may be assigned, but the name connot be longer than 16 characters.
Note: The J symbol in the example above represents the |CR| key.
When the[CR]key is pressed, " ± RECORD. PLAY" is displayed on the screen. Pressing the I RECORD!
button on the data recorder at this time records the program on cassette tape.
The name which is assigned to the program is referred to as its file name. Specification of a file name is not absolutely necessary, but from the point of view of file management it is a good idea to assign one. Of course, the file name is recorded on the tape together with the program.
When recording is completed, READY is displayed to indicate that the computer is finished. Now press the STOP button on the data recorder and rewind the tape.
The program is still present in the computer's memory after recording is completed, so type in NEW J
to delete it (enter LIST J to confirm that the program has been deleted). Now let's try using the LOAD instruction to load the program back into memory from the cassette tape as described on page 14.
When a cassette tape contains many programs, that which is to be loaded can be identified by specifying the program's file name together with the LOAD instruction as follows.
LOAD "CALCULATION" J
Specifying the file name in this manner tells the computer to ignore all programs on the tape other than that with the specified name. If the file name is not specified (if only LOAD J is entered), the computer
loads the first program encountered.
Note: When using cassette recorder other than the data recorder built into the MZ-731, and MZ-721 read
the instructions on page 109 before attempting to record or load programs.
The LIST command shown above can be used in a variety of different ways. For example, during
editing LIST 20 J can be used to display just line 20 of a program. The entire program can be listed by entering LIST J . Other uses of the instruction are as follows.
omisim BlllCRl Lists all lines of the program to line 30.
•mem [3][0]B[CH] Lists all lines from line 30 to the end of the program,
•mom mEBEEaEE] Lists all lines from line 30 to line 50. omem mSJESBl Lists line 30.
When editing programs by listing individual lines with the LIST instruction, press the [ CLR | key (the
| INST | key) together with the | SHIFT ~| key when the screen becomes distractingly crowded. This
clears the entire screen and moves the cursor to its upper left corner. (This does not affect the program
in memory). Afterwards, enter LIST < line number > J again to list the line which is to be edited.
20
Page 23
2.2 An Outline of BASIC
2.2.1 Constants
A constant is a number or string of characters which is written into a program, and which is used by that program as it is executed. Types of constants include numeric constants, string (character) constants, and system constants. These are explained below.
Numeric constants
A numeric constant is a number which has a maximum of 8 significant digits. The exponent of such constants must be in the range from 10"38 to 1038 (the maximum range is 1.548437E-38 to 1.7014118E
+38).
(Examples:)
-1 23. 4
0. 789
3748. 0
3. 7E + 1 2 3. 7X1012 1
7. 65E-9 7. 65X10"9 E indicates the exponent. 1 4. 8E9 1 4. 8X109 J
Hexadecimal numbers: Numbers can be specified in hexadecimal format only for direct memory addressing with the LIMIT, POKE, PEEK, and USR instructions (see pages 92 and 93), and are repre- sented as four digits preceded by a dollar sign ($).
(Examples:)
LIMIT SBFFF
USR CSC000, XS) X$ represents a string variable.
String constants
String constants are letters and symbols between quotation marks which are included in programs to allow titles or messages to be output to the display screen or printer. The characters " 4+9" appearing on page 17 are a character constant, and not a numeric constant. With BASIC, a string constant may consist of a maximum of 255 characters. (Not including quotation marks which cannot be included in a string constant.)
. (Examples:)
11
ABCDEFG
11
1 2345678910 "
DATA ABCDEFG Quotation marks are not needed when string constants are
11
specified in a DATA statement; however, they may be used if desired.
21
Page 24
2.2.2 Variables
The word "variable" has a different meaning with BASIC than it does when used with regard to alge-
braic expressions. To put it in very simple terms, the variables of BASIC are "boxes" in memory for
the storage of numbers and characters (character strings). The types of variables used in BASIC include
numeric variables, string variables, and system variables.
Numeric variables String variables
System variables
SIZE
Numeric variables
Only numeric data can be stored in numeric variables. Names must be assigned to these variables in accordance with the following rules. i) A variable name may consist of any number of characters, but only the first two characters are
actually used by the BASIC interpreter to identify the variable. Further, the first character of the
variable name must be a letter (A to Z), either letters or numerals may be used for subsequent
characters.
ii) It is not possible to use the names of BASIC commands and statements as variable names.
Correct variable names: ABC, XY, ABCD, A12345
(ABC and ABCD are regarded as the same variable.)
Incorrect variable names: PRINT (PRINT is a BASIC statement)
C@ (Variable names may not include special charac-
ters.)
(Example:)
1 0 A = 5 Stores 5 in variable A. 20 PRINT A Displays the value stored in variable A.
22
Page 25
String variables
String variables are variables which are used for storing character strings. Names assigned to string variables must conform to the same rules as those assigned to numeric variables; however a dollar sign ($) is appended to the end of string variable names to differentiate them from other types of variables.
String variables may be used to store a maximum of 255 characters. Such variables are blank until string data is assigned to them.
The only operator which can be used in expressions including more than one string variable is the
"+" sign.
(Example:)
10 A$= " A BCD " Substitutes the character string ABCD into string variable A$. 20 B$= " XYZ " Substitutes the character string XYZ' into string variable B$. 30 C$ = A$ + B$ Substitutes the sum of string variables A$ and B$ (ABCDXYZ)
into string variable C$.
40 PRINT CS Displays the contents of string variable C$.
System Variables
System variables contain values which are automatically changed by the BASIC interpreter. The system
variables are size (the variable which indicates the amount of BASIC free area) and TI$ (a 6-digit variable
which contains the value of the system's 24-hour clock).
(Examples:)
10 T I $= " 01 3500 " •• This statement assigns the value corresponding to 1:35:00 A.M.
to system variable TI$ and sets the system clock to that time.
20 PR I NT T I S Executing this statement displays the current time of the system
clock (24-hour time).
Display format:
132819 Indicates that the time is 13:28:19.
PR I NT S I Z E J This displays the current amount of free space in the computer's
memory (in other words, the amount of space which is available
for additional program lines). The value indicated by this variable is reduced each time a program line is entered.
23
Page 26
2.2.3 Arrays
Arrays can be thought of as shelves within the computer's memory which contain rows of boxes, each
of which represents a variable. The boxes on these shelves are arranged in an orderly sequence, and are identified by means of numbers; these numbers are referred to as subscripts, because they are subscripted to the name which identifies the entire group of boxes.
Such shelves of boxes are set up simply by executing an instruction which declares that they exist; this is referred to as making an array declaration. The array declaration specifies the number of boxes which are to be included in each set of shelves (i.e., the size of the shelves) and the manner in which they are to be arranged.
The boxes in each unit of shelves may be arranged in sequences which have any number of dimensions. Thus, a one-dimensional array can be thought of as a single shelf which holds, one row of boxes; a two- dimensional array can be thought of as a stack of shelves, each of which holds one row of boxes; and so forth. These boxes, or variables, are referred to as the array's elements.
The number of subscripts used to identify each of the array elements of a corresponds to the number of dimensions in that array. For example, each of the elements in a one-dimensional array is identified by a single subscript which indicates the box's position in the row; each of the elements in a two dimensional array is identified by two subscripts, one which identifies the box's row, and one which indicates the box's position within that row; and so forth. The numbers which are used as the subscripts start with zero, and have a maximum value which is determined by the size of each of the array's dimensions (i.e., the number of boxes in each row, etc.).
The maximum size of an array is limited by the amount of free space which is available in the com- puter's memory (i.e., by the size of the program, the number of items of data which are to be stored in the array, and so forth). The syntax of BASIC places no restrictions on the number of dimensions which can be used for any array, but in practice the number of dimensions is limited by the amount of free memory space which is available for storage of array variables.
An array must be declared before values can be stored in any of its elements.
Page 27
(Example 1)
10 DIM
20 DIM
10 DIM ACS), XSC8) Performs the same function as lines 10 and 20 above.
(Example 2)
10 DIM BC5, 5) Declares 2-dimensional numeric array B with 6x6
20 DIM YSC5, 8) Declares 2-dimensional string array Y$ with 6 x 9 elements.
10 DIM BC5, 5), YSC5, 8), AC5), XSC8) Declares two numeric arrays
(Example 3)
10 DIM CC3, 3, 3) Declares 3-dimensional array C with 4x4x4 elements.
Note: Different names must be used for each array which is declared; for example, the instruction DIM
A(5), A(6) is not a legal array declaration.
A(5)- X$(8)
Declares 1-dimensional numeric array A with 6 elements. Declares 1-dimensional string array X$ with 9 elements.
elements.
and two string arrays.
Try executing the program shown below and check the results which are obtained.
10 DIM AC2), BSC2) 20 A(0)=26 30 AC1 )= 9 40 A(2) = 1 00 50 B$(0)= "ABC ". 60 B$(1 )= " XYZ " 70 B$(2)= " MZ-700 " 80 PR I NT AC1 ) 90 PR I NT B$(2)
1 00 PR I NT AC2)
110 PRINT B$(0)+B$(1)
1 20 PR I NT A(0)
Note: Individual variables within an array, such as A(5) and X$(8), are referred to as an array's elements.
Numeric constants, numeric variables, and numeric arrays are collectively referred to as numeric expressions, and string constants, string variables, and string arrays are collectively referred to as string expressions.
25
Page 28
2.2.4 BASIC Operations
In BASIC, arithmetic operations take a slightly different form than is the case with ordinary arithmetic. The various arithmetic operators used in BASIC are shown in the table below. The priority of these operators when they are used together within a single expression (the sequence in which the different arithmetic operations are performed) is as indicated by the numbers in the left column of the table; however, operators within parentheses always have the highest priority.
Arithmetic operations
Operator
1 t
2
3
4 Plus, minus
Operation Format
Exponentiation X t Y (Indicates XY; i.e., X to the Yth power.)
Negation
Multiplication,
division
-X
X X Y (X times Y), X/Y i.e., X divided by Y)
X + Y (X plus Y), X - Y (X minus Y)
(Example 1)
1 0 A=3X8/4 When a series of operators with the same priority are used in
an arithmetic expression, calculations are carried out from left to right; thus, the result of the expression at left is 6.
(Example 2)
10 A = 60-6X8 + 2---- Result is 14.
20 B= (60-6) X8 + 2 Result is 434.
(Example 3)
10 A = 2 T 3 Assigns 2 to the 3rd power to A; result is 8.
String operations
String operations are used to create new strings of character data by concatenating (linking) two or more shorter strings. The only operator which can be used in string operations is the "+" sign.
(Example)
PRINT " ABC " + " DEF " J » Displays the character string "ABCDEF".
26
Page 29
2.2.5 Initial settings
Initial settings made when BASIC 1Z-013B is started are as described below.
Keyboard
1) Operation mode: Normal (alphanumeric)
2) Definable function keys
RUN" +CHRS (1 3) L I ST" AUTO" RENUM" COLOR"
Note A carriage return code is included in the definition of function key F1 .
Built-in clock The initial value set to system variable TI$ is "000000".
Music function
1) Musical performance tempo: 4 (moderato, approximately medium speed)
2) Note duration: 5 (quarter note J )
Control keys and control characters The control keys are keys which perform special functions when pressed together with the I CTRL I key.
Functions of these keys and their corresponding ASCII codes are as shown in the table below.
I SH I FT l +
I
SH I FT l+ I SH I FT l + I SH I FT l + I
SH I FT 14-
CHR$ ("
DEF KEY C CONT" SAVE" LOAD"
Control codes]
CTRL +
E
F
M 13
P
Q
R S
T 20 U V
W
X Y
Other The lower limit of the BASIC text area is set to address SFEFF; this is the same as LIMIT MAX is
executed).
For initial printer settings, see the discussion of the printer.
ASCII code
(decimal)
5
6
16 17 18 19
21 22
23 24
25
Function
Selects the lowercase letter input mode for alphanumeric characters. Selects the uppercase letter input mode for alphanumeric characters. Carriage return (|CR[). Same as the | DEL 1 key.
Moves the cursor down one line (O). Moves the cursor up one line (Hi). Moves the cursor one column (character) to the right (H). Moves the cursor one column (character) to the left (•). Moves the cursor to the home position ([ HOME |). Clears the screen to the background color ([ CLR ]). Places the computer in the graphic character input mode
(1 GRAPH |). Inserts one space (| INST |). Places the computer in the alphanumeric input mode.
-27
Page 30
2.3 Frequently Used BASIC Commands and Statements
2.3.1 Program file input/output instructions
2. 3. 1. 1 LOAD (abbreviated format: LO.)
Format
Function
Note
LOAD or LOAD 1 filename" This command loads the specified BASIC text file or a machine language file to be linked with a BASIC program from cassette tape.
(See pages 14 and 20.)
Only BASIC text files and machine language programs can be loaded with this command. When the file to be loaded is a BASIC text file, the current program is cleared from the BASIC text area when the new program is loaded. When loading a machine language routine to be linked with a BASIC program, the LIMIT statement must be executed to reserve a machine language progam area in memory. Further, the applicable machine language program file is executed as soon as loading is completed if the loading address is inside that area. (In this case, the BASIC text is not erased.)
The LOAD command can be used within a program to load a machine language program file.
SOOOO
Monitor
$1 200
BASIC interpreter
BASIC text area LIMIT ($9FFF)
($ AOOO)
Machine language area
SFEFF
Note: The lower limit of the BASIC text area shifts according to the size the program text loaded.
28
Page 31
2. 3. 1. 3
VERIFY
Function This command assigns a file name to the BASIC program in the computer's memory
and saves it on cassette tape.
(abbreviated format: V.)
Type in SAVE "NAME" [CRl.
Note
Assign any name of up to 16 characters.
Screen display ( <f RECORD ' PLAY ) Ready for recording!!
o
Tape recorder operation
Press the
RECORD
1
button. ) Recording start!!
o
Screen display WRITING
Screen display
This command saves only the BASIC program text (i.e., the program text displayed by executing the LIST command); it does not save any machine language program in the machine language area. The file name specified is recorded on tape together with the BASIC text file; specify any name desired using up to 16 characters. If no file name is specified, the program is recorded without a file name; however note that this can make file management difficult if more than one program is recorded on a single tape.
-
"NAME J Recording in progress.
NAME is not displayed if no pro-
o
READY^) Recording completed!!
gram file name has been specified.
29
Page 32
2. 3. 1. 3 VERIFY
(abbreviated format: V.)
Format
Function
VERIFY
L
(3) A PLAY is displayed on the TV
(S
VERIFY or VERIFY "filename" This command is used to confirm that programs have been properly recorded on tape by the SAVE command. This is done by playing the tape and comparing the program read with the program contained in memory. If both programs are the same, "OK" is displayed; if they are different, "READ error" is displayed.
In the latter case, save the program again.
I want to check whether my program has been properly recorded. . .
Then use the VERIFY comand!
(1) Rewind the tape.
screen.
(4) Press the |PLAY[ button on the data recorder
(2) Type in VERIFY "NAME' ("NAME" is not necessary if no
file name has been assigned).
!5) FOUND "%. This is displayed if the program finds another program
d
J ^ \ ^Jy V
06) FOUND "NAME" Displayed when the program to be verified is found.
before that which is to be verified. If that program has
a name
. it is displayed where indicated by "% x x x
V ^
(8) READ error, /~(7) VERIFYING "NAME
READY Indicates that the tape file is being Indicates that the progrannwas\J compared with the program in not correctly recorded; re-record)\rnemory. it with the SAVE command.
30
Page 33
2.3.2 Text editing commands
2. 3. 2. 1 AUTO
Format
Function
Example
(abbreviated format: A.)
AUTO or AUTO Ls, n
Ls Starting line number n Line number increment
This command automatically generates program line numbers during entry of BASIC program statements.
(Example 1)
AUTO J
1 0 J 20 J 30 J
(Example 2)
AUTO 300, 300 305
5 J
.... j
....
.... J
31 0
Automatically generates program line numbers with an increment of 5, starting with line 300.
(Example 3)
AUTO 100J
1 00 J 1 1 0 J 1 20 J
Generates program line numbers with an increment of 10, starting with line 100.
(Example 4) AUTO, 20J
1 0 J
30 J
50 J
Generates program line numbers with an increment of 20, starting with line 10.
Note: The AUTO command is terminated by pressing | SHIFT | and| BREAK |.
2. 3. 2. 2 DELETE (abbreviated format: D.)
Format
DELETE Ls-Le- DELETE -Le
Deletes program lines from Ls to Le. Deletes all program lines from the beginning of the program to line Le.
DELETE Ls-
Deletes all program lines from line Ls to the end of the program. Deletes line Ls. DELETE Ls
Example
(Example 1) DELETE 1 50—350J Deletes all program lines from 150 to 350. (Example 2)
DELETE -1 00J--
•Deletes all program lines up to line 100.
(Example 3)
DELETE 400-J--
•Deletes all program lines from 400 to the end of the program.
31
Page 34
2. 3. 1. 3 VERIFY (abbreviated format: V.)
Format
LIST LIST Ls—Le Ls indicates the starting line number and Le indicates LIST Ls the ending line number. L I ST -Le .
Function
This command lists all or part of the program lines contained in the BASIC text area on the display screen.
LI ST J LIST -30 LIST 30
J
J
LIST 30—50 LIST 30
J
J
Lists the entire program. Lists all lines of the program to line 30. Lists all lines of the program from line 30 to the end.
; Lists all lines of the program from line 30 to line 50.
Lists line 30 of the program. Output of the program list to the display screen can be temporarily interrupted by pressing the space bar; listing is then resumed when the space bar is released. To terminate list output, press the | BREAK ] key together with the 1 SHIFT ] key.
2. 3. 2. 4 LIST/P (abbreviated format: L./P)
Format
LIST/P <Ls—Le>
Ls Starting line number Le Ending line number
Function
This command lists all or part of the program in the BASIC text area on the printer.
The range of program lines to be listed is specified in the same manner as with the
LIST command described above.
Note: The angle brackets < . . . > in the above indicate that the enclosed item is optional.
2. 3. 2. 5 MERGE (abbreviated format: ME.)
MERGE or MERGE " filename"
The MERGE command is used to read a program from cassette tape. When a pro-
gram is read using this command, it is appended to the program in memory. If
"filename" is omitted, the computer reads the first file encountered on the cassette tape.
If any line numbers in the program read are the same as those of the program in memory, corresponding lines of the program in memory are replaced with lines of the program read.
2. 3. 2. 6 NEW
Format
Function
NEW The NEW command erases the BASIC text area and clears all variables. Execute this command when you wish to clear the program in memory prior to entering another program. This command does not erase the machine language area reserved by the LIMIT statement. Since the BASIC text area is automatically cleared by the LOAD command, it is not necessary to execute this command before loading a BASIC program from
cassette tape.
32
Page 35
2. 3. 2. 7 RENUM
(abbreviated format: REN.)
Format
Function This command renumbers the lines of a BASIC program. When this command is
RENUM RENUM Ln RENUM Ln, Lo, n
executed, line numbers referenced in branch statements such as GOTO, GOSUB, ON ~ GOTO, and ON ~ GOSUB are also reassigned.
RENUM Renumbers the lines of the current
RENUM 100 Renumbers the lines of the current
RENUM 1 00, 50, 20 Renumbers lines of the current program
Ln .... New line number
Lo .... Old line number
n Increment
program in memory so that they start with 10 and are incremented in units of 10.
program in memory so that they start with 100 and incremented in units of 10.
in memory starting with line number 50; line number 50 is renumbered to
100, and subsequent line numbers are
incremented in units of 20.
Example~| The example below shows the result of executing RENUM 100, 50, 20 for a sample
program.
(Before renumbering) (After renumbering)
50 A = 1 60 A=A+1 70 PR I NT
100 GOTO
Note When specifying the new and old line numbers, the new line number specified must
be larger than the old line number. Note that an error will result if execution of this
command results in generation of a line number which is greater than 65535.
A
60
100 A=1 120 A=A+1
'l 40 PRINT A
160 GOTO 120
Page 36
2.3.3 Control commands
2. 3. 1. 3 VERIFY (abbreviated format: V.)
Format
Function
7 3 1 mNT
RUN or RUN Ls
Ls . . . . Starting line number
This command executes the current program in the BASIC text area. If the program is to be executed starting with the first program line, just enter
RUN and press the |CR| key. If execution is to begin with a line other than that the lowest line number, type in RUN Ls (where Ls is the line number at which execution is to start) and press the When this command is executed, the BASIC interpreter clears all variables and arrays before passing control to the BASIC program.
CONT The CONT command is used to resume execution of a program which has been interrupted by pressing | SHIFT ~| + 1 BREAKl or by a STOP statement in the program. This command can also be used to continue execution of a program which has been interrupted by an END statement; however, in this case care must be taken
to ensure that lines following the END statement are not the lines of a subroutine. Examples of situations in which the CONT command can and cannot be used are
shown in the table below.
[CR]
key.
(abbreviated format: C.)
Program continuation possible
Program execution stopped by pressing | SHIFT | + | BREAK |.
Program execution stopped by a STOP command.
Program execution stopped by pressing | SHIFT | + | BREAKl while the program was a waiting input for an INPUT statement.
Program continuation not possible
Before a RUN command has been executed.
"READY" displayed due to an error occurring during program execution.
Cassette tape operation interrupted bv pressing I SHIFT | + | BREAK j.
Program execution stopped during execution of a MUSIC statement.
Program execution stopped and
"READY" displayed after
execution of an END statement.
34
Page 37
2. 3. 3. 3 BYE (abbreviated format: B.)
BYE This command returns control of the computer from BASIC interpreter 1Z-013B to the monitor program in RAM. (The monitor commands are explained starting
on page 99.)
2. 3. 3. 4 KEY LIST (abbreviated format: K. L.)
KEY LIST This command displays a list of the character strings assigned to the definable functions keys.
KEY L 1 ST
11
DEF KEY (1 ) = DEF KEY (2) =
RUN " +CHR$ (1 3)
11
L I ST'" DEF KEY (3) = " AUTO " DEF KEY
(4) = «
DEF KEY (5) = DEF DEF DEF
KEY (6) = KEY KEY
(7) = " DEF KEY ( " (8) = "
DEF KEY (9) =
DEF
KEY (1 0) =
RENUM"
11
COLOR"
11
CHRS ("
CONT "
11
SAVE "
"LOAD"
READY
35
Page 38
2.3.4 Assignment statement
LET
Format
Function
LET v = e or v = e
v . . . Numeric variable or array element, or string variable or array element.
e . . . Numeric expression (consisting of one or more constants, variables, or array
elements) or string expression (consisting of one or more constants, variables, or array elements).
This statement assigns the value (numeric or string) specified by e to the variable
or array element specified by v. As shown in the examples below, LET may be omitted.
Example
1 0
A = 1 0
B = 20
20
A=A + B
30 40
The following are examples of incorrect use of the LET statement.
20 A$ = A + B Invalid because different types of variables (string and
20 LOG (LK) =LK + 1 Invalid because the left side of the statement
PRINT A END
50
RUN J
30 The two programs above produce exactly
numeric) are specified on either sides of the "=" sign.
is not an numeric variable or array element.
1 0
LET
20 LET
LET
30
PR I N
40
END
50
the same result.
Page 39
2.3.5 Input/output statements
Input/output statements are the means by which data is submitted to the computer for processing,
and by which the results of processing are output to the TV screen or printer.
2. 3. 5. 1 PRINT
Format
Function
PRINT variable
1 ? expression
This statement outputs the values of variables, constants, character strings, or expressions to the display screen. Values are displayed starting at the cursor's
current location on the screen. (To move the cursor down one line on the screen, execute the PRINT statement without specifying any variables, constants, or ex- pressions.) To simplify key input when entering this statement, a question mark (?) may be typed instead of the word PRINT.
Numeric data is displayed by this statement in one of two formats: real number format or exponential format.
Real number format
Numeric values in the range from 1 x 10"8 to 1 x 108 are displayed in real
number format.
-1 - 9999 63598757
constant
<
variable
constant .expression
J
0. 00000001
99999999
>
1 x 10
-8
Exponential format
Numbers which cannot be displayed in real number format are displayed in
exponential format.
-.3141 5E + 9 —0.31415 x 10 . 51 3606E —20 0.513606 x 10"
A plus (+) or minus (—) sign is always displayed ahead of the exponent (the number following "E") of a number displayed in exponential format.
Some special methods of using the PRINT statement are shown below.
PR I NT
PR I NT
PR I NT PR I NT PR I NT PR I NT
Clears the entire screen and moves the cursor to the home position (the upper left corner of the screen). Moves the cursor to the home position without clearing the
screen.
Moves the cursor one column to the right.
D
Moves the cursor one column to the left.
a
Moves the cursor up one line. Moves the cursor down one line.
9
:20
37
Page 40
PR I NT "BDDDDDA" Clears the screen, then displays the character "A" at the begin-
ning of the sixth line from the top.
Note: The vertical bars I...I in the format description indicate that any one of the enclosed items may
be selected.
To enter the special characters for cursor control, press the | GRAPHl key; this places BASIC in the
graphic character input mode and changes the form of the cursor to "11". Next, enter the characters as follows.
CLR
key.
HOME 1 key.
key. key. key.
E)
Press the Press the Press the Press the Press the
Press the key.
After entering a special character, press the I ALPHA |key to return from the graphic character input
mode to the alphanumeric input mode.
2. 3. 5. 2 PRINT USING (abbreviated format: ?USI.)
38
Format
Function
PRINT USING " format string"; variable <
variable . . . >
This statement displays data on the screen in a specific format. The format specifi-
cation consists of a character or string of characters in quotation marks, and is specified immediately after the word USING as follows. (1) Format specification strings for numeric values
(a) #
The number sign is used to specify the maximum number of digits to be displayed. If the number of digits in the number displayed is smaller than the number of # signs specified in "format string", numbers are right-
justified in the field defined by that string.
(Example:)
10 A= 123
20 PRINT USING "####" ; A RUN J
123
Page 41
A period may be included in a format string consisting of # signs to specify
the position in which the decimal point is to be displayed. The number of # signs to the right of the decimal point specifies the number of decimal places to be displayed.
(Example:)
10 A = 12.345 :B = 6.789 20 PRINT USING "###.##" ; A 30 PRINT USING "###.##" ;B RUN J
^ 12.34
^6.79
(c) ,
Commas may also be included in "format string" to indicate positions in which commas are to be displayed. Numbers are right-justified in the same manner as when # signs are used alone.
(Example:)
10 A= 6345123 : B = 987324
20 PRINT USING "#,###,###" ;A
30 PRINT USING '#,###,###" ;B RUN J 6,345,123 ^987,324
(d) + and -
A plus (+) or minus (—) sign may be included at the end of "format string" to specify that the sign of the number is to be displayed in that position instead of a space. For instance, PRINT USING " ####+" will cause the sign to be displayed immediately after the number. (PRINT USING "####-"
causes a minus sign to be displayed following the number if the number is
negative; if the number is positive, only a space is displayed in that position.) Further, a plus sign may be specified at the beginning of a format string to indicate that the number's sign is to be displayed in that position regardless
of whether it is positive or negative. (Examples)
PRINT USING " ####+11 ; -13
t-,^ 13
PRINT USING +####" ; 25
(Note:)
Although a minus sign will be displayed if one is specified at the beginning of the format string, it will have no relationship to the sign of the number.
39
Page 42
(e) XX
Specifying a pair of asterisks at the beginning of the format string indicates that asterisks are to be displayed in the positions of leading zeros. (Example:)
10 A= 1234
20 PRINT USING " X X####" ; A RUN J XX1234
(f) ££
Specifying a pair of pound signs at the beginning of the format string indi- cates that a pound sign is to be displayed in the position immediately to the left of the number. (Example:)
10 A= 123
20 PRINT USING "££####" ; A
RUN J
--£123
(g) $$
Specifying a pair of dollar signs at the beginning of the format string indi- cates that a dollar sign is to be displayed in the position immediately to the
left of the number.
(h) t t t t
Four exponential operators may be included at the end of a format string to control display of numbers in exponential format. (Example:)
10 A = 51123
20 PRINT USING "##.### 11 t t " ; A RUN J
-5.112E+04
In this case, the first number sign is reserved for display of the sign of the
number.
(i) Extended list of operands
A list of variables may be specified following a single PRINT USING state-
ment by separating them from each others with commas or semicolons.
When this is done, the format specified in "format string" is used for display
of all resulting values. (Example:) 10 A =5.3 : B = 6.9 :C = 7.123 20 PRINT USING " ##.###" ; A, B, C RUN J
5.300 6.900 ^ 7.123
Page 43
(2) Format specification for string values
(a) !
When the values being displayed are character strings, specifying an excla- mation mark in "format string" causes just the first character of the string specified to be displayed.
(Example:)
10 A$ = CDE"
20 PRINT USING "!" ; A$ RUN J
C
(b) &
Specifying
in the format string causes the first 2 + n charac- ters of specified string expressions to be displayed (where n is the number of spaces between the two ampersands). If fewer than 2 + n characters
are specified in a string expression, characters displayed are left-justified
in the field defined by " & - - - - &".
(Examples:)
10 A$ = "ABCDEFGH
"
20 PRINT USING ; A$ RUN J
ABCDEF
10 A$ = "XY"
20 PRINT USING
11
& ^ - - &" ; A$
RUN J
XY
(3) String constant output function
When any character other than those described above is included in the format
string of a PRINT USING statement, that character is displayed together with the value specified following the semicolon. (Example:)
10 A= 123
20 PRINT USING " DATA####" ; A RUN J
DATA^123
(4) Separation of USING
Usually, PRINT and USING are specified adjacent to each other; however, it is possible to use them separately within the same statement.
(Example:)
10 A= -12 : B = 14 : C = 12
20 PRINT A; B; USING "####" ; C
Normal PRINT function USING function
RUN J
-12-14^12
41
Page 44
2. 3. 1. 3 VERIFY (abbreviated format: V.)
Format
Function
numeric variable
INPUT J string variable
i array element
I NPUT A INPUT B$ I NPUT X(5)
. or INPUT "character string" ; string variable
I NPUT
11
DATA A- INPUT"YES OR I NPUT 1 KEY I N
numeric variable
i array element
=
" ; A
NO";BS
; X (5)
INPUT is one of the statements which is used for entering values for assignment to
variables during program execution. Program execution pauses when an INPUT
statement is encountered to allow values to be typed in from the keyboard. After input has been completed, the values are substituted into specified variables by pressing the |CR| key, then program execution resumes.
(Example:)
1 0 I NPUT A, B 20 C=A+B 30 PR I NT C 40 END
When the program above is executed, a question mark is displayed and the cursor blinks to indicate that the computer is waiting for data input; enter any arbitrary number, then press the|
CRj
key. This assigns the value entered to variable A. After doing this, the question mark will be displayed again. The reason for this is that two variables (A and B) are specified in the INPUT statement on line 10, but only one value has been entered (that which is substituted into variable A). Enter another arbitrary number and press the |CR| key again; this substitutes the second value entered into variable B and causes execution to go on to the next line of the program. In the example above, subsequent lines add the values of A and B, substitute the result into C, then display the contents of C. Since the variables used in this example are numeric variables, the computer will display the message ILLEGAL DATA ERROR if an attempt is made to enter any characters other than numerics. The question mark is then redisplayed to prompt
the user to reenter a legal value (a value whose type is the same as that of the varia- ble or array element into which it is to be substituted). Be sure to enter data whose type matches that of the variable(s) specified in the INPUT statement.
During program execution, it may be difficult to remember what data is to be entered when the question mark is displayed; therefore, prompt strings are usually included in INPUT statements for display on the screen as a reminder. This is done as shown in the program example below.
42
1 0 I NPUT 20 30
I NPUT
PR I NT A + B =
A= " ;
B= " ;
40 PR I NT AB =
PR I NT AXB =
50 60 PR I NT A/B = 70
END
A B
ii
ii ii ii
A + B A-B AXB A/B
Page 45
2. 3. 5. 4 GET
Format
Function
Try running the program shown above. Inclusion of character strings in the PRINT and INPUT statements provides a clear indication of the program's operation. Practical computer programs consist of combinations of sequences similar to the one shown here. By combining commands, statements, and sequences in different manners, you will soon find that there are many different methods of achieving a desired result.
GET v
v Numeric variable or array element, or string variable or array element.
When this statement is encountered during program execution, the BASIC inter- preter checks whether any key on the keyboard is being pressed and, if so, assigns the corresponding value to the variable specified in v. Whereas the INPUT statement prompts for entry of data and waits until that data has been entered before resuming execution, the GET statement continues execution regardless of whether any key is being pressed. Although data is substituted into variable v by the GET statement if any keys are pressed when the statement is executed, the variable will be left empty (0 for a numeric variable or null for a string variable) if no keys are pressed. With numeric variables, this statement allows a single digit (from 0 to 9) to be entered; with string variables, it allows a single character to be entered. This statement can be extremely useful when you want to enter data without pressing the [CR| key, as is often the case with game programs.
(Example:)
PRINT "NEXT
1 0
20
30
GET AS
IF A$="Y" THEN
GOTO 20 Line 40 unconditionally transfers exe-
40
50
PR I NT " PROGRAM END " cution to line 20.
60
This program displays the prompt " NEXT GO? (Y OR N)" and waits for input. When the Y key is pressed, execution moves to line 50 and the program ends.
Now delete lines 30 and 40 and try executing the program again. As you can see, execution is completed immediately regardless of whether any keys have been pressed.
END
Until that time, however, execution loops repeatedly between lines 20 and 40.
Note: When GET statements are executed in succession, a routine should be includ-
ed between them to ensure that each is completed before going on to the
next. The reason for this is that key chatter (vibration of the contacts of
the key switches) may result in two GET statements being executed simul- taneously.
GO? CY OR N)
50-
In the example above, execution
jumps from line 30 to line 50 if the
value of variable A$ is "Y".
43
Page 46
2. 3. 5. 5 READ Format
DATA . .
READ
numeric variable string variable array element
(abbreviated format: REA. ~ DA.) numeric variable j > string variable f array element i
Function
Example
DATA
Like the INPUT and GET statements, the READ statement is used to submit data to the computer for processing. However, unlike the INPUT and GET statements, data is not entered from the keyboard, but is stored in the program itself in DATA statements. More specifically, the function of the READ statement is to read succes- sive items of data into variables from a list of values which follows a DATA state- ment. When doing this, there must be a one-to-one correspondence between the
variables of the READ statements and the data items specified in the DATA state-
ments.
(Example 1)
1 0 READ A, B, C, D 20 PRINT A;B;C;D 30 END 40 DATA 10. 100, 50, 60
RUN J
10 100 50 60
(Example 2)
1 0 READ X$, A1 , ZS 20 PR I NT X$;A1 ;Z$ 30 END 40 DATA A, 1 , C
RUN J
A^1 C
f numeric constant
I string constant
<
j numeric constant ]
1 string constant j
•In this example, values specified in the DATA statement are read into variables A, B, C, and D by the READ statement, then the values of those variable are displayed.
•As shown by the example below, string data included in DATA statements does not need to be enclosed in quotation marks.
•The READ statement in this example picks successive data items from the list specified in the DATA statement, then substitutes each item into the correspond- ing variable in the list following the
READ statement.
>
44
Page 47
(Example 3)
10 DIM A (2)
20
30 40 50
(Example 4)
10 READ
20 READ
30 DATA
READ A (0) , PR I NT A (0) END DATA
RUN J
3 4
3, 4, 5
A B X
A (1 ) . A (2)
; A (1 ) ; A (2)
•The READ statement in this program substitutes the numeric values following the DATA statement into array elements
A(0), A( 1), and A(2), then the PRINT statement on line 30 displays the values
of those array elements.
The example above is incorrect because (1) a numeric variable is specified by the
READ statement on line 10, but the value
specified following the DATA statement is a string value, and (2) there is no data which can be read by the READ statement on line 20.
45
Page 48
2. 3. 5. 6 RESTORE (abbreviated format: . . . RES.) RESTORE or RESTORE Ln
When READ statements are executed, a pointer managed by the BASIC interpreter is incremented to keep track of the next item of data to be read from DATA state- ments. The RESTORE statement resets this pointer to (1) the beginning of the first DATA statement in the program or (2) the beginning of the DATA statement on a specified line.
1 0 DATA 1,2,3
20 DATA "AA", "BB" 30 READ X, Y 40 READ Z, V$
100 RESTORE 110 READ A, B, C, D$, ES
200 READ I , J 210 RESTORE 220 READ M, N 230 RESTORE 260 240 READ O, P 250 DATA 1,2,3,4 260 DATA -1 , -2, -3, -4
An error will result if the number specified in Ln is the number of non-existent line.
1 0 X = 33XRND (1 )
20 FOR A = 1 TO ! 30 READ MS 40 PR I NT TAB (0) ; "
50 PR I NT TAB (37) ;
60 NEXT A
70 Y=1 0XRND (1 ) 80 FOR A=1 TO Y
90 PR I NT TAB (0) ; '
1 00 PR I NT TAB (37) 110 RESTORE:GOTO 120 DATA" anB" 130 DATA" 3SSSS5 140 DATA" HBPr\"
Note: See page 62 for the TAB function and page 47 for the FOR . . . NEXT statement.
This function creates random numbers (see page 12).
" ; TAB (X) ; MS ;
l!
;
n
^^ ii
NEXT
1 0
m"
46
Page 49
2.3.6 Loop and branch instructions
2. 3. 6. 1 FOR ~ NEXT Format FOR cv = iv TO fv < STEP sv >
NEXT < cv >
cv . . . . Control variable; a numeric variable or array element,
iv .... Initial value; a numeric expression,
fv .... Final value; a numeric expression.
sv .... Increment, or step value; a numeric expression (if omitted, 1 is assumed).
Function
This statement repeats the instructions between FOR and NEXT a certain number of times.
1 0 A = 0 20 FOR N=0 TO 10 STEP 2 30 A=A+1 40 PR I NT " N= " ; N,
50 PR I NT "A=" ;A 60 NEXT N
(1) In the program above, 0 is assigned to N as the initial value.
(2) Next, lines 20 through 50 are executed and the values of variables A and N
displayed.
(3) In line 60, the value of N is increased by 2, after which the BASIC interpreter
checks to see whether N is greater than 10, the final value. If not, lines following
line 20 are repeated. When the value of N exceeds 10, execution leaves the loop and subsequent instruc- tions (on lines following line 60) are executed. The program above repeats the loop 6 times. If < STEP sv > is omitted from the statement specification, the value of N is increas- ed by 1 each time the loop is repeated. In the case of the program above, omitting < STEP sv > in this manner would result in 11 repetitions of the loop.
(abbreviated format: F. ~ N.)
i j
47
Page 50
FOR . . . NEXT loops may be nested within other FOR . . . NEXT loops. When doing this, inner loops must be completely included within outer ones. Further, separate control variables must be used for each loop.
Example
10 FOR X=1 TO
20 FOR Y=1 TO
9-
9- 30 PRINT XXY; 40 NEXT Y
50 PR I NT
60 NEXT X
70 END
Incorrect example:
—TOR J = 1 TO 10
pFOR J = K TO K + S
-I—NEXT J
X Different control variables
must be used in each loop.
Oh
o o
FOR
n
FOR
o o
FOR
3
o
NEXT C
A = 1 B = 1 C=1
NEXT B NEXT A
When loops C, B, and A all end at the
same point as in the example above, one
NEXT statement may be used to indicate
the end of all the loops.
FOR 1=1 TO 10 FOR J = K TO
—NEXT I
—NEXT J
X Loops may not cross one
another.
TO TO TO
K
o
5 7
NEXT
C , B , A
+ 5
Note
2.3.6.2 GOTO
Format
Function
Example
The syntax of BASIC does not limit the number of levels to which loops may be nested; however, space is required to store return addresses for each level, so the number of levels is limited by the amount of available free space. The CLR statement (see page 59) cannot be used within a FOR . . . NEXT loop.
(abbreviated format: . . . G.)
GOTO Ln
Ln . . . . Destination line number
This statement unconditionally transfers program execution to the line number specified in Ln. If Ln is the number of a line which contains executable statements (statements other than REM or DATA statements), execution resumes with that line; otherwise, execution resumes with the first executable statement following line number Ln.
1 0 N = 1
20 PR I NT N 30 N=N+1 40 GOTO 20
•Transfers program execution to line 20.
50 END
48
Page 51
Since execution of the program shown above will continue indefinitely, stop it by pressing the | SHIFT ] and BREAK] keys together (this may be done at any time to stop execution of a BASIC program). To resume execution, execute the CONT J command.
Note The line number specified in a GOTO statement may not be that of a line included
within a FOR . . . NEXT loop.
2. 3. 6. 3 GOSUB ~ RETURN . Format
Function
GOSUB Ln
RETURN Ln . . . Destination line number The GOSUB statement unconditionally transfers program execution to a BASIC subroutine beginning at the line number specified in Ln; after execution of the subroutine has been completed, execution is returned to the statement following GOSUB when a RETURN statement is executed. GOSUB ~ RETURN statements are frequently used when the same processing is required at several different points in a program. In such cases, a subroutine which performs this processing is included at some point in the program, and execution is branched to this subroutine at appropriate points by means of the GOSUB state- ment. After the required processing has been completed, execution is returned to the main routine by the RETURN statement.
(abbreviated format: GOS. ~ RET.)
49
Page 52
Note The syntax of BASIC imposes no limit on the extent to which subroutines can be
nested (that is, on the number of levels of subroutine calls which can be made from
other subroutines); however, in practice a limitation is imposed by the amount of free space in memory which is available for storing return addresses.
= 5
10 B=5
20 C = 8
30 GOSUB 100
40 PRINT A
SO B-2
60 C = 10
70 GOSUB 100 80 PRINT A
90 END 100 A=B+G I IO RETURN
B
c
= 8
O
(G0SUBI0q>=^\
•>Q oo~)
A=B+C
<RETURN)
<0
GOSUB (00
r'
-A-
2.3.6.4 IF
Format
Function
PRINTA 12 displayed.
0
THEN (abbreviated format: ... IF ~ TH.)
IF e THEN Ln IF e THEN statement e: A relational expression or logical expression
Ln: Destination line number IF . . . THEN statements are used to control branching of program execution accord- ing to the result of a logical or relational expression. When the result of such an expression is true, statements following THEN are executed. If a line number is specified following THEN, program execution jumps to that line of the program if the result of the expression is true. If the result of the logical or relational expression is false, execution continues with the program line following that containing the IF . . . THEN statement.
IF Condition
THEN
Statement or line number
50
Page 53
Example
•••THEN
F
••=•• F- •••THEN F- •••THEN
•••THEN
F-
•••THEN
F- F- •••THEN
•••THEN
F- F- •••THEN F- •••THEN F- -THEN
P•••THEN
1 00
GOTO or I F GOTO
PR I NT or I F THEN <?
A = 5^7 assignment
1=10:J = 50
I NPUT
READ
GOSUB
RETURN
STOP
END
Examples of logical and relational expressions
Operator Sample application
I F A = X
THEN-
If the value of numeric variable A equals the value of X, execute the statements following THEN. If the contents of string variable A$ equal "XYZ", execute the statements following THEN. If the value of variable A is greater than X, execute the statements following THEN. If the value of variable A is less then X, execute the statements following THEN. If the value of variable A is not equal to X,
C/3
a
o
"t/5
GO
<L>
<L>
V-4
V-4
CJ
<> or ><
I F A$=' XYZ "
THEN-
>
<
I F A>X
I F A<X
I F AOX
THEN-
THEN-
THEN-
execute the statements following THEN.
Pi
>= or =>
I F A> = X THEN- If the value of variable A is greater than or
equal to X, execute the statements following THEN.
<= or =<
I F A< = X THEN---
If the value of variable A is less than or equal to X, execute the statements following THEN.
cn
C o
<D
|H
ft <D
<D
a
a o
o
*5b
*5b
O
hJ
* I F(A>X)*(B>Y)
THEN-
+
I F(A>X)+(B>Y)
THEN---
If the value of variable A is greater than X.and the value of variable B is greater than Y, execute the statements following THEN. If the value of variable A is greater than X or the value of variable B is greater than Y, execute the statements following THEN.
Explanation
51
Page 54
Precautions on comparison of numeric values with BASIC 1Z-013B, numeric values are internally represented in binary floating point representation; since such values must be converted to other forms for processing or external display (such as in decimal format with the PRINT statement), a certain amount of conversion error can occur. For example, when an arithmetic expression is evaluated whose mathematical result is an integer, an integer value may not be returned upon completion of the opera- tion if values other than integers are handled while calculations are being made. Be especially sure to take this into consideration when evaluating relational expres- sions using "=".
This need is illustrated by the sample program below, which returns FALSE after
testing for equality between 1 and 1/100 X 100.
10 A=1/100X100
20 IF A=1 THEN PRINT "TRUE":GOTO 40 30 PRINT ".FALSE" 40 PR I NT "A=" ;A
50 END
RUN FALSE A—1
The fact that both "FALSE" and " A = 1" are displayed as the result of this pro- gram showns that external representation of numbers may differ from the number's internal representation. Therefore, a better method of checking for equality in the program example above is as follows.
20 IF ABS CA-1 ) < .1 E-8 THEN PRINT "TRUE
GOTO 40
Page 55
2. 3. 6. 5 IF ~ GOTO (abbreviated format: IF ~ G.)
Format
Function
Example
IF e GOTO Lr e: Relational expression or logical expression
Lr: Destination line number This statement sequence evaluates the condition defined by relational or logical expression e, then branches to the line number specified in Lr if the condition is satisfied. As with the IF . . . THEN sequence, IF ~ GOTO is used for conditional branching; when the specified condition is satisfied, program execution jumps to the line number specified in Lr. If the condition is not satisfied, execution continues
with the next line of the program. (Any statements following IF ~ GOTO on the
same program line will be ignored.)
10 G=0:N=0
20 I N PUT "GRADE=" ;X 30
40 50
1 00
1 1 0
1 20
1 30
1 40
IF X=999 GOTO 100
T=T+X:N = N +1
GOTO 20
PR I NT " " PR I NT PR I NT PR I NT END
TOTAL:";T NO. PEOPLE : " ; N AVERAGE:";T/N
2. 3. 6. 6 IF ~ GOSUB (abbreviated format: IF ~ GOS.)
Format
Function
Example
IF e GOSUB Lr e: Relational expression or logical expression
Lr: Destination line number This statement evaluates the condition defined by relational or logical expression e,
then, if the condition is satisfied, branches to the subroutine beginning on the line number specified in Lr. Upon completion of the subroutine, execution returns
to the first executable statement following the calling IF ~ GOSUB statement;
therefore, if multiple statements are included on the line with the IF ~ GOSUB
statement, execution returns to the first statement following IF ~ GOSUB.
10 I N PUT
20 IF X<0 30 IF X=0 40 IF X>0 50 PR I NT " 60 GOTO 10
100 PRINT
200 PR I NT 300 PR I NT
X= " ; X GOSUB 100 GOSUB 200 GOSUB 300
X PROGRAM LINE 100 X PROGRAM LINE 200 X PROGRAM LINE 300
PR I NT"X<0 PR I NT" X=0 PR I NT"X>0
RETURN RETURN RETURN
53
Page 56
2.3.6.7 ON-GOTO (abbreviated format: ON~G.) Format
Function
Example
ON e GOTO L^ < , Lr2 , Lr3, , Lri > e . . . Numeric variable, array element, or expression Lri . List of destination line numbers This statement branches execution to one of the line numbers following GOTO, depending on the value of e. The value of e indicates which of the line numbers following GOTO is to be used for making the branch; in other words, if e is 1, execution branches to the first line number in the list; if e is 2, execution branches to the second line number in the list; and so forth. For example:
100 ON A GOTO
Destination when
A is 1 A is 2 A is 3 A is 4
10 INPUT"NUMBER";A 20 ON A GOTO 50, 60, 70 50 PR I NT 60 PR I NT 70 PR I NT RUN NUMBER ? XXX NUMBER 9
YYY
NUMBER ?
XXX "
YYY "
ZZZ "
1
BS
200, 300, 400, 500
GOTO GOTO GOTO
If a decimal number such as 1 . 2 is specified, the decimal pcrtion is truncated before evaluating the statement.
1 0 1 0
1 0
54
Note
When the value of e in an ON~GOTO statement is greater than the number of line numbers specified following GOTO, execution continues with the next line
of the program. This also applies if the value of e is less than 1 or negative. Further, if the value of e is a non-integer, the decimal portion is truncated to obtain
an integer value before the statement is evaluated.
Page 57
2. 3. 6. 8 ON-GOSUB (abbreviated format: ON-GOS.) Format ON e GOSUB Lrj < , Lr2 , Lr3, , Lri >
e . . . Numeric variable, array element, or expression Lri . Destination line numbers
Function
Example
This statement branches execution to the subroutine beginning on one of the
line numbers following GOSUB, depending on the value of e. Operation of this statement is basically the same as with the ON~GOTO statement, but all branches are made to subroutines. Upon return from the subroutine, execution resumes with the first executable statement following the ON~GOSUB statement which made the call.
Let's try using the ON~GOSUB statement in a scheduling program. The most important point to note in the following program is that, a subroutine call is made at line 180, even though line 180 itself is part of a subroutine (from line 170 to
190) which is called by line 90. Subroutines can be nested to many levels in this
manner.
1 0
AS=" ENGL ":B$=
20
30 40 50
60
70
80
90
200
210
D$=" SCI ":ES = G$= " H I ST J$=" BUS ":K$=
INPUT"WHAT DAY?
FOR Z=1 TO 7:Y$=
FR
SAT " , 1 + 3XCZ-1 ), 3) NEXT Z
FOR Y=0 TO 4:PR NEXT Y: PR I NT
1 00 1 1 0
1 20
1 30 1 40 1 50
1 60
1 70
1 80
1 90
ON X GOSUB 1 80, 1 20, 1 30, 1 40, 1 50, 160, 1 70
PR NT PR NT " MON " PR NT " TUE " B$ E$ HS HS DS PR NT PR NT PR NT " F R I " PR NT FOR Y-1 TO 6
ON Y GOSUB 120,
PR I NT:NEXT Y RETURN
l!
: H$ =
:GOTO 50
"WED " "THU " BS D$ FS GS E$ RETURN
" SAT " BS GS DS KS RETURN
AS
OS CS
AS DS
MATH ":C$=" FREN " MUS ":F$=" GYM
ART ":I$=" GEOG " H RM " : PR I NT"B"
; XS
:
M I DS C " SUNMONTUEWEDTHU
:IF Y$=X$ THEN X=Z
INT TABC5 + 6XY) ; Y+1 ;
BS
DS GS KS RETURN
RETURN
AS FS RETURN
I S
CS CS RETURN
I S
1 30, 1 40, 1 50, 1 60, 1 70
55
Page 58
2.3.7 Definition statements
2. 3. 7. 1 DIM Format
Function
| Example
DIM aj (ij) < , a2 (i2), ai (im) > DIMbj (ii,ji)<,b2 (i2, j2), bi (in Jn) >
ai 1-dimensional array name (list) bi 2-dimensional array name (table) im, in, jn Dimensions
This statement is used to declare (define) arrays with from one to four dimensions
and to reserve space in memory for the number of dimensions declared (DIM: dimension). Up to two characters can be specified as the array name, and subscripts of any value may be specified to define the size of dimensions; however, the number of dimensions which can be used is limited in practice by the amount of free memory available.
(Examples:)
10 DIM A (1 00) 20 FOR J=0 TO 100 30 READ A CJ)
40 NEXT J
50 DATA 5, 30, 1 2,
(Examples:)
10 DIM A$ (1 ) , B$ (1 ) , OS (1 )
20 FOR J=0 TO 1 : READ AS (J) , B$ CJ) 30 OS CJ) =A$ CJ) + " " +BS CJ) 40 PR I NT AS CJ) , B$ CJ) , OS CJ) 50 NEXT J 60 END 70 DATA YOUNG, G I RL, WH I TE, ROSE
Note
2. 3. 7. 2 DEF FN Format
Function
56
Execution of the DIM statement sets the values of all elements of declared arrays to 0 (for numeric arrays) or null (for string arrays). Therefore, this statement should
be executed before values are assigned to arrays. Different names must be used for each array which is declared; for example, the instruction DIM A(5), A(6) is not a legal array declaration. All array declarations are nullified by execution of a CLR statement (see page 59) and a NEW statement (see page 32).
DEF FN f (x) = e
f . . . Name assigned to the function being defined (one uppercase letter from A to Z)
x . . . Argument (variable name)
e . . . Numeric expression (constant, variable, array element, or function) or pre-
viously defined user function
The DEF FN statement is used to define user function FN f (x). Such functions
consist of combinations of functions which are intrinsic to BASIC.
Page 59
Example
DEF FNA (X) =2XX T 2+3XX+1 Defines 2X2 + 3X + 1 as FNA
(X). DEF FNE CV) =1/2XMXVT2 Defines 1/2MV2 as FNE (V). 10 DEF FNB (X) =TAN (X-PAI (1)06)
20 DEF FND (X) =FNB (X)/ C + X--Defines function FNB using the
function defined on line 10.
(Incorrect definitions)
10 DEF FNK (X)=SIN CX/3+PAIC1 )/4), FNL (X)=EXP(-X T2/K)
. . . . Only one user function can be defined by a single DEF FN statement.
Find the kinetic energy of a mass of 5.5 when it is imparted with initial accelerations of 3.5, 3.5 x 2, and 3.5 x 3.
10 DEF FNE (V) =1 Y2XMXV T 2 20 M = 5. 5 : V = 3. 5
30 PR I NT FNE CV) , FNE CVX2) , FNE CVX3)
•40 END
Note
2. 3. 7. 3 DEF KEY Format
Function
All user function definitions are cleared when the CLR statement and the NEW statement is executed.
DEF KEY (k) = S$ k Definable function key number (1 to 10) S$ Character string (up to 15 characters). Character strings can be assigned to any of the ten function keys to allow strings to be entered at any time just by pressing a single key. This statement is used to
define such strings and assign them to the definable function keys. Function key numbers 1 to 5 are entered just by pressing the corresponding key at the top left
corner of the keyboard; keys 6 to 10 are entered by pressing the I SHIFT ~| key together with the corresponding key. The function key number (1 to 10) is specified in k, and the string or command which is to be assigned to the key is specified exactly as it is to be entered in S$. Execution of the DEF KEY statement cancels the previous definition of the definable function key.
No other statement can be specified after a DEF KEY statement on the same line. (Example:)
10 DEF KEY (1 ) = " I NPUT " Defines key [FT] as INPUT
20 DEF KEY (2) = " RUN " +CHR$(13)- Defines RF2l as RUN J
Note: CHR$ (13) indicates the ASCII code foriCR|, and specifying it together with the string assigned to
a definable function key has the same effect as pressing the |CRj key. (See the description of the CHR$ function on page 78 and the ASCII code table on page 154.)
57
Page 60
2.3.8 Remark statement and control commands
2. 3. 8. 1 REM
Format
Function
Multiple statement program lines
When more than one statement is included on a single program line, each statement must be
separated from the one preceding it by a colon (:). Operation of the BASIC interpreter is generally the same in such cases as when the same statements are specified on different lines. For example, the two programs below produce exactly the same result.
1 0 A = 5 20 B = 8 30 C=AXB 40 PR!NT C
REM r
r ... . Programmer's remark
REM is a non-executable statement which is specified in a program line to cause the BASIC interpreter to ignore the remainder of that line. Since REM statements
are non-executable, they may be included at any point in the program without affecting the results of execution. REM statements are generally used to make a program easier to read, or to add explanatory notes to a program.
10 A = 5:B=8:C=AXB: PR I NT C
Note: Also note that program operation may differ when multiple statement lines are used as
shown below.
10 INPUT A 20 B=0 30 I F 99<A THEN B = 1 40 PRINT B 50 END
10 INPUT A: B=0: I F 99<A THEN B = 1 : PR I NT B 20 END
This program displays 1 if the value entered is greater than or equal to 100, but nothing at all if the value entered is less than 100. The reason for this is that statements follow- ing THEN on line 10 are not executed if the IF condition is not satisfied.
This program displays 1 if the value entered at line 10 is greater than or equal to 100, and 0 if the value entered is less than 100.
58
Page 61
2.3.8.2 STOP (abbreviated format: S.) Format
Function
Example
Note
STOP
Temporarily stops program execution, displays BREAK and READY, then waits for entry of executable commands in the direct mode. The STOP statement is used to temporarily interrupt program execution, and may be inserted at as many points and locations in the program as required. Since execution of the program is only interrupted temporarily, the PRINT statement can
be used in the direct mode to check the values stored in variables, after which
execution can be resumed by entering CONT J .
1 0
READ A. B
20
30 40
70
X = AXB STOP Y=A/B
50
PR I NT X, Y
60
DATA 1 5. 5
END
RUN BREAK I N
30
Unlike the END statement, no files are closed by the STOP statement. (See page 68
concerning procedures for opening and closing of files.)
2. 3. 8. 3 END
Note
(abbreviated format: E.)
END The END statement terminates program execution and returns the BASIC inter- preter to the command mode for input of direct mode commands. When this state- ment is executed, READY is displayed to indicate that the BASIC interpreter is ready. After the END statement has been executed, execution cannot be resumed by
executing the CONT command even if there are executable statements on program
lines following the END statement. All open files are closed when the END statement is executed. (See page 68 concern-
ing procedures for opening and closing files.)
Differences between the STOP and END statements
STOP
END
Screen display
BREAK IN xxxx
READY READY
Files
Open files are not closed.
Open files are closed
Resumption of execution
Can be resumed by
executing CONT.
Cannot be resumed.
2. 3. 8. 4 CLR CLR
The CLR command clears all variables and cancels all array definitions. All numeric variables are cleared to 0, and null strings (" ") are placed in all string variables; arrays are eliminated entirely by nullifying all previously executed DIM statements.
Therefore, DIM statements must be executed to redefine the dimensions of required
arrays before they can be used again.
59
Page 62
Note
2. 3. 8. 5 TIS
The CLR command also cancels all function definitions made with the DEF FN statement; therefore, it is also necessary to reexecute DEF FN statements to rede- fine such functions before they can be used again.
CLR statements cannot be included in a FOR~NEXT loop or BASIC subroutine.
Format
Function
Example
TIS " hh mm ss"
TI$ is the name of the system string variable which contains the time of the com-
puter's built-in clock.
This built-in variable is automatically incremented once each second, and the six character string contained in this variable indicates the hour, minute, and second, with two characters used for each. For example, if the string contained in TIS is
11
092035", the time is 9:20:35 A. M.
Variable TIS is automatically set to 00:00:00 when BASIC is loaded into the com- puter. To set the current time of day, use the string assignment statement. For example, the clock can be set to 7:00:00 P. M. by executing the following. TIS =
."
190000" The clock is set to 7:00:00 and then restarted automatically when the CR key is pressed. The digits specified for the hour must be in the range from 00 to 23, and those
specified for the minute and second must each be in the range from 00 to 59.
The following program displays the current local time in various cities of the world.
10 PRINT "H" 20 DIM CS C1 0) , D C1 0) , E C1 0) , T$ (1 0) 30 FOR 1=1 TO 10: READ CS CI ) , D CI) : NEXT I
40 PRINT"ENTER NEW YORK TIME (HOUR, MI NUT
E, SECOND) "
50 INPUT B$ :T I $ = B$ : PR I NT"H" 60 PRINT " EP : TS C1 ) =T I S 70 FOR 1=1 TO 10 80 E ( I ) = VAL CLEFTS CTS C1 ) , 2) ) +D C I ) 90 IF E CI ) =24 THEN E CI ) =0
100 IF E CI ) <0 THEN E CI ) =24+E ( I) 110 TS C I ) =STR$ CE C I ) ) +R I GHT$ CTS C1 ) , 4) 120 IF LEN CTS CI)) =5 THEN TS C I ) = " 0 " +TS C I ) 1 30 PR I NT CS C I ) ; TAB C1 5) ; LEFTS CTS CI), 2) ; 1 40 PR I NT " : " ; M I DS CTS CI), 3, 2) ;"::"; R I GHTS C
TS C I ) , 2) ;
150 NEXT 160 DATA
I:GOTO 60
NEW YORK, 0,
MOSCOW, 8, R I O DE UANE
I RO, 2
170 DATA
SYDNEY, 1 5, HONOLULU, -5, LONDON, 5,
CA I RO, 7
180 DATA
, 6
TOKYO, 14, SAN FRANCISCO, -3, PARIS
60-
Page 63
Note
2. 3. 8. 6 CURSOR (abbreviated format: CU.)
The TI$ variable cannot be specified in an INPUT statement. Further, after the time changes from 23:59:59 to 00:00:00, the time "00:00:01" is not displayed.
Format
Function
Example
CURSOR x,y x . . . X coordinate (0 to 39) y . . . Y coordinate (0 to 24)
This command is used to move the cursor to a specified position on the TV (display) screen, and can be used together with the PRINT and INPUT statements to display characters in any desired location. In the system of screen coordinates used, the columns of the screen are numbered from left to right, starting with 0 on the left side and ending with 39 on the right side; lines of the screen are numbered from top to bottom, with 0 indicating the top line of the screen and 24 indicating the bottom line. Thus, the cursor can be moved to any desired position in the range from (0, 0), which indicates the top
left corner of the screen, to (39, 24) indicates the bottom right corner. The following program moves an asterisk (>K) about on the screen as the cursor keys are pressed.
1 0
X=0:Y=0
1 5
PR I NT"E"
20
CURSOR X, Y:PR I NT"*" ;
30
GET A$:IF A$="" THEN
40
CURSOR X, Y : PR I NT" " ;
50 .
60
70
80
90
1 00
1 1 0
1 20
1 50
F A$="D F A$="D F A$="B F A$="B F X<0
I F Y<0 I F X >38 IF Y>24
GOTO 20
THEN THEN THEN THEN THEN THEN THEN THEN
Y=Y—1 Y=Y+1 X = X-1 X = X + 1 X=0 Y=0 X = 38 Y=24
30
REM REM REM REM
UP DOWN LEFT R I GHT
Note
If the value specified for either X or Y is other than an integer, it is converted to an integer by truncating the decimal portion before the cursor is moved. Other methods of moving the cursor which are used together with the PRINT statement include the TAB and SPC functions. (See page 62 for a description of the SPC function.)
0
0
10
Y
X
CURSOR 8.10
Page 64
2. 3. 9. 2
TEMPO
(abbreviated format: TEM.)
Format
Function
Example
Note
TAB (x)
x . . . A numeric expression
The TAB function is used together with the PRINT statement to move the cursor
to the character position which is x + 1 positions from the left side of the screen. (This is referred to as space tabulation.)
PR I NT TAB (5) ; " XYZ " ; TAB (1 0) ; " ABC "
01 2345678901 2 <]=[ Not actually displayed.
XYZ —ABC
1 j
Tabulation can only be used to move the cursor to the right; therefore, nothing
happens if this function is used together with the PRINT statement when the cursor
is already to the right of the character position specified in (x).
(Example:)
PR I NT TAB (5) ;
01234567890
11
XYZ
11
; TAB (5) ;
11
ABC
—————XYZABC
2. 3. 8. 8 SPC
Format
Function
Example
SPC (n) n . . . A numeric expression Use together with the PRINT statement, this function outputs a string of n spaces and thus moves the cursor n character positions to the right of its current position.
(Example 1)
PR I NT SPC (5) ; " ABC
O 1 2 3 4 5 6 7
11
-----ABC
(Example 2)
The following example illustrates the difference between the TAB and SPC func-
tions.
1 0 9 TAB (2) ; " ABC " ; TAB (6) ; " DEF " 20 9 SPC (2) ; " ABC " ; SPC (6) ; " DEF "
01 2345678901 23
--ABC-DEF-----
--ABC------DEF
62
Page 65
2.3.8.9 SET, RESET These statements are used to turn dots on or off at a specified position on the screen.
Format
Function
Range of X, Y coordinates
SET X, Y < , C > X . . . Numeric expression speci-
fying the X coordinate.
Y . . . Numeric expression speci-
fying the Y coordinate.
Turns on the dots at
the screen coordinates specified by X and Y.
(SET)
0 <X<19 0 < Y<49
C . . . Color code (0 to 7). RESET X, Y
X . . . Numeric expression speci-
fying the X coordinate.
Y . . . Numeric expression speci-
fying the Y coordinate.
Turns off the dots at the screen coordinates
specified by X and Y.
(RESET)
0<X<19
0<Y<49
When a color code is specified, the color of the dots displayed by the SET statement is as follows.
(0) Black (1
) Blue (2) Red (3 ) Purple (4) Green (5) Light blue (6) Yellow (7) White
Since four dots are turned on simultaneously by the SET statement, changing the color of any one
dot in that four dot group also causes the color of the other dots to change.
The SET and RESET statements can be use to produce a wide variety of interesting effects; some
examples are introduced below.
1. Turning on one dot on the
10 PR I NT"M "
20 X=79:Y=49 30 SET X, Y, 2 < 40 RESET X, Y <
50 GOTO 30
2. Coloring the entire screen whi
10 PRINT'S'
20 FOR X=0 TO 30 FOR Y=0 TO 40 SET X, Y, 7
50 NEXT Y, X
60 GOTO 1 0
een.
C] ^Turns dots on.)
^Turns dots off.)
te.
79 49
Page 66
3. Drawing a rectangle around the edge of the screen.
10 PRINT'S"
20 FOR X=0 TO 79 30 SET X. 0 40 SET X. 49
50 NEXT X 60 FOR Y= 0 TO 49 70 SET 0. Y 80 SET 79. Y 90 NEXT Y
100 GOTO 100
4. A program which simulates the ripples produced by throwing a pebble into a pond.
10 X=40:Y=25 20 DEF FNY CZ) =SQR CRXR-ZXZ) 30 PR I NT'S" :SET X, Y
40 R=R+5
50 FOR Z=0 TO R 60 T = FNY CZ) 70 SET X + Z, Y+T 80 SET X + Z. Y-T 90 SET X-Z, Y + T
100 SET X-Z, Y-T
110 NEXT Z
120 IF R<>25 THEN 40
130 GOTO 130
5. A program which simulates a ball bouncing off four walls.
10 PR I NT"0" 20 FOR X=0 TO 79 30 SET X, 0: SET X, 49 40 NEXT X 50 FOR Y=0 TO 49 60 SET 0, Y : SET 79, Y 70 NEXT Y
80 X =79XRNDC1) :Y = 49XRNDC1) 90 A=1:B=1
1 00 SET X, Y
110 IF X<2 GOSUB 200
120 IF X>78 GOSUB 200
130 IF Y< 2 GOSUB 250
140 IF Y>48 GOSUB 250
1 50 RESET X, Y
160 X=X+A:Y=Y+B:GOTO 100 200 A=—A:MUSIC"+A0": RETURN 250 B=-B:MUSIC"A0": RETURN
66-
Note As to JOY command, refer to the instruction manual of Joy Stick.
Page 67
2.3.9 Music control statements
This section discusses the MUSIC and TEMPO statements which are used to control performance of music by the computer. As its name implies, the TEMPO statement specifies the speed with which music is performed. The notes (including half notes and upper and lower octaves) and duration of notes produced are controlled by the MUSIC statement.
Tempo:
Melody:
Note specification
2. 3. 9. 1 MUSIC (abbreviated format: MU.)
Format
Discussion
Specified with TEMPO as a numeric variable or constant with a value from
1 (slow) to 7 (fast). Specified with MUSIC as a string variable consisting of a collection of notes.
octave
MUSIC X$ X$ . . . String data
Automatically performs music.
This statement outputs the melody or sound effects specified by the character string or string variable of its argument to the speaker. The speed with which this melody- is played is that which is specified with the TEMPO statement (see page 67).
The format for specification of each note is as follows: < octave specification > < # (sharp) > note name < duration >
The plus or minus signs are used to specify the octave. If neither is specified, the middle range is assumed.
# (sharp)
note name duration
The three ranges of sounds which can be output by the computer are as shown in the figure below. For example, the C notes ("do" on the 8-note C scale) indicated by the black dots below are differentiated from each other by the octave specification.
Low C -C Middle C C High C +C
?
>
V
Low Middle High range [ | range [ | range
No specification +
65-
Page 68
Note specification
The symbols used to specify notes within each range are as follows:
CDEFGAB # R The relationship between the 8-note scale (do, re, mi, fa, so, la, ti, do) and these symbols are as shown below. The sharp symbol (#) is used to specify half notes.
Silent intervals are specified with "R".
11
II
I I I
do
re
mi
I
C D
#C#D # F # G # A R Rest
Duration specification
The duration specification determines the length of the specified note. The dura-
tions from 1/32 to whole are specified as numbers from 0 to 9. (When R is specified, this determines the length of the silent interval.)
? f 7-7 7- } I- - -
1/32 rest 1/16 rest °°«
E F I G
erd
II
I
fa
so
I I
1/8 rest °°»est mfest Sst
est
II
la
A
I |
ti I
B
J> J> Ji' J> Ji J J. J J.
1/32note1/16notef;«
01 23456789
end
1/8note
ote
1/4
note ^ 1/2note Whole note
Example
When sucessive notes have the same duration, the duration specification can be
omitted for the second and following notes. If no duration is specified for the first note, 1/4 notes are assumed.
Sound volume
The volume of sound produced cannot be controlled by the program, but can be adjusted with the computer's external volume control.
Let's try assigning a string to SR$ to play the theme from the beginning of Beethoven's Serenade in D major (Opus 25).
SR$="+A3+ # F1+A + B3A + D+#F1 A + D3A + D
+ # F 1A + D3+#F1A + D+E+#F + G+A3R "
0
1
n
-ft
-0
rf=r
k -
66-
Page 69
2. 3. 9. 2 TEMPO
(abbreviated format: TEM.)
Format
Function
Example
TEMPO x x . . . Numeric expression (1 to 7)
This statement sets the tempo with which music is played by the MUSIC statement.
If this statement is not executed, TEMPO 4 is assumed for execution of MUSIC statements.
30 TEMPO 1 Slowest tempo (Lento, adagio) 30 TEMPO 4 Medium tempo (Moderato);
four times as fast as TEMPO 1.
30 TEMPO 7 Fastest tempo (Motto allegro, presto);
seven times as fast as TEMPO 1.
10 REM Chopin's mazourka 20 MM$="A3":M1$="A5+#C3+D+E+#F+G+#F0+G+#
F4+E3 + D+#CB
ll
30 M2$="A3+D2R0+D1+E2+D+#C3B+#C7+#C3"
40 M3$="A3 + #C2R0+ #C1+D2+#CB3A + D7 + D3"
50 TEMPO 3
60 MUS I C MM$, M1 S, M2S, M1 S, M3$, M1 $, M2S, M1
S, M3$
70 END
67
Page 70
2.3.10 Data file input/output commands
Although the SAVE and LOAD commands can be used to write or read program text, other commands are used to record or read the various types of data which is handled by programs. These commands are described below.
Format Function
Opens a data file on cassette tape
WOPEN
(abbreviated W.)
PRINT/T
(abbreviated ?/T)
ROPEN
(abbreviated RO.)
INPUT/T
(abbreviated I./T)
CLOSE
(abbreviated CLO.)
WOPEN < file name >
PRINT/T dx < , d2, d3 , . . . dn >
dn . . . . Numeric data or string data
ROPEN < file name >
INPUT/T
vn . . . . Numeric data or string data
CLOSE
< , v2, v3 , . . . vn >
Vl
prior to writing data to it. This command also assigns a name to the data file.
Writes data to cassette tape in the same format as it would be displayed by the PRINT statement.
Searches for the data file on cassette tape with the specified name and opens that file to prepare for reading data from it.
Used to input data from a cassette file and pass it to the program (in a manner similar to that in which the INPUT statement is used to input data from the keyboard).
Statement which closes cassette data files after writing or reading has been completed.
Unlike the LOAD and SAVE commands, no messages are displayed by execution of the WOPEN and
ROPEN statements.
If display of a message is desired, use the PRINT statement to define one in the program.
Note: When an ordinary cassette recorder is used, it may not be possible to record data files even if no
problems are encountered in storing or reading programs with the SAVE and LOAD commands.
(Example 1)
The following program writes the numbers from 1 to 99 on cassette tape.
10 WOPEN "DATA" 20 FOR X=1 TO 99 30 PR I NT/T X 40 NEXT X 50 CLOSE 60 END
(Example 2) The following program reads data from the data file prepared in Example 1 above. Before execut- ing this program, be sure to rewind the cassette tape.
10 ROPEN "DATA"
20 FOR X=1 TO 99 30 INPUT/T A 40 PRINT A
50 NEXT X
60 CLOSE 70 END
Page 71
(Example 3) The following program creates a data file consisting of string data.
10 DIM N$ (5) 20 N$ (1 ) = " BACH " 30 NS (2) = " MOZART " 40 N$ (3) =" BEETHOVEN " 50 NS (4) = " CHOP I N " 60 NS (5) =" BRAHMS " 70 WOPEN"GREAT MUSICIAN" 80 FOR J=1 TO 5
90 PR I NT/T NS CJ)
100 NEXT J 110 CLOSE 120 END
(Example 4) The following program reads string data from the file created in Example 3. Before executing this program, be sure to rewind the cassette tape.
200 DIM MS (5)
210 ROPEN "GREAT MUSICIAN"
220 FOR K=1 TO 5
230 I NPUT/T MS CK)
240 PR I NT MS CK)
250 NEXT K
260 CLOSE
270 END
It is also possible to create data files which include both numeric and string data. However, since an error will occur if the type of data read does not match the type of variable specified in the INPUT/T statement, it is generally best to limit files to one type of data or the other.
Note: It is possible to omit the file name when opening a sequential file with the WOPEN statement.
However, this is likely to result in errors if many files are included on the same tape; therefore, it is recommended that you make a habit of assigning file names to sequential data files.
69-
Page 72
The following program records student grades in English, French, science, and mathemetics to a
sequential data cassette file.
10 INPUT"ENTER NO. OF STUDENTS";N
20
30 40 50
60
70
80
90
1 00
1 1 0 1 20
1 30 1 40 1 50
1 60
1 70
1 80
1 90
DIM N$ CN) , K CN) , E CN) DIM R CN) , S CN)
AS="GRADE IS"
FOR X=1 TO N PR I NT: PR I NT "STUDENT NO. ";X
INPUT"ENTER STUDENT NAME: PR I NT PR I NT
PR I NT PR I NT NEXT X
WOPEN"GRADES'
PR I NT0T N FOR X=1 TO N PR I NT/T NS CX) NEXT X
CLOSE •C;Closes the cassette ffleT)
END
ENG " FREN "
" SO I
" MATH
; AS ; ; AS ; " ; AS " ; AS
I NPUT K CX) I NPUT E CX) : I NPUT R CX) : I NPUT S CX)
<C=(Opens data file "GRADES" for output on cassette tape.) <C=(
Writes the number of students in the class to the file. ]
K CX) , E CX) , R CX) , S CX)
NS CX)
Writes grades to the file.
<
The following program reads the grade data written to the cassette file by the program shown above, then calculates displays the grade average for each student and class averages for each of the various subjects.
Opens cassette file "GRADES" for input.]
Reads student names and the grades for English.
/iJ Reads the grades for French, science
^,and mathematics.
Closes the file.)
l!
TAB (1 5) TAB (25)
E (0) 0N
S (0) 0N
70-
1 0
20
30 40 50
60
70
80
90
ROPEN"GRADES"
I NPUT/T N Reads the number of people in the class.) DIM NS CN) , K CN) , E CN) DIM R CN) , S CN) FOR X=1
INPUT0T INPUT/T
NEXT X
CLOSE
1 00
1 1 0
1 20
1 30 1 40 1 50
1 60
1 70
1 80
1 90
200
21 0
230
240. 250
TO N NS CX) , K CX) E CX) , R CX) , S CX)
PR I NT PR I NT PR I NT PR I NT FOR X = PR I NT PR I NT PR I NT PR I NT PR I NT
K (0) =K (0) + K (X) R (0) =R (0) +R (X) NEXT X PR I NT TAB (1 0) ; PR I NT TAB (20) ; END
TAB C1 0) ; " ENG TAB C1 5) ; " FREN ' TAB C20) ; "SCI " TAB C25) ;
-•1 TO N
NS CX) ; TAB (10) ; K (X) TAB (1 5) TAB (20) TAB (25) TAB (30)
11
MATH "
E (X) R (X)
S (X)
(K (X) + E (X) +R (X) +S (X) ) 04 : E (0) =E (0) +E (X) : S (0) =S (0) +S (X)
K (0) 0N
R (0) 0N
Page 73
2.4 Built-in Function
Function
Absolute value
Sign
Integer
conver-
sion
Trigono-
Trigono-
Trigono-
Trigono- metric
metric
metric
metric functions
functions
functions
functions
BASIC
symbol
ABS (X)
Example
A - ABS (X)
SGN (X) A - SGN (X)
INT (X) A = INT (X)
SIN (X) A = SIN (X)
A=SIN(30XPAI(1/180)
Description
Assigns the absolute value of variable | X | to vairable A.
Example: A = ABS (2. 9) ->A -2.9
A = ABS (-5. 5)A =5.5
Assigns the numeric sign of variable X to variable A. If the value of X is negative,
1
is assigned to A; if X is 0,
0 is assigned to A; and if X is positive, 1 is assigned to A.
[ 1 (X > 0) Example: 1 is assigned to variable
A = 0 (X = 0) A when A = SGN (0.4)
' -1 (X < 0) is executed.
Assigns the greatest integer value to A which is less than or equal to the value of variable X. Examples: A = INT (3. 87) ->A - 3
A = INT (0. 6) ^A = 0 A = INT (-3. 87) ->A = -4
Assigns the sine of X (where X is in radians) to variable A. If the value of X is in degrees, it must be converted to radians before this function is used to obtain the sine. Since
1 degree equals 7r/180 radians, the value in radians is
obtained by multiplying the number of degrees by PAI(l)/
180. For example, 30° = 30* PAI(1)/180 radians. The same
applies to the COS, TAN, and ATN functions.
Square root
Exponen-
tiation
Common logarithm
Natural
logarithm Ratio of
circum- ference to diameter
COS (X)
TAN (X)
ATN (X)
SQR (X)
EXP (X)
LOG (X)
A = COS (X)
A=COS
(200XPAI(1)/180)
A = TAN (X)
A=TAN(YXPAI(1)/180)
A = ATN (X)
A=180/PAI(1)XATN(X)
A = SQR (X) Calculates the square root of X and assigns the result to
A = EXP (X) Calculates the value of ex and assigns the result to variable
A = LOG (X)
LN (X) A = LN (X)
PAI (X)
A - PAI (X)
Assigns the cosine of X (where X is in radians) to variable A.
Assigns the tangent of X (where X is in radians) to variable A.
Assigns the arctangent in radians of X (tan-1 X) to variable A. The value returned will be in the range from —PI/2 to PI/2.
variable A. X must be a positive number or 0.
A. Calculates the common logarithm of X (log10X) and assigns
the result to variable A. Calculates the natural logarithm of X (loge X) and assigns
the result to variable A. Assigns the value to variable A which is X times the value
of PI.
Radians
RAD (X)
A = RAD (X)
Converts the value of X (where X is in degrees) to radians and assigns the result to variable A.
Page 74
Examples of use of the built-in funcions
(Example 1) Let's try solving the various elements of a triangle with a BASIC program.
Angle A of the triangle shown in the figure at right is 30°,
CA=12
angle B is a right angle, and side CA has a length of 12. The following program finds all angles of the triangle, the
AB
length of its sides, and its total area.
10 A=30:B=90:CA=12
20 AB=CAXCOS (AXPA I (1 )01 80) 30 BC=CAXS I N (AXPA I (1 )01 80) 40 S=ABXBC02 50 C=180—A—B 60 PRINT " AB= " ; AB, " BC= " ; BC,
CA=";CA
70 PRINT "A REAS=" ;S
80 PRINT "A=" ;A, "B=";B. "C="
C
90 END
(Example 2)
Now let's change line 50 of the program to use ATN, the function for finding the arctangent of a number,
to fine angle C from sides AB and BC.
10 A=30:B=90:CA=12
20 AB=CAXCOS (AXPA I (1 )01 80) 30 BC = CAXS I N (AXPA I (1 )01 80) 40 S=ABXBC02 50 C = ATN (AB0BC) X1 800PA I (1 ) 60 PRINT " AB= " ; AB,
|:
BC= " ; BC,
CA=";CA 70 PRINT "AREAS=";S 80 PRINT " A " ; A, " B= " ; B, " C= "
; C
90 END
RND function
72-
Format
Function
RND (X)
X . . Numeric expression
The RND function returns a pseudo-random number in the range from 0.00000001
to 0.99999999. When X is greater than 0, the random number returned is the one which follows that
previously generated by the BASIC interpreter in a given pseudo-random number
series.
When X 0, the BASIC Interpreter's pseudo-random number generator is reinitia-
lized to start a new series, and the pseudo-random number returned is the first one
in that series. Reinitialization of the pseudo-random number series in this manner
can be used to allow simulations based on random numbers to be reproduced.
Page 75
The RND function is often used in game programs to produce unpredicatable numbers, as in games of chance. Let's try using the RND function to investigate the percentage of times each of the six sides of a die comes up by simulating the action of throwing it a given number of times. Since the sides of each die are numbered from 1 to 6, we must multiply the value returned by the RND function by 6.
x6
0<RND (1) <1 * 0<6-XRND (1) <6
Then we must use the INT function to convert the value obtained to an integer.
I NT (6XRND (1 ) ) ->Os 1, 2s 3, 4s 5
The result will be an integer between 0 and 5; now 1 is added to obtain the numbers which correspond to the number of dots on each of the 6 sides of a die.
I NT (6XRND (1 ) ) + 11 s 2s 3s 4s 5s 6
This sequence is performed a specified number of times for each die thrown. Now let's incorporate the sequence into a program and check the results.
Example
10 PRINT "ENTER NO. OF
TIMES DIE THROWN";
20 INPUT N
The RND ____ function generates numbers in the range from 0.0000001 to
0.99999999.
30 FOR J=1 TO N 40 R=l NT (6XRND (1) ) +1 50 IF R=1 THEN N1=N1+1 60 IF R = 2 THEN N2=N2+1 70 IF R=3 THEN N3=N3+1 80 IF R=4 THEN N4=N4+1 90 IF R=5 THEN N5=N5+1
100 IF R = 6 THEN N6=N6+1 or S)
DKl^seTOEXtDjK®
= /S Ft7 (5)
110 NEXT U 120 P1=N1/N:P2=N2/N:P3=N3/N 130 P4=N4/N:P5=N50N:P6=N60N
140 PRINT P1 , P2, P3. P4, P5, P6 150 END
How about it? If the die is thrown enough times, the percentage of the time each number appears should be about the same. Mathematically speaking, each number
should occur an average of once in six throws, or about 16.7% of the time. This mathematical ideal is approached more closely as the number of throws is increased.
73-
Page 76
Example
Now let's try using the RND function in a program which tests your ability to solve
for the area of a triangle of random size. Here, the RND function is used to deter- mine the length of each of the three sides of the triangle, then you compute the area of the triangle yourself and submit your answer to the computer for checking.
DIM A (3) , L$ (4)
1 0
20
30
40
50
60
70
80
90
200
21 0
220
230
240
250
260
270
280
290
300
31 0 320 330 340 350 360
FOR J-1 TO 4 READ L$ CJ) : NEXT J
FOR J=1 TO 3 A (J) - : NT (20*RND (1 ) ) +1 NEXT J
IF A (1) > = A (2) + A (3) GOTO IF A (2) > = A (1) +A (3) GOTO IF A (3) > = A (1) + A (2) GOTO
1 00
1 1 0 1 20
1 30 1 40 1 50
1 60
1 70
1 80
1 90
W= (A (1 ) + A (2) + A (3) ) 02
T=W :FOR J = 1 TO 3 T = T* (W-A (J) ) : NEXT J SS = SQR (T) : S= I NT CSS)
IF SS-S>0. 5 THEN S=S+1 PRINT SEH9E1E3 PRINT " SOLVE FOR THE FOLLOWING TRIANGLE" PRINT " ROUND YOUR ANSWER NEAREST WHOLE NUMBER" PR I NT
PR I NT PR I NT
; A (1) PR I NT
; A (2) PR I NT
; A (3) PR I NT PR I NT PR I NT PR I NT PR I NT
I NPUT I F Y=S
40
I F Y< S
: GOTO PR I NT PR I NT PR I NT TAB (24)
GOTO 270
DATA LENGTH S DATA LENGTH S
GLE ABC IS
TAB (8) TAB (8)
TAB (7)
TAB (6)
TAB (5) TAB (3) TAB (4)
••
TAB (3)
Y
THEN
THEN PRINT "
320
TOO LARGE!
HO " ;
LS (4)
PR I NT OK!! " : GOTO
40 40 40
AREA OF THE
TO THE
A "
0S "
0 H
0
0
B0
•nnnnnnnnn
SPC (25) : PR I NT I
DE AB=, LENGTH S DE CA = , AREAS OF
H
TAB (1 5) ; LS (1 )
TAB (1 5) ; LS (2)
; TAB (1 5) ; LS (3)
H
SO
TOO SMALL!
DE TR
BC AN
:
74
Page 77
Note
Note than specifying a value for X which is less than or equal to 0 will always result in the same number for a given value of X. The reason for this is that specifying 0 or
a negative number reinitializes the pseudo-random number generator to the beginn-
ing of the random number series.
Page 78
5 String Function
>.1 LEN
Format
Function
Example
LEN (XS)
X$ . . . String expression This funcion returns the number of characters included in the string expression represented by X$. This value includes spaces which are not displayed on the screen
and any control characters in the string, as well as letters, numefals, and symbols. (Example 1)
10 A$ =
20 PR I NT LEN (A$>
RUN
7
(Example 2) The following program uses the LEN funcition to draw squares on the
10 9"E":9"ENTER 30R MORE ASTERISKS"
20 INPUT AS 30 FOR I =1 TO LEN (AS) -2 40 PR I NT TAB (2) ; " * " ; SPC (LEN (AS) -2) ; "'* "
50 NEXT I
60 PR I NT TAB (2) ; AS : GOTO 20
11
ABCDEFG "
screen.
(Example 3) The LEN function can also be used to produce a "parade" of charac-
ters as shown below.
10 S$="SHARP BASIC"
20 FOR 1=1 TO LEN (SS) 30 9 R I GHTS (SS, I ) 40 NEXT I
50 END
RUN C
I C
S I C
SHARP BASIC
(Example 4)
PR I NT LEN (STRS (PA I (1 ))) J
9
PAI (1), the function which returns the value of the ratio of the circumference of a
circle to its diameter, contains the 8-digit constant 3.1415927 (approximately the value of PI). When the length of the character string produced by converting this
constant with the STR$ function is evaluated with the LEN function, a total string
length of 9 is returned.
Page 79
2.5.2 LEFT$, MID$, and RIGHT$
The LEFTS, MID$, and RIGHTS functions are used to extract character strings from the left end, right
end, or middle of a character expression.
Format X$: String expression m and n: Numeric expressions
LEFTS (XS, n)
MIDS (XS, m, n)
MIDS (XS, m, n)
MIDS (XS, m, n)
RIGHTS (XS, n)
RIGHTS (XS, n)
Function
Returns the character string consisting of the n characters making up the left of string expression xs.
Returns the character
Returns the character
Returns the character
Returns the character string consisting of the n
string consisting of the n
string consisting of the n
string consisting of the n characters making up the
characters making up the
characters making up the
characters making up the n characters starting with
n characters starting with
n characters starting with
n characters starting with the mth character in string
the mth character in string
the mth character in string
the mth character in string expression X$.
expression X$.
expression X$.
expression X$.
Returns the character
Returns the character string consisting of the n
string consisting of the n characters making up the
characters making up the right end of string ex-
right end of string ex- pression X$.
pression X$.
Example (when AS = "ABCDEFG")
B$= LEFTS (AS, 2)
B$" AB CDEFG
Substitutes 2 characters from the left end of string variable AS into string varible BS. Thus, BS = AB1 .
B$=MID$ (AS, 3, 3)
B$«-I AB CDE
Substitutes the 3 characters
Substitutes the 3 characters starting at the 3rd character
starting at the 3rd character in string variable AS into
in string variable AS into string variable B$.
string variable B$. BS = RIGHTS (AS, 2
BS—| ABODE
FG
)
FG
Substitutes 2 characters from the right end of string variable AS into string varible BS. Thus, BS = "FG".
Remarks
0< n^ 255
1< m^ 255
1< m^ 255
1< m^ 255
0< n< 255
0< n< 255
0< n< 255
n^ 255
n^ 255
Page 80
2.5.3 ASC and CHR$
Format
ASC (x$)
x$: String expression
CHRS (x) x: Numeric expression
Function
Returns the ASCII code for the first character in string expression x$.
Returns the letter whose ASCII code corresponds to the value of numeric
expression X. (No character is returned if the value specified for x is less then 33; therefore, PRINT
11
_ " or PRINT SPC (1) should be used to obtain spaces, rather than CHR$ (32)).
Example
X=ASC (" A
11
)
Substitutes 65 (the ASCII code for the
letter A) into variable X.
Y=ASC
11
C
S HARP " )
Substitutes 83 (the ASCII code for S, the first letter in the string "SHARP")
into variable X.
A$=CHR$ (65) Assigns A, the letter corresponding to ASCII code 65, to string variable A$. This function can be used to display
characters which cannot be entered
from the keyboard as follows. PRINT CHR$ (107) J This displays the graphic character EB.
78-
Note: ASCII code is a standard code system which is frequently used with computers. This code uses
8 bit numbers to represent the letters of the alphabet, numerals, and symbols such as the dollar sign and question mark. The full code set is presented in the table on page 154.
Page 81
2.5.4 VAL and STR$
Format
STRS (x)
x: Numeric expression
Function
Returns a string of ASCII characters
representing the value of numeric
expression X.
A$=STR$ (-12)
Substitutes the character string " —12
into string variable AS.
Example
B$=STR$ (70 X 33)
Substitutes the character string
" 2310 " into string variable BS.
C$=STR$ (1200000 * 5000)
Substitutes the character string " 6E + 09" into string variable CS.
Note: Positive numeric values axe displayed with a
leading space to indicate that the plus sign
(+) has been omitted. However, this space
is not included in the character sting re-
turned by the STR$ function.
VAL(x$) x$: String expression
Converts an ASCII character repre- sentation of a numeric value into a numeric value. This is the comple- ment of the STRS function.
A=VAL ("123") Converts the character string " 123
1
into the number 123 and assigns it to numeric variable A.
The following sample program illustrates use of some of the functions discussed above to display
numeric values in tabular format (with the decimal points aligned).
"
1.23456
1 2. 3456
1 0
1
1 234
If the values read from DATA statements were displayed using only the PRINT statement, the result would appear as shown below.
10 FOR X=1 TO 5 20 READ A 30 L = 5-LEN (STRS ( ! NT(A) ) ) 40 PR I NT TAB CL) ; A 50 NEXT:END 60 DATA 1. 23456, 12. 3456 70 DATA 123. 456, 1234. 56 80 DATA 12345.6
1
1 2
1 23
1 234
1 2345
Page 82
2.6 Color display statement
One of the greatest features of the MZ-700 is that it allows characters and graphics to be displayed using any of up to 8 colors.
2.6.1 COLOR (Abbreviated format: COL.)
Format
Function
COLOR x, y, c <, b >
x .... X coordinate (0 to 39)
y . . . . Y coordinate (0 to 24)
c . . . . Character color specification (0 to 7).
b . . . . Background color specification (0 to 7).
This statement is used to set the foreground and background colors for the character at a specific position on the screen. Any of up to 8 different colors can be specified for the character foreground (c) or background (b) as shown in the table below.
Color No. Color
Example
0
1 2 Red 3 Purple 4 Green
5 Light blue 6 7
(1) Changing the background color of the entire screen
COLOR , , , 2 (Changes the background color used
(2) Changing the foreground color of the entire screen (the color used for display
of all characters)
COLOR, ,3 (Changes the color used for display of
(3) Changing both the background and foreground colors for the entire screen
COLOR ,,1,0 (Changes the color used for display of
(4) Changing the background color at a specific screen location
COLOR 2, 2, ,4 (Changes the background color at
(5) Changing the foreground color at a specific screen location
COLOR 3, 2, 7 (Changes the foreground color at
(6) Changing both the foreground and background color at a specific screen location
COLOR 4, 2, 4, 2 (Changes the foreground color at
Black
Blue
Yellow
White
for display of characters to red.)
all characters to purple.)
all characters to blue and changes the background used for display of chara- cters to black.)
coordinates 2, 2 to green.)
coordinates 3, 2 to white.)
coordinates 4, 2 to green and changes the background color at that location to red.)
80-
Page 83
2.6.2 Adding color specifications to the PRINT statement
j
Format
PRINT | [f, b] | variable
i ? I constant
expression J 1 expression
or
f
PRINT
1 9
f . . . . Foreground (character color) specification (a number from 0 to 7)
b . . . . Background color specification (a number from 0 to 7)
[f, b] USING "format string" ; variable
<
C t , I j constant
1 ( variable
<
I ,
= 1
variable ....)
Function
Example
Adding the color specifications to the PRINT and PRINT USING statements des-
cribed on pages 37 and 38 makes it possible to display characters in a variety of colors. In the format above, f indicates the character foreground color, and b indi- cates the character background color. If only the foreground color is specified, the current background color is used for display of characters; this is done by specify- ing the foreground color, followed by a comma.
If only the background color is specified, the current foreground color is used for display of characters; in this case, a comma must precede the background color specification.
(Example 1)
PR I NT (6, 5]
PR | NT C, 4) " FGH I J
PR ! NT (7, ) " VWXYZ
(Example 2) Let's try adding color to the automobile race program shown on page
46.
PR I NT C, 1 3 " H "
1 0
20
Q= I NT (5XRND (1 ) ) +2 : X = 33XRND (1 )
30 40 50
60
70
80
90
FOR A=1 TO 5
READ M$
PR I NT TAB (0)
PR I NT CO. 1 )
PR I NT (7, 1 )
NEXT A Y=1 0XRND (1 )
1 00
1 1 0
1 20
1 30 1 40 1 50
1 60
FOR A=1 TO Y PR I NT TAB (0) ; " " ; PR I NT TAB (37) ; " " : RESTORE: GOTO 20 DATA" aDB ". DATA" 6SBSSS " , "fflBBSffl" DATA " ME "
ABODE
; " " ; TAB (X) ; M$ ; TAB (37) ; " "
.... Displays the letters "ABCDE" in
yellow against a background of light blue. Displays the letters "FGHIJ" in yellow against a background of green. Displays the letter "VWXYZ" in green
against a background of white.
NEXT
With ordinary PRINT statements (those without color specifications), the fore- ground and background colors used for character display are those which have been specified with the latest COLOR statement.
-81
Page 84
2.7 Color Plotter-Printer Commands
The color plotter-printer commands described below can be used with the MZ-731 or, when the MZ1P01
color-plotter printer is connected, with the MZ-711, or MZ-721. The color plotter-printer can be
used in either of two modes: The text mode (for printout of program lists, results of calculations, or
other character data), or the graphic mode (for drawing figures and graphs).
Further, any of four colors (black, blue, green, or red) can be used for printout of characters and
graphics. This capability is particularly useful when using the printer in the graphic mode.
2.7.1 General information about the color plotter-printer
(1) The color plotter-printer operates in either of two modes: The text mode (for printout of the results
of calculations, program lists, and other character data) and the graphic mode (used for drawing figures and graphs). The printer will only operate in one mode at a time. (Graphic printer commands are ignored while the printer is in the text mode, and vice versa.)
(2) Printer parameters are reset when the printer is switched from the graphics mode to the text mode.
(In other words, the pens' X and Y coordinate settings are reinitialized.)
(3) The printer runs on power supplied from the main unit of the MZ-700, and is not equipped with a
separate power switch.
(4) The following switches are used to control operation of the printer.
a. Feed switch Advances the paper.
b. Reset switch Resets (reinitializes) the printer.
c. Pen change switch Used when replacing the printer's pens.
(5) There are four pen colors: Black, blue, green, and red. (6) When the printer is used in the text mode, any of three different sizes of characters can be printed.
The largest size permits a maximum of 26 characters to be printed on one line, medium size permits a maximum of 40 characters to be printed on one line, and the smallest size allows up to 80 characters to be printed on one line. Characters which can be printed when using the printer in the text mode are as shown below. No other letters, symbols, or graphic characters can be output while the printer is in this mode. In most cases, hexadecimal ASCII codes will be printed in a different 5 CD/0123456789: ; <=> ?@ABCDEFGH color if an attempt is made to print IJKLHN0PQRSTUUWXY2OTH tgh bxdrpcq graphic characters with the PRINT/- ozwsui Ok f ^ u£jn urn" I Aoa y< P statement or LIST/P command. SB00£4=S
BCDEFGHIJ KLUNOPQRSTUUUIXYZ [ \ ] T<- tgh
bxdrpcqazujsu I okf^ uBjn um' >Aol Aoa y<
XD 2 ' C D*+, /01 23456789 :
C
D*+/01 23456789 : ; <=>
; <=>
=
Xo ->ffl[H
2.7.2 Initial Printer Settings
The initial printer settings made when the BASIC interpreter 1Z-013B is started up are as follows. (1) Pen color: Black (2) Pen position: Left side of the carriage, (top line of 1 page.) (3) Mode: Text mode (4) Print size: 40 characters/line (standard size)
66 lines/page
82-
Page 85
2.7.3 Mode Specification Commands
These commands are used to place the printer in the text mode for printout of letters and numerics. This is the mode which is effective when the power is turned on; the initial character size is 40 characters/line. (1) MODE TN . (abbreviated format: M. TN)
This command returns the printer to the text mode from the graphic mode and sets the character size
to 40 characters/line.
(2) MODETL (abbreviated format: M. TL)
This command returns the printer to the text mode from the graphic mode and sets the character size
to 26 characters/line.
(3) MODE TS (abbreviated format: M. TS)
This command returns the printer to the text mode from the graphic mode and sets the character size to 80 characters/line.
*** CHARACTER MODE ***
80 character mode
ABCDEFGHJ.JKLMNOPQRSTUUIJXY?
40 character mode
ABCDEFGHIJKLNN-0PQRSTUUWXY2
26 character mode
ABCDEFGHIJ KLMN0PQRSTUUWXY2
(4) MODE GR (abreviated format: M. GR)
The MODE GR command is used to switch the printer from the text mode to the graphics mode for printout of charts and graphs. When switching to this mode, it is necessary for the BASIC program being executed to make a note of the character size being used immediately before the mode change is made. The reason for this is in order to return to the text mode when the BREAK key is pressed or a STOP command is encountered.
Note: Executing MODE command, every state returns to initial state excluding pen color and print size.
2.7.4 Pen color selection commands
: 3
black blue
red
(abbreviated format: PC.)
PCOLOR n
n : 0 n : 1 n : 2 green n
This command specifies the color to be used for printout of characters or graphics, n is a number from
0 to 3, with 0 corresponding to black, 1 to blue, 2 to green, and 3 to red.
In text mode, executing PCOLOR in text mode every state is on initial state excluding pen color. To keep current state execute PRINT/P CHR$(29) next color.
This command can be entered in either the text mode or graphics mode.
83-
Page 86
2.7.5 Text mode commands
2.7.5.1 TEST (abbreviated format: TE.) TEST This command causes the printer to print squares in each of the four different colors to check the color specification, quantity of pen ink, and so forth. (Only usable in
the text mode.)
2.7.5.2 SKIP
Format
Function
2.7.5.3 PAGE
Format
Function
2.7.5.4 LIST/P
Format
Function
0 12 3
(Black) (Blue) (Green) (Red)
SKIP n
n. . . A number in the range from —20 to 20 This command is used to feed the paper. Paper is fed n lines in the forward direction
when the value for n is positive; if the value specified for n is negative, the paper is fed n lines in the reverse direction. Note that PRINTER MODE ERROR will occur
if this command is executed while the printer is in the graphics mode.
PAGE n n. . .An integer in the range 1 n"S 72 This command specifies the number of lines per page. (Executable only in the text mode.)
LIST/P or LIST/P <LS-Le> Ls Starting line number Le Ending line number This command lists all or part of the program lines in memory on the printer. See the explanation of the LIST command on page 32 for an explanation of procedures for specifying the range of lines to be printed. Note that, when graphic characters are included in the program list, most of them will be printed in a different color as hexadecimal ASCII codes. See page 154 for the printer ASCII codes.
This command can only be executed in the text mode.
Value of n in PCOLOR n
(abbreviated format: L./P)
2.7.5.5 PRINT/P Format
Function
2.7.5.6. PRINT/P USING (abbreviated format: ?/P USI.) Except that output is directed to the printer, this is the same as the PRINT USING statement described
on page 38.
PRINT/P <I1; dj, I2, d2 In, dn > In Output list (numeric or string expressions) dn Delimiter This command outputs the data in the output list to the printer. For details on using this command, see the description of the PRINT command on page 37. See pages
82 for printout of graphic characters.
(abbreviated format: ? /P)
Page 87
2.7.6 Graphic mode statements
The graphic mode statements become effective after the MODE GR statement has been executed. When this statement is executed, the current pen location is set to the origin (X = 0, Y = 0). However, the origin can be set to any location. Be careful not to specify a location which is out of the print area, as this may damage the pen or cause other problems.
Max. Y=999
+Y
Current
pen location
(0,0)
(480,0)
-Y
Min. Y = —999
X-Y coordinates after MODE GR has
been executed. The allowable range of X is 0 to 480 and the allowable range of Y is -999 to 999.
Note: See page 88 for the HSET statement.
2.7.6.1 LINE Format
LINE Xj, yx <, x2, y2,..., xi, yi> or LINE %n, Xj, y1 <, x2, y2, . . . , xi, yi> n Integer from 1 to 16 xi Number indicating the X coordinate (xi = —480 to 480; the limit varies
depending on the current, pen location.)
yi Number indicating the Y coordinate (yi = —999 to 999)
Function
This statement draws a line from the current pen location to location (xl5 yx), then draws a line from (xj, yj) to (x2, y2), and so on. n specifies the type of line drawn as shown below, n = 1: solid line n = 2 to 16: dotted line If % is omitted, the previous value of n is assumed. The initial value of n is 1 (solid line).
Example
(Example 1) The following program draws a square with a side length of 240 units.
1 0
20
30 40
50
60
MODE
L I NE
L I NE L I NE L I NE
MODE
GR
240, 0
240, -240
0, -240
0, 0
TN
(Example 2) The following program draws the same square as the example above.
10 MODE GR 20 LINE 240, 0, 240, -240, 0, -240, 0, 0 30 MODE TN
o
o <u
a.
Max. Y = 999
+Y
o
o
QJ
OJ
-Y
Min. Y =-999
X-Y coordinates after the origin has been moved to the center of paper. (MOVE 240, -240: HSET)
•Switches to the graphic mode.
Draws a line from the origin to the center of paper.
Draws a line to the origin.
Returns to the text mode.
Page 88
(Example 3) The following program draws a rectangle with aside length of 240 units.
10 MODE GR 20 SQ= I NT (1 20XSQR (3) ) 30 LINE 962 , 240, 0, 1 20, -SQ, 0, 0 40 MODE TN
The lines indicated with n are as follows.
*## LINE I-16 ***
_N=
1
N--2
_N=3
N=4 _N=5 _N=6
N=7
N=8
_N=9 _N= 1
0
N=1 1 _N= 1
2
1
3
_N= 1
4
_N= 1 5
N=16
2.7.6.2 RLINE (abbreviated format: RL.)
Format
RLINE
Xi, yi <, x2, y2, . . . xi, yi... >
RLINE %n, Xj, yl3 <, x2,
y2, . . . , xi, yi . . . > n Integer from 1 to 16 xi Number indicating the X coordinate (—480 to 480) yi Number indicating the Y coordinate (—999 to 999)
Function
This statement draws a line from the current pen location to the location indicated by relative coordinates x1; yl5 then draws a line from that point to the location indicated by relative coordinates x2, y2, and so on. n is the same as for the LINE statement.
Example
This program draws the same rectangle as example 3 above.
10 MODE GR 20 SQ= I NT (1 20XSQR (3) ) 30 RL I NE 961 , 240, 0, -1 20, -SO, -1 20, SQ 40 MODE TN
Initial pen location Initial pen location
(0,0)
240/
(240,0)
120/3
Figure drawn ,'240,0},CI20,—SQ; 0,0
by LINE
(120,-120/3) I
Figure drawn ,'240.0'; (-120,-SQ") . '-120,SCf;
I -
by RLINE "* "" ---'' ''
Page 89
2.7.6.3 MOVE Format
Function Example
2.7.6.4 RMOVE Format
Function
Example
2.7.6.5 PHOME
MOVE x, y x Integer indicating the X coordinate (—480 to 480) y Integer indicating the Y coordinate (—999 to 999) This statement lifts the pen and moves it to the specified location (x, y). The following program draws a cross with a side length of 480 units.
10 MODE GR 20 LINE 480, 0 30 MOVE 240, 240 Lifts the pen at (480, 0) and moves it to
240, 240).
40 LINE 240, -240 50 MODE TN
Be sure to advance the paper before executing this program.
(abbreviated formed: RM.)
RMOVE x, y x Integer indicating relative X coordinate (—480 to 480) y Integer indicating relative Y coordinate (—999 to 999) This statement lifts the pen and moves it to the location indicated by relative coordinates (A x, A y) The following program draws the same cross as the example for the MOVE state- ment.
10 MODE GR
20 LINE 480, 0 30 RMOVE -240, 240 Lifts the pen at (480, 0), then moves it
—240 units in the X direction and 240
units in the Y direction.
40 50
Be sure to advance the paper before executing this program.
PHOME
This statement returns the pen to the origin. The following example draws the same cross in red as the example for the MOVE statement.
10 MODE GR
20 LINE 480,0 :MOVE 30 LINE 240, -240 40 PHOME 50 PCOLOR 3 60 LINE 0, 240,
L I NE
MODE
LINE 240,
240, -240 TN
(abbreviated format: PH.)
240, 240
Returns the pen to the origin.
480, 240, 480, -240, 0, -240, 0,
0
70 MODE TN
87
Page 90
2.7.6.6 HSET
Format
Function
Example
2.7.6.7 GPRINT
Format
Function
Example
(abbreviated format: H.)
HSET
This statement sets the current pen location as the new origin. With this feature, the origin can be set to the location which is most appropriate for drawing figures. A MOVE statement is frequently executed before executing this command.
10 MODE GR
20
MOVE 240, -240
30
HSET Sets the new origin.
40
GPRINT [n, @] , x$ GPRINT x$
n Integer indicating the character size (0 ~ 63) @ Integer indicating the direction in which lines of characters are printed.
x$ Character This statement prints the specified character using the specified size and direction.
When n and @ are omitted, the previous settings are assumed. Their initial values are n = 1 and @ = 0.
20 GPRINT "A" Prints "A" in the graphic mode. 30 GPR I NT (2, 23 , " A " --Prints an upside down "A" in the 26
The following figures show various examples of printout.
FOR 1=1 TO 360 STEP 30
50
L I NE 240XCOS CPAIC1 )*l/180). 240* SIN (PAIC1 )XI/1 80)
60
PHOME
70
NEXT
80
MODE TN
(abbreviated format: GP.)
(@ = 0 ~ 3)
80 characters can be printed on each line when n = 0; 40 characters can be printed on each line when n = 1; and 26 characters can be printed on each line when n = 2.
10 MODE GR
characters/line mode.
88-
N=0
N=3
A
N= I
A
N=2 N=5
A
N=4
A
A
>=0
»-3
\/@=2
Page 91
2.7.6.8 AXIS
Format
Function
Example
. . (abbreviated format: AX.)
AXIS x, p, r x Integer specifying the axis drawn (0 or 1) p Integer specifying the scale pitch (—999 to 999) r Integer specifying the number of repetitions (1 to 255) This statement draws the X-axis when x = 0 and the Y-axis when x = 1. The number of scale marks specified in r are drawn with a pitch of p.
The following example draws the X and Y axes with scale marks from —240 to 240
at 10 unit intervals.
10 MODE GR Switches the printer to the graphic
mode.
20 MOVE 240, 5 30 GPRI NT [1,0], " A " 40 MOVE 240, 0 Lifts the pen and moves it to position
A (240, 0).
50 AXIS 0, -10, 48 Draws the Y-axis from position A to
position B with scale marks included at 10-unit interval.
60 MOVE 240, -500 70 GPRI NT [1,0], "B" 80 MOVE 0, —240 Lifts the pen and moves it to position
C (0, -240).
90 GPRINT [1 , 0] , "C"
100 MOVE 0, -240 110 AXIS 1,10,48 Draws the X-axis from position C to
position D with scale marks included at 10-unit intervals.
120 MOVE 470,-240 1 30 GPRINT [1,0], "D " 140 MODE TN
The coordinates can be used in the same manner as ordinary Cartesian coordinates after setting the point of intersection of the X and Y axes as the new origin. (X =
-240 to 240, Y = -240 to 240)
-89
Page 92
2.7.6.9 CIRCLE Format
Function
Example
(abbreviated format: CI.) CIRCLE x, y, r, s, e, d x, y Location of the center (-999 to 999) r Radius (0 to 999) s Starting angle (in degree) e Ending angle (in degree) d Step angle (in degree) This statement draws a circle or arc with a radius of r and a step of d at location (x, y), starting at angle S and ending at angle e. A complete circle is drawn when s = 0, e = 360 and d = 0.2. Actually this statement draws a polygon; therefore, d must be as small as possible in order to draw a smooth figure. s must be smaller than e. When d = 0, lines connecting the center and the starting point and the center and the ending point are drawn.
10 MODE GR
20 LINE 480, 0, 480, -480, 0, -480, 0, 0
MOVE 240, -240
30
HSET
40 50
C
ROLE
60
C
ROLE
70
C
ROLE
80
C
ROLE
90
C
ROLE
100 MODE
0, 0, 240, 0, 360, 0. 2 240, 0, 240, 90, 270, 0. 2 0, 240, 240, 180, 360, 0. 2
-240, 0, 240, 270, 450, 0. 2 0, -240, 240, 0, 1 80, 0. 2
TN
90-
Page 93
2.8 Machine Language Program Control Statements
Several machine language program control statements are suported by the MZ-700 BASIC interpreter. With these statements, machine language programs can be linked with a BASIC program. Computer programming languages form a hierarchical structure as shown below. High level languages such
as BASIC automatically performs work required when lower level languages such as assembly language are
used. Although high level languages are convenient and easy to use, they cannot control the CPU directly.
The lowest level language (machine language) directly controls the CPU and provides high processing speed, but considerable skill is required for coding long programs.
Machine language program control statements enable sophisticated programming techiques which make it
possible to utilize the advantages of both BASIC and machine language.
Machine language programs can be generated and loaded into the machine language program area (reserved with the BASIC LIMIT statement) using the monitor or assembler and loader. Such machine language
programs can be called by BASIC programs with the USR ( ) function. Machine language programs
can also be loaded into memory using a BASIC program which uses the POKE statement to write each
step in machine code. The resultant machine language program can then be called by BASIC programs
with the USR ( ) function.
The memory map at bottom right outlines the concept of data access with POKE and PEEK, and of
calling machine language programs with USR ( ).
91-
Page 94
2.8.1 LIMIT (Abbreviated format: LIM.)
Format
Function
Example
LIMIT ad ad Address; either a decimal number from 0 to 65279 or a 4-digit hexa-
decimal number from $0000 to $FEFF. This statement limits the memory area which can be used by the BASIC interpreter, ad indicates the upper limit of the BASIC area, and the area from the following address (ad + 1) to $FEFF (65279) can be used for machine language programs or special data. LIMIT $AFFF
Limits the BASIC program area to $AFFF.
Note The area from $FF00 to $FFFF is used by the monitor as a work area, so it
cannot be used as the user area. The LIMIT statement must be used at the beginning of a BASIC program.
Monitor
BASIC interpreter
BASIC program area
2.8.2 POKE
Format
Function
Example
$ BOOO
SFEFF
Use LIMIT MAX to cancel the limit set by LIMIT ad.
POKE ad, d POKE@ ad, d
ad Address: either a decimal number from 0 to 65535 or a hexadecimal num-
ber from $0000 to $FFFF.
d Data to be written: a decimal number (0 to 255) or hexadecimal number
This statement writes data byte d to address ad. The POKE statement can write data to any memory location, regardless of the limit setting by the LIMIT statement. Therefore, careless use of this statement can destroy the monitor or BASIC interpreter. The POKE@ format is used to write data to an address in the user RAM area follow- ing 53248 ($D000). (See page 125.)
POKE SD000, S5F
POKE 53248. 95
The two statements above perform the same funcition.
Note A POKE statement specifying an address after $D000 writes data into the
video RAM area.
User area
($00 to $FF)
•LIMIT $AFFF
92-
Page 95
2.8.3 PEEK
Format
Function
Example
2.8.4 USR (Abbreviated format: U.)
PEEK (ad)
PEEK@ (ad)
ad Address in decimal or hexadecimal notation (0 to 65535 or $0000 to
$FFFF) This function returns the contents of the specified address as a decimal number from 0 to 255. Use the PEEK@ format to PEEK a user RAM area following 53248 ($D000).
The following program displays data stored in the area from 40960 ($A000) to
40975 ($A00F).
10 FOR AD= 40960 TO 40975 20 9 PEEK (AD)
30 NEXT AD
Format
Function
USR (ad)
USR (ad, x$) ad Address (decimal or 4-digit hexadecimal) x$ String data
This is a special function which transfers control to a machine language program
which starts at the specified address. As with CALL ad, so control is returned to the
statement following the USR function if the machine language program includes a
return instruction (RET or RET^cc).
When x$ is specified, the starting address of the memory area containing x$ is loaded into the DE register, then the length of x$ is loaded into the B register before
the machine language program is called. This makes it possible for a BASIC program to pass string data to a machine language program.
93-
Page 96
2.8.5 Preparing machine language programs
A machine language program which fills the entire display screen with the characters supported by the
MZ-700 is presented in this section as an example.
The following BASIC program loads such a machine program into memory and calls it.
10 LIMIT $BFFF 20 GOSUB 50 30 USRC$C0003
40 END 50 FOR I =49152 TO 4918! 60 READ M 70 POKE I,M 80 NEXT I 90 RETURN
DATA 197:REM PUSH BC
1 10 DATA 120 DATA 130 DATA 22,0:REM LO D, 0
DATA
1
40 150 DATA 1 , 232,3 REM LD BC,1000 1
60
DATA 243:REM DJ DATA
1
70 1
80 DATA 114^ REM ST0 190 DATA 35 :REM INC HL !
200
DATA 20 :REM
210
DATA 11 :REn DEC BC
220 DATA 120 : REM
230 DATA 177 :REM
DATA
240 250 DATA 211,225 : REM 260 DATA 251:REM
DATA 225 :REt1
270
DATA 209•REM
280 290 DATA 300
DATA
213: REM PUSH DE 229 :REI1 PUSH HL
33,0, 208 :REf1 LD HL,D000H
21 1 , 227:REM
194, 14, 192 REM
193 :REM POP BC
201:REM
OUT CE3HTA
:LD CHL3,D
INC D
LD A, B OR C JP N2,STO OUT CE1H],A EI POP HL POP DE
RET
:
Limits the BASIC area to $BFFF.
•Calls the machine language program.
Reads data for the machine language program from DATA statements and writes it into the machine language area.
Beginning of data for the machine language program.
Switches the memory block to video RAM. (See page
155).
Sets a display code to video RAM.
Switches the memory block to RAM. (See page 127.)
Returns to the BASIC program.
If the machine language program has been generated with the monitor and saved on cassette tape under
the file name DISPLAYCODE, use the following program to call the machine language program.
110 LIMIT SBFFF 110 LOAD "DISPLAYCODE" 1 20 USR CSC000)
94-
Page 97
2.9 I/O Statements
All external devices (including floppy disk drives) are connected to the MZ-700 through an optional interface board. The optional universal interface board makes it possible for the user to connect external devices such as an X-Y plotter, paper tape punch, and music synthesizer to the MZ-700. A port address selection switch is provided on the universal interface card to allow any port address from
0 to 239 (00H to EFH) can be assigned to any devices. Addresses 240 to 255 are reserved for optional
peripheral devices supplied by Sharp.
The INP and OUT statements allow the user to transfer data from/to external devices through the optional universal I/O card. The format of these statements is as follows.
INP #P, D Reads 8-bit data from port P, converts it into a decimal number and assigns
it to variable D.
OUT #P, D Converts a decimal number in variable D to binary format and outputs it to
port D.
These statements greatly extend the range of applications of the MZ-700 series computers.
95-
Page 98
2.10 Other Statements
2.10.1 ON ERROR GOTO (Abbreviated format: ON ERR. G.)
I Format ] ON ERROR GOTO Lr
Lr . . . . Destination line number (entry point of an error processing routine)
Function
2.10.2 IF ERN
Format
Function
Example
This statements causes execution to branch to line number Lr if an error occurs. The IF ERN and IF ERL statement can be used in a trap routine starting at that line to control subsequent processing according to the type of error and the line number in which it occurred. Including a RESUME statement at the end of the error pro- cessing routine makes it possible to return execution to the line at which the error occurred. Executing an ON ERROR GOTO statement cancels the error trap line number definied by the previous ON ERROR GOTO statement. The error trap line number definition is also cancelled by executing a CLR statement.
IF relational expression using ERN THEN Lr IF relational expression using ERN THEN statement IF relational expression using ERN GOTO Lr
Lr . . . . Destination line number
This statement branches execution to the error processing (trap) routine starting at line Lr or executes the statement following THEN when the result of <relational
expression using ERN> is true. ERN is a special function which returns a number corresponding to the type of error occurring. See page 159 for the error numbers.
The following shows an error processing routine beginning on line 1000 which causes
execution to branch to line 1200 if the error number is 5. 10 ON ERROR GOTO 1000 Declares the line number of the
error processing routine.
1 000 I F ERN = 5 THEN 1 200 Branches to 1200 if a string
overflow error has occurred.
96-
Page 99
2.10.3 IFERL
Format
Function
Example
IF relational expression using ERL THEN Lr IF relational expression using ERL THEN statement IF relational expression using ERL GOTO Lr
Lr . . . . Destination line number
This statement branches execution to the routine starting at line Lr or executes the statement following THEN when the result of Crelational expression using ERL> is true. ERL is a special function which returns the line number at which an error occurred. The following statement causes execution to branch to line 1300 if an error has occurred on line 250.
1010 IF ERL = 250 THEN 1300 The following statement returns control to line 520 in the main routine if the error number is 43 and the error line number is other then 450.
1020 IF (ERN = 43) X (ERL < >450) THEN RESUME 520
2.10.4 RESUME (Abbreviated format: RESU.)
RESUME <NEXT>
RESUME Lr
Lr . . . . Line number or 0
This statement returns control to the main routine from an error processing routine. The system holds the number of the line on which the error occurred in memory and returns program execution to that line or to another specified line after the error is corrected.
2.10.5 SIZE
Format
Function
The RESUME statement may be used in any of the following four forms:
RESUME Returns to the error line. RESUME NEXT Returns to the line following the error line. RESUME Lr Returns to line Lr. RESUME 0 Returns to the beginning of the main routine.
If the RESUME is encountered when no error has occurred, error 21 (RESUME ERROR) occurs. If the RESUME cannot be executed, error 20 (CAN'T RESUME ERROR) occurs.
PRINT SIZE This is a special function which returns the number of bytes in memory which can be used for storage of BASIC programs. For example, PRINT SIZE displays the number of free bytes of memory area.
97-
Page 100
2.10.6 PLOT ON (Abbreviated format: PL. ON)
| Format | PLOT ON
Function
Example
Note
This statement makes it possible to use the color plotter-printer as a display unit. Thus, the MZ-700 can be used without an external display screen. This statement is effective only when the color plotter-printer is installed and the MODE TN statement has been previously executed. PLOT ON A period " . " is printed to represent any characters which are not stored in the color plotter-printer's character generator (see page 156). The I INST 1 , | DEL | and " Q " keys are disabled by executing this statement. 1 CTRL | + change the pen.
[g]
can be used to
2.10.7 PLOT OFF (Abbreviated format: PL. OFF)
I Format | PLOT OFF
Function Example
This statement cancels PLOT ON made of plotter-printer operation. PLOT OFF
2.10.8 CONSOLE (Abbreviated format: CONS.)
I Format [ CONSOLE <Is, In< ,Cs, Cn »
Is : Starting line of the scroll area
In : Number of lines within the scroll area Cs : Starting column of the scroll area Cn: Number of columns in the scroll area i
Example
Function
CONSOLE 0. 25. 0, 40 CONSOLE 5, 1 5 CONSOLE 0, 25, 5, 30 CONSOLE 0, 1 0, 0, 10 CONSOLE
This statement specifies the size of the scroll area; i. e., the area which is cleared by PRINT " E ". The first example specifies the entire screen as the scroll area. The second specifies the area between lines 5 and 15 as the scroll area. The third specifies the area bet- ween columns 5 and 30 as the scroll area. The fourth specifies the 10x10 positions at the upper left corner of the screen as the scroll area. This statement is useful for excluding the left and/or right edges of the image from
the display area. When they are hidden behind the edges of the screen.
The last example does not specify the scroll area. When the scroll area is not speci- fied, it is possible to scroll the screen up or down. However, this makes it harder to perform screen editing because the values of Cn and In become smaller.
98-
Loading...