Classic Computer Magazine Archive COMPUTE! ISSUE 51 / AUGUST 1984 / PAGE 10

File Structure On Atari

I have an Atari 800 and am trying to write a BASIC program to access records in a file. If I open a file with a 9 to append the file, it will use the entire sector to store the data. If I open the file with a 12, I can write to the entire sector, but eventually I will come up with an EOF (End Of File) error. Is there any way to get around this problem? Also, are there any good books (besides the DOS manual) on file and record structure for the Atari disk?

Charles Bentivegna

The OPEN command has four parameters:

OPEN IOCB#, access, aux, "filename"

IOCB# is a number from 1 to 7. There are eight Input/Output Control Blocks on the Atari. Each IOCB keeps track of an individual file. IOCB #0 is reserved for use by the screen editor (INPUT and PRINT). IOCB #7 is used for LPRINT, CSAVE, SAVE, LOAD, and CLOAD. When you OPEN a file to a particular IOCB, you use the same number when accessing the file with PRINT#IOCB; data or INPUT#IOCB, variable.

The second parameter, access, is either 4 (OPEN for read), 8 (OPEN for write), 12 (OPEN for read and write), or 9 (OPEN to append). The aux byte is usually just 0. Access numbers 4 and 8 are straightforward. OPEN for read lets you GET or IN­PUT from that file, but not PRINT or PUT to it.

Access number 8 lets you create a file, or send data out to a device like a printer with PUT and PRINT. With a disk drive, using access number 8 will either create a new file or replace a previous one. Access number 12 lets you read and write to an existing file.

It's a little strange. You can keep reading the file until you get to the place you want to change, then start writing. Once you start writing, however, you can no longer read, since you have started to replace a portion of the file. With access number 9, you can only write to the end of a file. To keep things simple, the data you append to an existing file starts on a new sector, rather than filling up the remainder of the last sector used by the file. If you add short items to files with access number 9, you can waste a lot of disk space over the long run.

The only way you can both read and write independently of the disk is to use random access files. With NOTE, you can store the relative sector number of each black as you write the file to the disk. You can then refer to the information you stored with NOTE, and use POINT to jump directly to any sector in that file. You can write a single sector (record) independently of the rest of the file, and instantly skip to any sector without having to sequentially read through all the previous data. We cannot go into detail on the use of NOTE and POINT here, but the DOS 2.0S Manual has most of the information you need. Another source for details on the working of DOS is Bill Wilkinson's Inside Atari DOS, available from COMPUTE! Books.