System information
Thus, the r0, r1 byte pair is treated as a double-byte, or word value, that contains the record to
read. This value ranges from 0 to 65535, providing access to any particular record of the
8-megabyte file. To process a file using random access, the base extent (extent 0) must first be
opened. Although the base extent might or might not contain any allocated data, this ensures that
the file is properly recorded in the directory and is visible in DIR requests. The selected record
number is then stored in the random record field (r0, r1), and the BDOS is called to read the
record.
Upon return from the call, register A either contains an error code, as listed below, or the value
00, indicating the operation was successful. In the latter case, the current DMA address contains
the randomly accessed record. Note that contrary to the sequential read operation, the record
number is not advanced. Thus, subsequent random read operations continue to read the same
record.
Upon each random read operation, the logical extent and current record values are automatically
set. Thus, the file can be sequentially read or written, starting from the current randomly accessed
position. However, note that, in this case, the last randomly read record will be reread as one
switches from random mode to sequential read and the last record will be rewritten as one
switches to a sequential write operation. The user can simply advance the random record position
following each random read or write to obtain the effect of sequential I/O operation.
Error codes returned in register A following a random read are listed below.
01 reading unwritten data
02 (not returned in random mode)
03 cannot close current extent
04 seek to unwritten extent
05 (not returned in read mode)
06 seek Past Physical end of disk
Error codes 01 and 04 occur when a random read operation accesses a data block that has not
been previously written or an extent that has not been created, which are equivalent conditions.
Error code 03 does not normally occur under proper system operation. If it does, it can be cleared
by simply rereading or reopening extent zero as long as the disk is not physically write protected.
Error code 06 occurs whenever byte r2 is nonzero under the current 2.0 release. Normally,
nonzero return codes can be treated as missing data, with zero return codes indicating operation
complete.
5.2 Call Conventions CP/M Operating System Manual
5-31