Random Access Example - Commodore 2031 User Manual

Hide thumbs Also See for 2031:
Table of Contents

Advertisement

If the buffers are not available, a NO CHANNEL error condition is generated.
The explicit buffer allocation can be used to reserve a buffer for position
dependent code as in the case of an EXECUTE command.
Execute a GET# statement to find the number of the allocated buffer. The byte
transmitted is the buffer number. A buffer number may only be obtained
PRIOR TO any write or read operations to that buffer.
The CLOSE statement clears the OPENed channel and writes the BAM to the
diskette that was last used by that channel. To avoid confusion, limit yourself to
accessing one drive with any direct access channel.

RANDOM ACCESS EXAMPLE

Since the BLOCK-ALLOCATE command returns the next available diskette
block through the error channel, it can be used in the allocation of records. This
feature allows creating a random file without being concerned with the actual
physical structure of the diskette. However, the allocated blocks must first be
recorded in a sequential or user file in order to be referenced by the BASIC
program.
The following random file example demonstrates the use of block access entitled
"RANDOMEXAMPLE". The example program is built upon a relative record
scheme and provides single record access through BASIC programming. Most
of the programming below line 2000 is relative record access. The field accessing
routines left-justify binary and alpha fields, and right-justify numeric fields.
In an actual situation, the program should generate error messages to the opera-
tor, or automatically take corrective action such as rounding numbers to fit a
field. It would also be possible to add data sorts and searches as well as key
fields to the program. Record size, including field markers, must be less than 254
characters. Field size is restricted to 80 characters because of the restrictions
of the BASIC INPUT# statement. Longer fields could be used if the BASIC pro-
gram were modified to use GET# for retrieval but that procedure would be much
slower.
56

Advertisement

Table of Contents
loading

Table of Contents