EXOS 2.1 Cassette Driver Specification

3. Using the Cassette Driver

The cassette driver allows a maximum of two channels to be open to it at a time, one for reading and one for writing. A channel which is opened for reading cannot be written to and vice versa. A reading channel is opened by making an open channel call and a writing channel by making a create channel call. The cassette driver is thus the only built in device driver which distinguishes between these two EXOS calls.


3.1 Opening Channels for Reading

A channel can be opened for reading a file from tape by simply doing an open channel EXOS call with device name "TAPE:". The unit number controls the use of remotes (see below) and the filename is optional. The cassette channel will require a channel RAM buffer of 4K (enough for one data chunk) and an error (.NORAM) will be returned if there is insufficient RAM. An error will also be returned if a cassette read channel is already open (.2NDCH), or if there is a proctection violation (.PROT - see below).

Assuming that all this was OK, the cassette driver will start the cassette motor (see section on remotes below), and start searching for a suitable header chunk. At this stage it will display the message "SEARCHING" on the status line.

When a header chunk is found, the name of this file from the header is examined. If it is not the same as the filename specified by the user, and if the user's filename was not null, then this is the wrong file. In this case the message "FOUND <filename>" will be displayed on the status line and the search for a suitable header chunk will continue.

If the filename is correct, or if the user's filename was null which means load the first file found, then the message "LOADING <filename>" will be displayed on the status line and the open channel routine will return with a zero status code to indicate success, after stopping the cassette motor. Read character or read block function calls can now be made to read the data.

At any point in this process, the STOP key can be pressed which will abort the searching and return immediately to the user. An internal flag will be set so that any attempt to read characters will result in an .EOF error. The user must close the channel.

The "LOADING" message is left on the status line until the channel is closed. It may of course be overwritten by the user.


3.2 Reading Data

Data can be read from a cassette read channel by simply making any combination of EXOS read character and read block function calls. Data from the tape is buffered in the 4K channel RAM area. When the channel is first opened this buffer will be marked as empty.

If there is data in the buffer when a read character call is made then the next byte will just be returned to the user immediately, and the buffer pointers adjusted.

If there is no data in the buffer when a read character call is made then another data chunk must be read from the tape. The tape motor will be started and the cassette driver will look for a chunk. When a chunk is found, if it is a header chunk then a .CCRC error is returned to the user and the end­of­file flag will be set so that no more bytes can be read. If a data chunk is found then the data from it will be read into the buffer with CRC checking.

Having read the chunk in successfully, the first character will be returned to the user. If this was the last chunk in the file then a flag is set which will prevent another chunk from being loaded. When this final chunk has all been read by the user, any further read character calls will result in .EOF errors being returned.

If a CRC error occurred in one of the 256 byte blocks in the chunk, then any previous blocks will be buffered as usual and can be read by the user. When all the valid blocks have been read, the next read character call will return a .CCRC error, and subsequent ones will return .EOF errors. No more data can be read from this channel.

The STOP key is tested all the time while data is being read from the tape. If it is pressed then it will cause an immediate return to the user, with the tape motor being stopped first. The end of file flag will be set so that any further read character calls will result in .EOF errors being returned. No data from the interrupted chunk or any later chunks, can be read.


3.3 Creating Channels for Writing

A create cannel EXOS call will be accepted as long as there is 4K of channel RAM available for the data buffer, a cassette write channel is not already open and there is no protection violation (see below). This is the same as for a reading channel.

Assuming that this is OK, the cassette driver will start the cassette motor and wait for a second or so for the tape speed to stabilise. The message "SAVING <filename>" will be displayed on the status line. After the delay the cassette driver will write out a header chunk for this new file, which will contain the filename, and then stop the motor. After this it will return to the user with a zero status code to indicate that the create was successful.

The STOP key is tested during the writing of the header chunk and if it is pressed then the write will stop immediately, the tape motor will be stopped and the channel will be marked as invalid so no data can be written to it. The channel will still be open and so must be closed by the user.

The "SAVING" message on the status line is left there until the channel is closed, although it may be overwritten by the user of course.


3.4 Writing Data

Data can be written to a cassette write channel by any combination of write character and write block calls. A write block call is treated exactly as if each character in the block was written individually. Data is written into a 4K buffer in channel RAM and is only written out to the tape when the buffer becomes full, or the channel is closed.

When a character is written, it is just added to the buffer and the buffer pointers adjusted. If there is still more room in the buffer then the cassette driver will return to the user immediately. If the buffer is now full then it will be written to tape as a data chunk.

The process of writing the data chunk is very similar to writing out the header chunk when the file was created. The motor is started and then there is a delay to allow it to come up to speed. The data chunk itself is then written out and the motor stopped. This process is interruptable with the STOP key.


3.5 Closing Channels

The cassette driver treats close channel and destroy channel EXOS calls identically. When a write channel is closed then the final data chunk must be written out. This is done even if there are no bytes in the buffer, to mark the end of the file. If the STOP key was pressed while data was being written then the channel will have been marked as dead, and in this case the final block will not be written out.

For any cassette channel the status line will be blanked to remove the "LOADING" or "SAVING" messages from the status line.


Next Chapter: Miscellaneous Cassette Features.



David Bouman. (dsbouma@cs.vu.nl)