268 The VIC 20
User
Guide
CLOSING
DISK
FILES
As
a program writes
data
to a disk file, the data are first written to a
buffer. When the buffer
is
full, the data are written onto the diskette.
If
you
are done writing
data
to the diskette and the buffer
is
not yet filled, the
data
will
not
be written onto the diskette unless you close the file. Closing a file
writes the data in the buffer onto the diskette whether
or
not the buffer
is
full.
It
is
therefore very important that you close all files when you are done
writing
data
to them.
Note: You may keep only ten files open with the VIC, and only five
of
them to the disk drive. Therefore, it
is
advisable to close channels after
reading them as well as after writing to them, even though leaving a channel
that you have read will not cause the same kind of catastrophic failures as
failing to close a file that has been written to.
The PRINT#
Command
The
PRINT#
command
is
used to transfer
data
to the disk drive
or
any
other peripheral device. The VIC
20
automatically sends a carriage return
at
the end
of
each file record to terminate it properly. In some cases, such as
printing to the
1515
printer, you may want to send a carriage return and a
line feed to terminate the records in a file.
Use logical file numbers 1 through
127
to send a carriage return only,
and logical file numbers
128
through
255
to send a carriage return-line feed
after each record.
Reading a Data File
The INPUT# and GET# statements work in basically the same way on
disk files as they do on Datassette files. The INPUT# statement can read
strings no longer
than
80
characters. To read longer strings, it will be
necessary to use GET# and read the strings one byte at a time.
Random Access Flies
You can create random access files by directly addressing diskette
data
blocks and memory buffers. Each data block occupies a single sector of the
diskette. There are eight buffers available
on
the VIC 20, but four
of
them
are used for the Block Availability Map, variable space, command channel