Chapter Fourteen

SECTOR
I/O
ROUTINES


The FMS performs sector I/O by calling the SIO routine in the OS ROM (Figure 1, control path 3). All sector I/O calls in the FMS occur from the BSIO routine. There are several other routines that are designed to set up information for BSIO. These routines deal with reading and writing sectors of a particular type such as data sectors, directory sectors, and the VTOC sector.

BSIO
Address — $76C 
Entry Registers — 
A = Sector number most significant byte.
Y = Sector number least significant byte.
X = If 1, then 128 byte 1/0 (810 drive). 
       If 2, then 256 byte I/O (815 drive).
Exit Registers —   
A = Status byte from DCB.
Y = Unknown.
X = IOCB and FCB number times 16.

Functions:

1) The sector number is stored in the DCB from the A,Y register pair. The DCB is the interface control block for SIO calls.
2) If the carry is clear, then the DCB is set up for read data. If the carry is set, then the DCB is set up for write data.
3) The serial bus ID for the disk, and the disk timeout values are placed into the DCB.
4) The error retry counter, RETRY, is set for four retries.
5) The I/O data length is set to 128 or 256 depending upon the data in the X register.
6) The serial I/O routine ($E459) is called to execute the I/O.
7) If the I/O operation was good, then the X register is loaded with the IOCB (and FCB) number times 16 from the CRFCB cell and the status byte from the DCB is loaded into the A register. Return is via the RTS instruction.
8) If the I/O operation was bad, then the retry counter is decremented. If the retry value is positive, then the I/O is retried. If the value is negative, then the routine is exited in the manner described in step seven.
DSIO
The DSIO routine is called to perform data sector I/O operations.
Address—$11F7 
Entry Registers — 
A = Sector number most significant byte.
Y = Sector number least significant byte.
X = IOCB and FCB number times 16.
Exit Registers —   
A = I/O condition code.
Y = Unknown.
X = IOCB and FCB number times 16.

Functions:

1) The sector buffer address is obtained from the zero page sector buffer pointer ZSBA ($47) and placed in the DCB buffer address field, DCBBUF.
2) The drive type byte is loaded into the X register from DRVTYP. If the drive is an 810, then the value will be one. If the drive is an 815, then the value will be two.
3) BSIO is called.
4) The DSIO caller is returned to via the RTS instruction.
RDDIR And WRTDIR
The RDDIR and the WRTDIR routines are used to perform Directory sector I/O operations. The RDDIR entry ($106E) sets the carry to indicate read. The WRTDIR entry ($1071) clears the carry to indicate write. Both of the routines continue at DIRIO.

DIRIO

1) Save the read/write flag (carry sense) on the stack.
2) Set the address of the directory buffer into the DCB buffer field, DCBBUF.
3) The CDIRS cell contains the number of the directory sector to he read or written. This value ranges from zero to seven. The DIRIO routine creates the actual sector number to read or write by adding $169 to the CDIRS value. The resulting sector number is placed in the A,Y register combination.
4) Continue at DSYSIO.
RDVTOC And WRTVTOC
The RDVTOC and WRTVTOC routine are called to initiate I/O to and from the VTOC sector. The RDVTOC routine ($108B) first checks the write required byte in the VTOC sector buffer. If the value of this byte is not zero, then the VTOC is already in the buffer (and has been changed). If the VTOC is already in the buffer, then the read does not have to be done; therefore, the RDVTOG routine will return to the caller. If the write-required byte is zero, then RDVTOC will clear the carry to indicate that the operation is read. The WRTVTOC routine ($1095) sets the write required byte to zero, then sets the carry to indicate a write operation. Both RDVTOC and WRTVTOC continue at VTIO.

VTIO

1) The read/write flag is pushed onto the stack.
2) The VTOC sector buffer address is moved from the zero page drive buffer address pointer ZDRVA ($45) to the DCB buffer pointer, DCBBUF.
3) The A,Y register combination is loaded with the VTOC sector number ($168).
4) Continue at DSYSIO.
DSYSIO
1) The read/write sense is popped from the stack.
2) The drive type value is loaded into the X register from DRVTYP.
3) BSIO is called.
4) If the I/O operation was good, then return to the caller via the RTS instruction.
5) If the I/O operation was bad, the exit via the ERRSYS exit (fatal system I/O error).
OPVTOC
The OPVTOC routine ($10BF) is used by various FMS routines to insure that the diskette is not write protected before executing functions that will write to the disk. This routine will read the VTOC via RDVTOC and then attempt to write the VTOC via WRTVTOC. If the diskette is write protected, the WRTVTOC will cause an I/O error exit (error number 144). If the diskette is not write protected, then the routine will return to the caller. When OPVTOC does return to the caller, the current disk VTOC is in the drive buffer.
Return to Table of Contents | Previous Chapter | Next Chapter