Tape operations

Structure of the file header

Files are recorded as block with a size of 512 bytes. The first block is the header record that is specially marked followed by the data blocks. The header record is comparable to a directory entry on a diskette, but there is no central directory on tape.
Because the tapes are compatible with the tapes from an IBM 5100 system and the character code on the 5100 is not the same as the EBCDI code on the 5110, all text strings have to be translated before writing or after reading. This affects file names in header records as well as whole text files (e.g. files with type 2).

 
Offset  Description/contents
------------------------------------------------------------------------------ 
00      File type (8 bit); 0 stands for a free file
01-02   File number (16 bit)
03-04   Size of marked file in kB (16 bit)
05	A non-zero value is used for blocked records
06-07   Number of used file blocks (16 bit)
...
80-90   File name (in tape code!)

92-9B	BASTMT \ for BASIC
9C-AF	BASKEY /   files
...
B8-BB	APLMSG \
BC-BF	APLWS1  \
C0-C3	APLSVI   \
C4-C7	APLWS2    > for APL files
C8-C9	APLMSZ   /
CA-CB	APLMXL  /
CC-CF	APLMX# /

CA-CB   logical record length (for type 9) (16 bit)
CC-CF   Number of logical records (for type 9) (32 bit)
...

All values are binary integer numbers.

Opening / finding a file

These operations are nearly indentical to those for disk files. The difference is that the tape must be searched until the file is found or the end of the marked area is reached. And you can only find by file number and not by file name.

The first operation must always be a Sense. The I/O supervisor is called as described in the paragraph IOCB. The IOCB for the Sense operation needs these values (in addition to the device address):

After a Sense the desired file can be looked for with a Find:

Important: During all operations on the same file IOCB_WA has to point to the same buffer. The I/O routines store information about the current file.

If the file has been found IOCB_Ret will be zero. It it could not be found (and no other error has occured) a value of $F1F1 = '11' is returned.
The header record is stored in the buffer on success. The entries are described above.

Reading or writing a block

Reading or writing a file can only be done one block at a time; only one block can be transfered per I/O call. The values for the IOCB are:

It is best to check after a Find if the file is big enough for writing. If this is not possible error codes 09 and 10 should be handled accordingly.

Translation of text

For compatibility reasons the tape code for the IBM 5110 is the same as for the 5100. This means that text files and strings have to be converted to EBCDIC after reading or from EBCDIC to tape code before writing. There is a special I/O command called "translate only" that can be used for this.

Freeing a file

Files can not be deleted on tapes like on diskettes. They can only be freed for new use. This is done by setting the file type in the header record (offset 0) to 0.

Writing a file

It is important to do all tape I/O operations in a fixed order otherwise the misplaced operation will be canceled and subsequent operations won't be possible. The following steps show how to write to a file:

Start ---> Sense
             |
             | ok
             v
           Find
             |
             | found
             v
           Change file type and file name
             |
             |
             v
           Write Header
             |
             | ok
             v
           Write (as often as needed)
             |
             | ok
             v
           Write Last (for last file block)
             |
             | ok
             v
           Find (same file!)
             |
             | ok
             v
           Change number of used tape blocks
             |
             |
             v
           Write Header  --> Done!