Sharp MZ-700, MZ-2Z009 Basic Manual

r:: r::
r::
r:::
r:::
r:::
r:::
r:::
r:::
r:::
-
-
-
1
Personal Computer
-
b'illHID
DISK BASIC MANUAL
SHARP
DISK BASIC
Manual
Introductory Note
This manual
is
based upon the DISK BASIC Interpreter MZ-2Z009, the system
software of the
MZ-700 personal computer.
(1) The DISK BASIC interpreter
MZ-2Z009 includes all commands
of
the
MZ-700 BASIC 1Z-013B. In
other
words, the DISK BASIC
is
an expansion
of
the BASIC 1Z-013B.
(2) For the multi-purpose MZ-700 personal computer, the system software
is completely supported by a software pack (cassette tape, floppy disk, etc.) in the
file
form.
This system software and the contents
of
this manual are subject to upgrading
changes for improvement, and for that reason the user
is
urged to particularly
note the file version number.
Please understand that
we
cannot be responsible
for damage incurred during,
or
as a result
of
operation.
(3) All system software for the
MZ-700 series personal computer
is
original
software of
SHARP
Corporation, and
is
covered by applicable copyrights. The
copying
or
reproduction
of
this software and/or this manual and its contents, in
whole
or
in part, and by whatever means and for whatever reason,
is
expressly
forbidden without the written permission by
SHARP
Corporation.
Introduction
We want to take this opportunity to thank you for purchasing the Sharp DISK BASIC system software. The manual provides a general explanation
of
the use and programming of the DISK
BASIC system software for the personal computer.
This system software
is
provided in the floppy disk format, and careful attention
should be given to the proper use and handling of the disk drive and the disks
themselves.
Please refer to page
108
of
this manual for information regarding the
proper handling
of
the floppy disks.
When the floppy disk
is
to be used, it
is
recommended that the disk, a copy which
is packed together with the original master disk (DISK BASIC), be used instead of the master disk. This
is
for protection
of
the master disk in the event of some unexpected
trouble which might make the master disk useless.
Please store the master disk in a
safe place.
Before using the DISK BASIC please carefully and completely read this manual in order to assure its correct use.
• Difference between the
CASSETTE
TAPE
BASIC
and
DISK
BASIC.
The following commands are extended and supplemented in the difference between the
CASSETIE TAPE BASIC and DISK BASIC.
Extension Page
Supplement Page
Supplement Page
RUN
.......................
36
DIR
........................
35
XOR
.......................
65
LOAD
.....................
37 LOCK
.....................
40
N()T
.......................
65
SAVE
......................
38 UNLOCK
................
41
OR
.........................
65
DELETE
.................
39
RENAME
................
42
AND
.......................
65
MERGE
..................
43
CHAIN
...................
44
ROPEN #
................
46
SWAP
.....................
45
INPUT #
.................
47
XOPEN #
................
50
WOPEN #
...............
48
KILL #
....................
54
PRINT#
.................
49
DEFAULT
...............
55
INPUT # ( )
...........
51
EOF#
....................
56
PRINT # ( ) ...........
52
LABEL
...................
57
CLOSE #
................
53
WAIT
......................
58
USR
.......................
62
SEARCH
.................
59
INP@
.....................
63
INIT
........................
60
OUT@
...................
64
In
addition to the above, there are the following differences:
CASSETIE
TAPE
BASIC DISK BASIC
If
the space key
is
pressed, the LIST Once the space key
is
pressed, the LIST
display stops, and if it
is
not pressed,
display stops, and, if it
is
pressed for a
the
LIST display continues.
second time,
the LIST display con-
tinues.
Relative to the data file, the
CASSET- Relative to the data file, the DISK
TE TAPE BASIC takes the format BASIC takes the format INPUT
#n,
INPUTrr, etc. etc
....
If,
for any reason, the program execu-
If
CONT
is
possible,
Ready
is
dis-
tion
is
interrupted, Ready
is
always played.
displayed.
CAS·SETTE
TAPE
BASIC
DISK BASIC
CONT
is
possible after execution
of
CONT
is
not possible after execution
of
END statement. END statement.
IcrRLI
+
I]]
has not effect.
IcrRLI
+
I]]
initialize the color and con-
sole,
aaQ
il!iIlIilW~iI
PbS:;r
8~.
Neglects space between reserved words;
Does not neglect space between re-
considers
GO~TO~lO
as
GOTO~
10.
served words. Does not consider
GO~TO~lO
as
GOTO~lO.
Compared to the CASSETI'E
TAPE
BASIC, the user area
of
DISK BASIC
is slightly reduced so there are some instances in which a program made in CASSETTE
TAPE
BASIC cannot be read in (LOAD) and executed
(RUN, GOTO). Because
of
extension, there are some instances that programs using BASIC
MONITOR with the USR function do not operate normally. The introduction
of
file descriptor changes the error display partially .
• Notes concerning
the
control of
the
floppy disk
drive in
MZ-
700
• System composition
t:J-
Display CPU MZ-700
• Can be controlled also by MZ-700 by setting up the ROM explained on the next page.
• Increase of floppy
'disk
interface-
ROM
Floppy
disk
drive
control
ROM
If
the DISK BASIC controls the floppy disk drive (MZ-1F02), connect the ROM chip
(see below) which
is
packed together with the DISK BASIC to the socket of the
floppy disk interface
(MZ-IEOS: optional).
If
this ROM
is
not connected to the floppy disk interface, the floppy disk drive cannot be controlled. Note the following points when connecting the
ROM to the interface:
• Take care not to drop, scratch or otherwise damage the ROM. Do not expose it to a strong magnetic field.
• Take special care not to break
or
bend the pins of the ROM.
Before pressing the ROM into the socket, be sure that its pins are correctly aligned with the socket holes. Be sure that the notches in the
ROM and socket match each other before pressing
the
ROM in.
Do not remove the seal attached to the
ROM.
Do not touch the pin of the ROM, because static electricity may destroy the ROM
contents.
Seal
N_-ctn
Contents
What
the DISK BASIC
is
....................................................................
: .......
10
Section
1:
DISK BASIC Outline
.................................................................
13
1.1 Starting the DISK BASIC
.................................................................
14
1.2 How to Copy the DISK BASIC
.........................................................
15
1.3 File Control
...................................................................................
17
1.4 Sequential Access File Control
..........................................................
18
1.5
Random Access File Control
.............................................................
23
1.6
PROGRAM
CHAIN (CHAIN)
.........................................................
26
1.7
PROGRAM
SWAP (SWAP)
............................................................
27
1.8 Reserved Words
.............................................................................
28
1.9 List
of
File Input/Output Devices
.....................................................
31
1.10 Initial Settings
................................................................................
31
Section 2: DISK BASIC Expansion,
New
Commands and Statements
...........
33
DIR
........................................................................................................
35
RUN
.......................................................................................................
36
LOAD
....................................................................................................
37
SAVE
.....................................................................................................
38
DELETE
.................................................................................................
39
LOCK
.....................................................................................................
40
UNLOCK
................................................................................................
41
RENAME
...............................................................................................
42
MERGE
..................................................................................................
43
CHAIN
...................................................................................................
44
SWAP
.....................................................................................................
45
ROPEN #
...............................................................................................
46
INPUT #
.................................................................................................
47
WOPEN #
...............................................................................................
48
PRINT #
.................................................................................................
49
XOPEN #
...............................................................................................
50
INPUT # ( )
........................................................................................
51
PRINT # ( )
...........................................................................................
52
CLOSE #
................................................................................................
53
KILL #
................................................... : ...............................................
54
DEFAULT
..............................................................................................
55
EOF(#)
..................................................................................................
56
LABEL
...................................................................................................
57
WAIT
.....................................................................................................
58
SEARCH
................................................................................................
59
INIT
........................................................................................................
60
USR
......................................................................................................
62
INP@
.....................................................................................................
63
OUT@
................................................................................................
64
Logical Operation
......................................................................................
65
Section
3:
BASIC Monitor Functions
.........................................................
67
3.1
Editing Format
.............................................................................
68
3.2 Printer Switch (P Command)
...........................................................
68
3.3 DUMP (D Command)
...................................................................
69
3.4 MEMORY SET (M Command)
.......................................................
69
3.5 FIND (F Command)
........................................................................
70
3.6 GOSUB (G Command)
...................................................................
70
3.7 TRANSFER (T Command)
..............................................................
70
3.8 SAVE
(S
Command)
.......................................................................
70
3.9 LOAD (L Command)
......................................................................
71
3.10 VERIFY (V Command)
...................................................................
71
3.11
RETURN (R Command)
.................................................................
71
Section
4:
Application Programs
.............................................................
73
Use of the File Converter
..........................................................................
74
Section
5:
DISK BASIC Summary
..............................................................
81
5.1
Summary of DISK BASIC Commands, Statements, Functions and
Operations
....................................................................................
82
5.1.1 Commands
....................................................................................
82
5.1.2 File control statements
.....................................................................
84
5.1.3 BSD control statements
....................................................................
86
5.1.4 BRD control statements
...................................................................
87
5.1.5 Error processing statements
..............................................................
88
5.1.6 Substitution statements
....................................................................
89
5.1.7 Input/output and color control statements
............................................
89
5.1.8 Loop statements
..........................................................................
: ..
91
5.1.9 Branch statements
...........................................................................
92
5.1.10 Definition statements
.......................................................................
93
5.1.11 Comment statements and control statements
.......................................
94
5.1.12 Music control statements
..................................................................
95
5.1.13 Machine language program control statements
......................................
96
5.1.14 Printer control statements
.................................................................
97
5.1.15 String control function
...................................................................
100
5.1.16 Tab function
................................................................................
101
5.1.17 Arithmetic operators
.....................................................................
101
5.1.18 Comparison logic operators
.............................................................
101
5.1.19 Other symbols
..............................................................................
102
5.2 Error Message List (DISK BASIC)
.................................................
104
5.3 Memory
Map........................................................
.....................
107
5.4 Use of the Floppy Disk
..................................................................
108
10
What the
DISK
BASIC
is
The DISK BASIC has a strong
file
control function relative to the cassette base
. BASIC. For example, it makes the most of the features of a disk base which has
high-speed read-outlwrite-in capabilities, and, more than simply serving for data storage, the
file
makes it possible to use the data area directly connected to the
computer system.
Moreover, because this
DISK BASIC also includes the control functions related to the
RS-232C
interface, it makes
it
possible to control various devices, by using the
MZ-SBI03
serial interface (optional).
Thus, it can be said that the
DISK BASIC
is
a new system software which permits the
expansion of the software range of the personal computer.
By
understanding this DISK BASIC and making full use of its many functions, the
user can create a higher level system.
• File
The computer can exchange data and programs between peripheral devices (floppy disk, cassette recorder, printer, etc.). The units of these data and programs are called files.
• File cl.ssificatlon
There are two types of files: data files and program files.
1
Data files ..... These files store numbers, characters, etc.
as
data.
(
BASIC
sequential access data files .....
BSD)
Files
BASIC random access data files ..... BRD
Program files ..... These files store programs just
as
they are.
(
BASIC
text programs ..... BTX )
Machine language programs .....
OBJ
Computer systems can be thought of as either of two fundamental types of systems: logical internal systems composed of data-processing equipment and main memories, and external filing systems composed of processed data and program banks.
11
• Data file control
There are two types of data files, depending upon the format of file access (the method of data read-out and write-in).
One is called the sequential access
file
and the other
is called the random access file. With the sequential access file, the file data
access
is
treated as one sequential block.
The
file
name
is
specified for one group of data, and such data are accessed
in
order
from the heading at the time of registration
or
read-out of the file. For the random access file on the other hand, the filed data are accessed at random. One random access file is composed of one data group designated
by
its own
file
name. Each group of data
is
registered
in
the
file
in
a parallel arrangement, and
write-in and read-out of each data group
is
possible
by
using the number (expression)
assigned to that data.
If,
for example, a collection of certain data can be handled
as
a connected group (such as, for example, data consisting of a series of decimal expressions used when producing machine language programs by BASIC
POKE command and elements of tables that
can be presented in order from the heading, etc.), collection of such data
in
a
sequential access
file
can be useful and effective. The registration of data
in
a random
access file, on the other hand, can be useful when it
is
necessary to not only consider
the group of overall data but to read-out and/or write-in each element (when it
is
necessary, for example, to rewrite data or to search, arrange, delete, etc.).
12
• Program file control
The BASIC program file control commands CHAIN (page 44) and SWAP (page 45) are for read-out of another program in the memory during the execution of one
program and moving the control to that program. As shown in the figure below, CHAIN has the same function as the
<goto
"filename">. (For detailed information, please refer to page 26.)
file
"ABC"
file "DEF"
10
PRINT "MZ-700"
,.-
10
PRINT "DISK BASIC"
20
20
,
,
,
,
100
CHAIN "DEF"
-
100
END
CHAIN
SWAP has the same function as the <gosub "filename">. After execution of
movement from the currently executing program to a separate program, it
is
then
possible to return to the first program. (For detailed information, refer to page 27.)
file
"GHI"
file "JKL"
10
PRINT "MZ-700"
,---
10
INPUT A, B
20
!
20
FOR
A=B
TO
A*B
50
SWAP "JKL"
f---
,
IL-
i
200
END
150
END
SWAP
In addition it
is
also possible to control the various files as utility programs files and
commands of the machine language program files.
Section 1
DISK BASIC OUTLINE
This section explains the features
of
the DISK BASIC and outlines the file
controls. First
of
all
is
an explanation
of
the DISK BASIC starting method.
Section 2 includes a syntax explanation
of
the new commands and statements
which the DISK BASIC has, and Section 5 includes a summary
of
all commands,
statements, functions and operations which it has.
14
1.1
Starting the DISK
BASIC
To make the DISK BASIC run, first perform initial loading by the IPL (Initial
Program Loader). The initial loading
is
easily executed. With the floppy disk drive
connected to the computer, switch the power supply
ON and then set the disk in which
the
DISK BASIC
is
included to drive number 1
(FDl).
After making the setting, the DISK BASIC
will
start when the power supply of the
computer
is
switched ON and F
is
input.
The figure below shows that
DISK BASIC
is
started, and the BASIC command level
condition
is
indicated by the flashing of the cursor.
Disk
Basic
Co
p y
rig
ht
nt
er
pr
et
er
MZ-
XXXXX
VX.
XX
(C)
1984
by
SHARP
Corp.
XXXXX
bytes
free
Note:
Ready
Please specify the default device
as
a cassette during write-in or read-in of a program
from a cassette tape, thus starting the
DISK BASIC.
DEFAULT
"CMT:"
(Refer to page 55.)
• Automatic execution of BASIC
text
AUTO RUN
The execution of AUTO RUN
is
included in the functions noted above. When the
DISK BASIC
is
loadeQ and the byte size which indicates the size of the text area
is
displayed, the master disk
is
accessed once again. When the initial loading finished,
the
DISK BASIC automatically executes the RUN"
AUTO
RUN
n command, Le., the
program text with the
"AUTO RUN"
file
name
is
read out from the same master disk,
and execution
is
from that heading. The program which defines the definable function
15
,
key
is
registered by this file name on the supported master disk.
In addition, because the NEW command
is
at the end of this program,
"READY"
is
displayed after execution, and the text
is
erased before the cursor begins flashing.
(Here, try the execution of
LOAD
"AUTO
RUN"
and check the list.)
If
you want to start a certain program after the start of the DISK BASIC, the file
name
of
that program should be saved on the master disk as
"AUTO
RUN."
1.2 How to Copy the Disk
Basic
Start the DISK BASIC and prepare a new floppy disk for copying.
Execute the directory
of
DISK BASIC (DIR: refer to page 35) and "FDCOPY".
01 R
"F
0 1 : "
ICRI
.........
Perform the directory
of
floppy disk drive number
1.
The screen becomes
as
follows when this com-
mand
is
executed:
OIR
"F01:"
01
RECTORY
OF
F01:
XXKB
FREE.
OBJ*"OISK
BASIS
Ul
XXX)H(
i:)e.\'\.;'t>~.
-IIIOBJ
*
"F
OCOPY"
I
iOBJ*
"TRANS"
r--J
BTX*
"AUTO
RUN"
I1
Ready
L_III
• Using the
ill
key, move the cursor to the position of the - sign and press the
~
key.
(RUN
"FOCOPY")
When "FDCOPY"
is
executed, the screen becomes as follows.
16
FD
For
mat I Copy
Ut i lit
Y
VX.
xx
[
Funct
i
on
I
F
For
mat
d i s k
C
Copy
d i s k
I
Bo
ot
[
Co
mma n d
are
a I
*-
Insert the floppy disk prepared into drive number
2.
When "F"
is
pressed, the screen
becomes
as
follows and the drive number
is
asked, so specify number
2.
*F
..............................
..
Drive
No.?2
OKI
Input the drive number. In this instance, the drive number
is
2.
When the drive number
is
input, the
floppy disk in this drive
is
initialized.
* _
.. .. .. .. .. .. ..
..
.
..
..
.. ..
.
..
.
..
..
Indicates the end of floppy disk initialization and the waiting condition for the next command.
If
there
is
SYSTEM software in the floppy disk inserted into the floppy disk drive, the
display
is
as
follows and confirmation
is
asked.
This
is
Master-Disk
For
ma t
[Y
I
NI?
N The meaning
of
display
is
as follows:
The floppy disk inserted into the
1>pecified
drive
contains the
SYSTEM software;
is
initialization
and erasure
OK?
If
it's OK, input Y; if it's not OK, input N.
17
*111....................................
If
N
is
input, changes to the condition of awaiting
the next command, and, if Y
is
input, the floppy
disk
is
initialized and changes to the condition of
awaiting the next command.
If
C
is
input, the screen becomes as follows:
* C
.............................
Copies the entire floppy disk.
Source
Drive
NO.?1
............
Specifies the drive of the inserted source disk (original disk) (drive number 1, in this instance).
De
s t n a t
ion
D r i
ve
No.?
2
...........
" Specifies the drive
of
the inserted destination disk
(new disk) (drive number 2, in this instance).
* III
..............................
Indicates the end of the entire floppy disk copying and
awaiting the next command.
Then the copying of the
DISK BASIC
is
finished. The DISK BASIC
is
started when
" ! "
is
input.
Note:
If
the source drive and the destination drive are the same, refer to REFERENCE
(page 78).
1.3
File
Control
There are, as mentioned in the "File" section, 3 types
of
files produced by the DISK
BASIC:
the 2 types
of
data files, sequential access files (BSD) and random access files
(BRD), and the
BASIC text (BTX) program files. The other type
of
file: the machine
language program files (OBJ),
is
a file which registers programs prepared in the
MONITOR mode, etc. on the floppy disk. This can be a program by itself
or
it can be
linked to a
BASIC text as a BASIC machine language area. Thus, even though it can
be used with the
DISK BASIC, it
is
not a
file
to prepare and to change its contents
with the
DISK BASIC.
18
DISK BASIC
Sequential Access File }
data file
BASIC Text Files }
L
..
__
--:---r-------. program file.
_ Machine Language
Program Files
As
the various
file
control commands are explained, first the preparation method, the
use, and the features of the 2 types of data files
will
be explained, followed
by
an
explanation of the use of the CHAIN and
SWAP commands of the program files.
1.4 Sequential
Access
File Control
Sequential access files are data files
in
which the registration or read-out of data
is
in
the sequential access format. The sequential access format is,
as
mentioned previously,
a format
in
which
access to the data
is
in sequential order from the heading.
The method of making a data
file
on a cassette
file
has already been explained
in
the
BASIC manual for the MZ-IZ013B. Sequential access for the DISK BASIC
is
exactly
the same except that the
file
is
made on the disk rather than a cassette. Naturally, the
access speed
is
much faster, and, because several new
file
control commands can be
used for disk access, the breadth of useful functions for
file
management
is
also
enlarged.
First,
we
will
compare the composition of sequential access commands for DISK
BASIC
and for CASSETTE BASE BASIC.
File registration (data write-in)
DISK BASIC
CASSETTE BASE BASIC
File open command WOPEN
#n,
"fjJename" WOPEN "filename"
Data write-in command PRINT
#n,
data
PRINTIT data
File close command CLOSE
#n
CLOSE
Cancel command
KILL
#n
--
19
i
File call (data read-out)
DISK BASIC
CASSETIE
BASE BASIC
File open command
ROPEN
#n,
"fjJename" ROPEN "fjJename"
Data read-out command
INPUT
#n,
variable INPUTfT variable
File close command CLOSE
#n
CLOSE
File end detection
IF
EOF
(#n)
THEN
--
As you can see, comparison of the various commands shows an almost I-to-l relationship. Note, however, that DISK BASIC commands always include elements #n.
These numbers are called logical numbers, and must always be designated for DISK BASIC file access. For
CASS~TIE
BASE BASIC, file access for data write-in or read-out
is
limited to one file. For DISK BASIC, however, contains several files in order to make the best use of its random access feature at will, so that it
is
possible to simultaneously control
several
(maximum 10) files. And, if a file
is
opened, optionally selected logical numbers can be defined and thereafter used for designation of the pertinent file, thereby eliminating the necessity
of
using the file name each time.
Example:
As a simple example, let's consider the registration of a person's name and address
in
the sequential access file. Thus, all available addresses can be stored one after the
other in the file. Take, for example, the following file:
filename =
If
ADDRESS LIST"
Name
I
Address
I
Name
I
Address
I
Name
I
Address
I
20
The reason that the space used for each name and each address
is
of various lengths
is
because the data registered by sequential access are not usually
of
a fixed length; the length varies according to the data. For the random access files, to be explained later, all
data are stored in boxes of a fixed length
of
32
bytes.
If,
as in this example, data are
to be handled
as
one group, and, as for the addresses above,
32
bytes
is
not sufficient,
and the lengths are different, then the use
of
the sequential access file
is
convenient.
A program can be made as described below, by
INPUT command, to substitute names and addresses alternately in string variables, register each person's file individually, prepare an ADDRESS LIST
of
a total
of
50 people, and then read out the prepared
file
and display on the screen the names and addresses
of
10
persons at a time.
Write-in
1 0 0
WO
PEN
# 3
"F
D 1 :
ADD
RES S LIS
T"
........
Designation of drive number and file name
1 1 0
FOR I =1
TO
5 0
120
INPUT
"name="
;NA$
130
INPUT
"address"
=
;AD$
140
PRI
NT
#3,
NA$,
AD$
...........................
Write-intofloppydisk
150
NEXT
I
160
CLOSE
#3
Read-out
200
ROPE N #4,
"FD1:
ADDRESS
LIST"
210
FOR I =1
TO
5
FOR
J
=1
TO
10
220
INPUT
#4,
NA$,
AD$
230
PRI
NT
NA$ : PRI
NT
AD$
240
NEXT
J
250
PRI
NT
"
PUSH
SPACE
KEY"
260
GET
X$
F
X$
"
THEN
280
270
GO
TO
260
280
NEXT
I
290
PRI
NT
"END"
300
CLOSE
#4
,
21
• To find
the
data end
What would happen if the data being read-out in order from the file surpass the number of data registered? In this case, an error does not occur. And a zero
or
blank
is
set
in
the read-out variable, but there
is
a special function
EOF
(#n)
(page 56)
which can detect the data end. When there
is
a data read-out by an INPUT command,
EOF
(#n)
becomes a true condition when there
is
no data.
As a result, if the
IF
EOF
(#n)
THEN
command
is
placed after the INPUT # command, then if
EOF
(#n)
becomes "true",
i.e. if the end
of
the data
is
found, the command after
THEN
will
be executed.
Here use the practice problems to become sufficiently accustomed to the use of the
BSD file.
Practice problems Problem 1
Using the program example on the previous page, change the program assuming that the number
of
people registered
is
unknown, read-out the file
10
persons at a time
until the end of the file
is
reached and display them.
Example solution
The following program might, for example, be considered.
300
ROPEN
#5,
" F D 1
ADDRESS
LI
ST"
3 1 0
FOR
I
=1
TO
1 0
320
INPUT
#5,
NA$,
AD$
330
I F E
OF
(
#5)
THEN
400
350
NEXT
360
PRI
NT
" PUSH
SPACE
KEY"
370
GET
X$: I F
X$
THEN
310
380
GOTO
370
400
CLOSE
#5
410
PRI
NT
" F I
LE
END" :
END
22
Problem 2
Divide, and re-register, the BSD file "ADDRESS LIST" into two: a BSD file which registers names only and a
BSD file which registers addresses only.
Example solution
500
ROPEN
#6,
" F D 1 :
ADDRESS
LIST"
5 1 0
WOPEN
#7,
" F
D1
:
na
me"
520
WOPEN
#8,
"F
D1
:
address"
530
INPUT
#6,
NA$,
AD$
540
I F E OF
(
#6)
THEN
600
550
PRI
NT
#7,
NA$
560
PRI
NT
#8,
AD$
570
GOTO
530
600
CLOSE
#6,
#7,
#8
610
END
Problem 3
Register the string input by INPUT command in a BSD file. But to close the file, key input
"CLOSE" and to cancel it, key input "KILL".
Example solution
100
WOPEN
#30,
"FD1:
DATA"
110
I
NPUT
"DATA
=
";A$
120
IF
A$="CLOSE"
THEN
CLOSE
#30:
END
130
IF
A$="KI
LL"
THEN
KI
LL
#30:
END
140
PRINT
#30,A$:GOTO
110
23
i
1.5 Random
Access
File Control
Random access files are data files in which the registration
or
read-out
of
data
is
in the
random access format. The
randoll\ access format
is
the
format in which the access
is done by specifying the array format. In other words, compared to the sequential access format in which access must be from the heading
of
the data, the random access format can be used for access to any data in the file at random. In order to access data in the random access file in a specified array,
PRINT # (page
49)
and INPUT # (page 47) are used, as described below, as expressions following
logical numbers.
PRINT
#n
(expression), data
INPUT
#n
(expression), variable
Designation of
tay
element
The expression
is
assigned by numbers
or
variables.
For example, the statement
INPUT
#7
(21), A$
means a command to read-out, to string variable
AS, the data registered as the 21st
element
of
the data collected as the random access file opened by logical number
#7.
Note that random access files in which data such as this can be accessed have the condition that all data must be
register~d
at a fixed length, Le., when numbers
or string variables are registered in the file, they must each be set within a "box" with a limited length
of
32
bytes.
expression
~
32-byte fixed length
{
~
+.
12345678+ElO
Random access 3
file 4 ABCDEFGHI
- 5
I-Ac::B-=C
_____
--t
6
:
+-
Variable A=O. 12345678+ElO
+-
String "ABCDEFGHI"
:.- String "ABC"
For numerical variables, even exponential expressions are always stored within the 32-byte length, but, because string variables can be as long as
249
bytes, a string which
exceeds
32
bytes cannot be registered in one data element of a random access file.
One other point which
is
different from sequential access files
is
that even though a
file
24
11
may be once closed and in the registered.condition, that same file can be made larger.
The random access file
"RND
1", for example, in which up to
20
expressions have
been registered, can be enlarged to a file with
30 "boxes" by registering data as 30 new
expressions.
"RND
I"
"RND
I"
1 1
2
Enlargement
2
a In addition,
.
data are registered
by
-----1~
expression =
30.
3
possible
3
20
30
Example: Let's take an example in which, by using a random access file, a simple stock list file
is
to be made. Each product
is
assigned a fixed number from 1 to 50, and the file will have four items: product name, unit price, number in stock, total price (unit price x number
in
stock) and comments.
In order to register the stock data for each product, first the product number
is
input,
and then the information to be registered for each item
is
input.
The program execution
is
ended, however, when "0"
is
input.
Registration of stock data
100
XOPEN
#5,
"STORELIST"
110
INPUT
"product
no.";K
120
IF
K=O
THEN
300
130
I
NPUT
"product
name=";
N$
140
INPUT
"uni
t
pr
ce=";
P
150
INPUT
"i
nventory
count
1 6 0 I N
PUT
" c 0 mme n t
=";
C $
170
T
=P*
S
"
S
180
PRINT
#5(K*5-4),N$,P,S,T,C$
190
GOTO
110
300
CLOSE
#5
310
END
25
The random access file prepared in that way would be as follows.
If
product no.
K=12, 5 data are registered in elements corresponding to array expressions
56
- 60.
Data
position
a expression
~
KJl:5-4}
55
___
56
K=12
57
58
59
60
61
N$
p
S
T
C$
d
ata
.....
product name
.....
unit price
.....
inventory count
.....
total amount
.....
comment
BRD
file
"STORE
LIST"
In this way, then, data can be set in any specified array in the file. As a result, unlike the sequential access file, in which data is overlaid in
order
from the heading, it
is
also
possible for there to be vacant addresses in the filed data.
And, because data can be accessed
at
will, it
is
also possible to easily rewrite data.
Use the practice problem to become accustomed to the use
of
the
BRD
file.
Problem Let's read-out the random access file
"STORE
LIST" made here and read-out the inventory data for a certain product. The program execution
is
ended, however, when "0"
is
input.
Read out
of
inventory data
500
XOPEN
#7,
"STORE
LI
ST"
5 1 0
520 530
INPUT
INPUT
PRI
NT
"
pro
d u c t
no.
=";
J : I F J =0
THE
N
700
#7(
J*5-4),
N$,
P,
S,
T,
C$
"
NO.
";
J :
PR I NT
"p
rod
u c t n a me
";
N$
540
PR I NT
"u
n i
price
";P
550
PRI
NT
"i
nventory
count"
S
560
PR I NT
"t
0 t a I a
mo
u n t
";
T
5 7
0 P R I N T
"c
0 mme n t
";
C $
580
GOTO
510
700
CLOSE
#7
710
E NO
In this way then, even for many products, the inventory data can be quickly read-out by inputting the product number.
26
1.6 Program Chain (CHAIN)
Next, following the data
file
control commands,
will
be an explanation of program
file
controls. The commands explained here are CHAIN (page
44)
and SWAP (page 45).
When these commands are used, the program
is
registered on the floppy disk in job
units and, while the program
is
being run, a separate program can be read-out and control moved to it, i.e., a program can be connected (CHAIN) to a program registered on the floppy disk, and can be read-out
(SWAP)
in
the form of a sub
routine. The CHAIN command, which connects and links the programs,
will
be
explained first.
The form of a CHAIN command can be, for example,
as
follows:
700
CHAI
N
"F01:
TeXT
2"
This statement means that the program currently within the text area
is
made NEW
(although the variable
will
be retained), the "TEXT
2"
file
registered on the floppy
disk
in
drive number 1
is
to be overlaid (that is, to overlay text areas and be read out),
and control
is
moved to the heading of that text.
When this statement
is
executed, control
will
move away from the BASIC text now
running,
newly
read out the "TEXT 2" text, and control
will
move to that heading.
When the program CHAIN
is
executed, the variable, and the function defined
by
DEF FN,
will
be transferred to the CHAIN destination program.
The CHAIN command function can be taken
as
<goto "filename"> .
.
file
"ABC"
~
file
"DEF"
-
10
PRINT "SUNDAY"
10
INPUT
A,S
,
2i
PRINT A, B
:
100
CHAIN "DEF"
r-
300
CHAIN "GHI"
When the CHAIN command
is
used, a large program (even a huge program which
exceeds the
BASIC text area) can
be
divided and,
as
shown in the figure above, can be
connected. When one program
is
finished, the data are left
as
is, and the following programs are chained one after another. The CHAIN command can be considered indispensable if complicated and diversified data must be processed.
27
1.7 Program Swap (SWAP)
Program files on the floppy disk are read-in to the memory, and control
is
moved to
this program,
by
SWAP command but, when this program
is
finished, the original
program (the program which did the
SWAP command) can be reset. This movement
is
exactly
in
the same
way
as the sub-routine
in
the program, and the reset to the original
program becomes a return to the next command, which did the
SWAP command. As a
result, the
SWAP command can be taken
as
<gosub "filename">.
In
order for this operation to be made, the program which has the SWAP command
is temporarily shunted to the floppy disk during SWAP execution. Then the program area
is
made NEW, and another program
is
read in. After the end of the other
program, the original program
is
read in. The usual form of the SWAP command
is:
SWAP"
FDn
: filename"
This
is
a command to SWAP the sub-program designated
by
the "filename" registered
on the floppy disk in drive number n (n = 1
- 4), and the shunting of the program
prior to the read-in of the other program
is
done on the floppy disk
in
the drive set
by
the default condition. Therefore, a floppy disk on which it
is
possible to temporarily
write-in the program text must be set in that drive. The
SWAP level must not exceed the 1 level. In order to understand the
SWAP command, let's take a simple example and follow
the movement of the program file.
Program now
in
text area
10
REM
COMPOSER
2 0 M 1 $
~.
" A 7 B 6 + C 3 A 7 A 3 "
30
M2$="B+C+D+E
6A3"
4 0
M3
$ = " + F 6 A 3 +E 7 H
50
PR I
NT
"P L AY
T HE
CELL
0"
60
SWAP
"FD2:
PLAYER"
70
PRINT
"VERY
GOOD"
80
END
28
Program
file
"PLAYER"
10
REM
CELLO
PLAYER
20
MUSI
C
M1$, M2$,
M3$
30
PRI
NT"OK7"
40
E
NO
On slave disk in drive number 2 First,
"COMPOSER"
is
within text area and
is
executed.
Text
area
~
Dr:ve
File
Corn oser
2
"PLAYER"
"PL:'{'y
THE
CELLO"
The text
is
first shunted to the disk in
FDl
taking
DIR
by the SWAP command of line
number 60, and the area
is
made NEW.
r----------,~r-l~lr(C~O-M-P-O~SE~R~)1
NEW I I 2 .
"PLAYER"
.
1--
___
--'
Next, BTX "PLAYER"
is
overlaid and executed. The melody
is
played.
Text
"PLAYER"
At the end, the shunted COMPOSER
is
reset and says "VERY
GOOD."
Reset
r-1-!-·C-~-M-PO--SE-R-
..
-'r1r--r-I,,-p-LA-Y-E-R-
..
...,:
I
~~~~e~OOD
..
1.8 Reserved Words
The DISK BASIC text
is
composed of reserved words, also called key-words, the
operand, separator and data. The
DISK BASIC the reserved words, which are special words to execute certain determined functions, and commands, statements and functions are appropriate to these words. Because the reserved words are certain words used in order to execute special commands, the programmer cannot use them as names of variables, arrays, etc. Next page shows a listing
in
alphabetical order of all
of
the DISK BASIC reserved words.
(The numbers to the right
of
the reserved words indicate the reference page.)
When there
is
a (MZ) notation, refer to the Personal Computer OWNER'S
MANUAL or to the DISK BASIC SUMMARY of this manual.
29
161
ABS
...............................
MZ
K]
GET
...............................
MZ
AND
................................
65
GOSUB
..........................
MZ
ASC
...............................
MZ
GOTO
............................
MZ
ATN
...............................
MZ
GPRINT
.........................
MZ
AUTO
............................
MZ
!HI
HSET
............................
MZ
AXIS
..............................
MZ
rn
IF
..................................
MZ
!HI
ByE·
...............................
MZ
INIT
.................................
60
~
CHAIN
.............................
44
INP@
..............................
63
CHR$
.............................
MZ
INPUT
............................
MZ
CIRCLE
.........................
MZ
INPUT #
..........................
47
CLOSE #
........................
MZ
INPUT # ( )
....................
51
CLR
..............................
MZ
INPUTrr
.........................
MZ
CLS
................................
MZ
INT
................................
MZ
COLOR
..........................
MZ
!KI
KEY
LIST
.......................
MZ
CONSOLE
......................
MZ
KILL #
.............................
54
CONT
............................
MZ
[1J
LABEL
.............................
57
COS
...............................
MZ
LEFT$
............................
MZ
CURSOR
........................
MZ
LEN
..............................
MZ
~
DATA
............................
MZ
LET
...............................
MZ
DEFAULT
........................
55
LIMIT
...........................
MZ
DEFFN
..........................
MZ
LINE
..............................
MZ
DEFKEY
.......................
MZ
LIST
......................... ~ .....
MZ
DELETE
..........................
39 LIST/P
............................
MZ
DIM
..............................
MZ
LN
................................
MZ
DIR
.................................
35
LOAD
..............................
37
~
END
.............................
MZ
LOCK
..............................
40
EOF
(#)
........................... 56
LOG
.............................
MZ
ERL
..............................
MZ
M
MERGE
...........................
43
ERN
...............................
MZ
MID$
.............................
MZ
ERROR
..........................
MZ
MODEGR
......................
MZ
EXP
...............................
MZ
MODE
TL
......................
MZ
!El
FOR
...............................
MZ
MODETN
......................
MZ
MODE
TS
.......................
MZ
Loading...
+ 79 hidden pages