Chapter 26. Cassette File Handling

Aside from saving programs, data files can be opened on the cassette: for example, to store addresses and telephone numbers.

Here is a list of file handling commands which you can use:

Gives a catalogue of all data files and programs on the cassette. It takes a very long time on a cassette.
Opens a file so that it can be read.
Opens a new (empty) file for writing.
Opens a file for reading or writing.
Reads data from a file into the computer.
Writes data from the computer into a file.
Reads a single character (byte) from a file.
Writes a single character (byte) to a file.
Indicates whether or not the end of a file has been reached.
Indicates to the computer that you have finished with a file.


To create a data file, you must first open it using OPENOUT. OPENOUT must be assigned to a variable, as follows:

A = OPENOUT"stamps"

In this case, the file called 'stamps' has been opened, and is allocated to a variable called A. A becomes the communication channel to the file, and all data sent to the file is routed via A. For example. if you want to write the names of all your stamps into the file, you use PRINT#.

10 A=OPENOUT"stamps"
30 INPUT"Give the name of the stamp",name$
40 PRINT#A,name$
50 UNTIL name$="NO MORE"

So after the file has been opened, its name is not mentioned again. The above program will allow you to make a list of names and, if the cassette player is switched on, they will be recorded on tape. Notice that the file must be closed after use, with CLOSE#.


To get the data back into the computer, you must open the file for reading using OPENIN. (The tape must be wound to the start of the file, and the PLAY button pressed).

A = OPENIN "stamps"

The variable name, in this case A, is completely arbitrary. You could equally well call it FRED, file, or anything else you wish. To read data from the tape into the computer's memory, use INPUT#:

10 A=OPENOUT"stamps"
30 INPUT#A,name$
40 UNTIL name$="NO MORE"

Line 40 could equally well read:



EOF# is a logical file operator which is TRUE when the end of the file has been reached.

PRINT# and INPUT# are used to write or read strings to and from the cassette file. The instructions BPUT# and BGET# are used to write and read single characters.

*CAT may be used anytime to give a catalogue of all program and data files on tape, and *. can be used as an abbreviation.


Cassette operations print messages on the screen, and sometimes cassette operations will produce errors. The message printed, and the computer's reactions to errors can be altered using *OPT:

*OPT1,X controls all of the error messages which are printed on the screen.

X = 0 Gives no messages.
X = 1 Gives short messages (as normal).
X = 2 Gives long messages, including load and execution addresses.

*OPT2,X controls the computer's action.

X = 0 Lets the computer ignore all errors, and carry on regardless. Messages can still be given.
X = 1 The computer asks you to try again by rewinding the tape (as normal).
X = 2 The computer aborts the operation.

*OPT3,X sets the inter-block gap in tenths of a second. This only applies to PRINT# and BPUT#. The gap on SAVE is fixed to 0.6 seconds.

*OPT on its own sets all the values to normal.