Here is a list of file handling commands which you can use:
*CAT | Gives a catalogue of all data files and programs on the cassette. It takes a very long time on a cassette. |
OPENIN | Opens a file so that it can be read. |
OPENOUT | Opens a new (empty) file for writing. |
OPENUP | Opens a file for reading or writing. |
INPUT# | Reads data from a file into the computer. |
PRINT# | Writes data from the computer into a file. |
BGET# | Reads a single character (byte) from a file. |
BPUT# | Writes a single character (byte) to a file. |
EOF# | Indicates whether or not the end of a file has been reached. |
CLOSE# | Indicates to the computer that you have finished with a file. |
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" 20 REPEAT 30 INPUT"Give the name of the stamp",name$ 40 PRINT#A,name$ 50 UNTIL name$="NO MORE" 60 CLOSE#A
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" 20 REPEAT 30 INPUT# A,name$ 40 UNTIL name$ = "NO MORE" 60 CLOSE# A
Line 40 could equally well read:
40 UNTIL EOF# A
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 but 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. |
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. |
*OPT on its own sets all the values to normal.