System information

5.5 A Sample Random Access Program
This section concludes with an extensive example of random access operation. The program
listed below performs the simple function of reading or writing random records upon command
from the terminal. When a program has been created, assembled, and placed into a file labeled R
A N D 0 M . C 0 M , the CCP level command
RANDOM X. DAT
starts the test program. The program looks for a file by the name X . DA T and, if found,
proceeds to prompt the console for input. If not found, the file is created before the prompt is
given. Each prompt takes the form
next command?
and is followed by operator input, followed by a carriage return. The input commands take the
form
nWnRQ
where n is an integer value in the range 0 to 65535, and W, R, and Q are simple command
characters corresponding to random write, random read, and quit processing, respectively. If the
W command is issued, the RANDOM program issues the prompt
type data:
The operator then responds by typing up to 127 characters, followed by a carriage return.
RANDOM then writes the character string into the "', . DA T file at record n. If the R command
is issued, RANDOM reads record number n and displays the string value at the console, If the Q
command is issued, the X . DAT file is closed, and the program returns to the CCP. In the
interest of brevity, the only error message is
error, try again .
The program begins with an initialization section where the input file is opened or created,
followed by a continuous loop at the label ready where the individual commands are interpreted.
The DFBC at 005CH and the default buffer at 0080H are used in all disk operations. The utility
subroutines then follow, which contain the principal input line processor, called readc. This
particular program shows the elements of random access processing, and can be used as the basis
for further program development.
5.4 A Sample File Dump Utility CP/M Operating System Manual
5-46