Low level disk routines ------------------------------------------------------------------ 1-301 Function Name: SetDevice Purpose: Set current drive. Call address: $C2B0 Input requirements: A Device number of drive (8-11). Output: $BA curDevice: Set to new device number. $8489 curDrive: Set to new drive number. Description: If the drive being specified is not the current drive then ExitTurbo is called to clear the current drive. Then locations $BA and $8489 are set to the new drive number. No other locations are affected, nor is anything actually done with the drive. 1-302 Function Name: ChangeDiskDevice Purpose: Change the device number of a drive. Call address: $C2BC Input requirements: A New device number for drive. $8489 curDrive: Current drive number. Output: $BA curDevice: New device number. $8489 curDrive: New device number. $8492-$8495 turboFlags: Appropriate bytes are reset and set. Errors: See appendix I. Description: The current drive is made ready, then the new device number is sent to turbodos which will change it. This results in the drive being set as the current drive but with a new device number, and with turbodos up and running. The status bytes at $8492-$8495 are changed, the old one is reset and the new one has bits 6 and 7 set. 1-303 Function Name: OpenDisk Purpose: Opens a disk to GEOS. Call address: $C2A1 Input requirements: $8489 curDrive: Current drive number. Output: $848B isGEOS: $00/$FF Geos format or not. $841E-$8465 Appropriate buffer will have disk's name. Errors: See Appendix I. Description: The current drive is initialized by calling NewDisk. GEOS format is checked for, and the disk's name is copied into the appropriate buffer at $841E-$8465. 1-304 Function Name: NewDisk Purpose: Initializes a drive. Call address: $C1E1 Input requirements: $04 R1L Track to position the disk drive head at. $05 R1H Sector to position the disk drive head at. Errors: See Appendix Description: Makes sure that current drive has turbodos running. It also positions the head over a particular sector. 1-305 Function Name: EnterTurbo Purpose: Sets up a drive with turbodos. Call address: $C214 Input requirements: $8489 curDrive: Current drive number. Errors: See Appendix I. Description: This routine initializes the current drive, sending turbodos if necessary. It then causes the drive to run turbodos. This routine is called by several of the disk I/O routines, most notably are GetBlock and PutBlock. Upon initializing the drive, the drive's status byte is set to the appropriate value. The status bytes are stored at $8492-$8495 and have the following bit definitions: Bit 7 Turbodos is loaded. Bit 6 Turbodos is running. 1-306 Function Name: ExitTurbo Purpose: Turn off turbodos. Call address: $C232 Input requirements: $8489 curDrive: Current drive number. Description: Turbodos is terminated in the current drive. 1-307 Function Name: PurgeTurbo Purpose: Clear the drive ready status. Call address: $C235 Input requirements: $8489 curDrive: Current drive number. Output: Appropriate status byte is reset. Description: This routine terminates turbodos in the current drive, and resets the drive status byte at $8492-$8495. 1-308 Function Name: GetDirHead Purpose: Read track 18, sector 0 from the disk. Call address: $C247 Output: $04 R1L Track number. $05 R1H Sector number. $0A-$0B R4 $8200 (curDirHead), address of buffer area. $8200-$82FF curDirHead: Data from track 18 sector 0. Errors: See Appendix I. Description: This routine sets up the pointers for GetBlock, then calls it to read the sector. This is generally used to get the BAM into memory. 1-309 Function Name: PutDirHead Purpose: Write track 18 sector 0 back to disk. Call address: $C24A Input requirements: $8200-$82FF curDirHead: Data for track 18 sector 0. Output: $04 R1L $12, track number. $05 R1H $00, sector number. $0A-$0B R4 $8200, address of buffer area. Errors: See Appendix I. Description: This routine sets up the pointers for PutBlock, then calls it to write the sector. This is generally used to update the BAM on the disk. 1-310 Function Name: GetBlock Purpose: Read a given track and sector. Call address: $C1E4 Input requirements: $04 R1L Track of sector to be read. $05 R1H Sector number to be read. $0A-$0B R4 Pointer to buffer. Errors: See Appendix Description: Loads and runs turbodos if it is not already there. Then reads the desired block from the disk into the buffer. 1-311 Function Name: PutBlock Purpose: Write a given track and sector. Call address: $C1E7 Input requirements: $04 R1L Track of sector to be written. $05 R1H Sector number to be written. $0A-$0B R4 Pointer to buffer. Errors: See Appendix Description: Loads turbodos if it is not already there by calling EnterTurbo. The desired block is then written to the disk by calling WriteBlock. Finally VerWriteBlock is called to verify the sector. 1-312 Function Name: ReadBlock Purpose: Read a sector from the disk. Call address: $C21A Input requirements: $04 R1L Track to be read. $05 R1H Sector to be read. $0A-$0B R4 Pointer to buffer for data. Output: Data is read into the desired buffer. Preparatory routines: EnterTurbo, InitForIO Errors: See Appendix I. Description: This routine is called by GetBlock to read a sector. The difference between this routine and GetBlock is that GetBlock calls EnterTurbo before trying to read the sector. This routine assumes that the drive is ready with turbodos running. 1-313 Function Name: WriteBlock Purpose: Write a sector to the disk. Call address: $C220 Input requirements: $04 R1L Track number. $05 R1H Sector number. $0A-$0B R4 Pointer to data buffer. Preparatory routines: EnterTurbo, InitForIO Errors: See Appendix I. Description: This routine is to PutBlock, as ReadBlock is to GetBlock. EnterTurbo must have been called prior to using this routine. 1-314 Function Name: VerWriteBlock Purpose: Conditionally write a sector to disk. Call address: $C223 Input requirements: $04 R1L Track number. $05 R1H Sector number. $0A-$0B R4 Pointer to data buffer. Preparatory routines: EnterTurbo, InitForIO Errors: See appendix I. Description: The first thing this routine does is try to read the desired sector. If the read succeeds, nothing happens. Three attempts are made at the read. After these read attempts, the sector is written to the disk, by calling WriteBlock. If the write succeeded without any errors, then the routine restarts itself. It will make five attempts at this loop. If after five attempts, the sector can not be read reliably, an error 39 results. This routine is usually called after the sector has been written out with a call to WriteBlock. PutBlock calls this routine to verify the sector. 1-315 Function Name: GetPtrCurDkNm Purpose: Compute the address of the disk's name. Call address: $C298 Input requirements: X Address to place pointer in. $8489 curDrive: Current drive number. Output: Location in zero page pointed to by X has the address of the current drive's name. Preparatory routines: OpenDisk Description: This routine computes the address of the current drive's name by multiplying the drive number (minus 8) by 18, then the offset of $841E (DrACurDkNm) is added to that. The result of the computation is stored at the zero page address in X. 1-316 Function Name: FindBAMBit Purpose: Check if a disk sector is in use. Call address: $C2AD Input requirements: $0E R6L Track to be checked. $0F R6H Sector to be checked. $8200-$82FF curDirHead: Track 18 sector 0, BAM buffer. Output: X Index into BAM of the appropriate byte. Z flag Set if the sector is in use. $11 R7H Index to track's data in BAM. $13 R8H Bit mask for the desired sector. Preparatory routines: GetDirHead Description: This routine is used by SetNextFree to test if a sector is already in use. 1-317 Function Name: SetNextFree Purpose: Allocate a block on the disk. Call address: $C292 Input requirements: $08 R3L Track to start scanning from. $09 R3H Sector to start scanning from. $8200-$82FF curDirHead: Track 18 sector 0, BAM. $848C interleave: Skew factor (default is 8). Output: $08 R3L New track number. $09 R3H New sector number. Errors: See appendix I. Description: This routine expects that the BAM is already in memory. It scans the BAM starting at a specified location, looking for a free sector. If one is found it is returned, otherwise an error results. The sector is allocated in the BAM, and the BAM must be updated to disk afterwards in order for the sector to remain allocated. 1-318 Function Name: BlkAlloc Purpose: Allocate enough sectors for a file. Call address: $C1FC Input requirements: $06-$07 R2 Number of bytes to be saved. $0E-$0F R6 Address of buffer for track and sector list. $8200 curDirHead: Directory header information Output: Buffer is filled with a set of tracks and sectors. Errors: See Appendix Description: Given a byte count and a pointer to a buffer, this routine attempts to allocate enough sectors. This routine is called prior to saving a file. The track and sector list is not limited in length, available disk space not withstanding. The list is terminated with a track number of zero and the appropriate byte count in the sector location. Note if an error occurs during the allocation, the sectors already allocated are not freed up. Either this must be done or the disk must be validated. 1-319 Function Name: NxtBlkAlloc Purpose: Allocate enough sectors for a file. Call address: $C24D Input requirements: $06-$07 R2 Number of bytes to be saved. $08 R3L Track to start looking from. $09 R3H Sector to start looking from. $0E-$0F R6 Address of buffer for track and sector list. Output: Buffer is filled with a set of tracks and sectors. Errors: See Appendix Description: This routine is almost identical to BlkAlloc. As a matter of fact, BlkAlloc falls into this routine after setting $08- $09 to point to track 1 sector 0. This routine allows the user to specify where on the disk to start looking for free sectors, possibly speeding things up. 1-320 Function Name: SetGEOSDisk Purpose: Converts a disk to GEOS format. Call address: $C1EA Errors: See appendix Description: This routine modifies the directory header to include the GEOS format message. It also allocates a sector to be used for the border from DESKTOP. 1-321 Function Name: ChkDkGEOS Purpose: Checks if a disk is GEOS format or not. Call address: $C1DE Input requirements: $0C-$0D R5 Pointer to buffer with track 18 sector 0. Output: Z Set if non-GEOS, reset if GEOS format. A,$848B isGEOS: $00 if non-GEOS, $FF if GEOS format. Description: This routine expects that track 18 sector 0 has already been read. It compares 11 bytes, starting with the 173rd, against 'GEOS format'. It sets $848B so that the current drive is kept track of. 1-322 Function Name: CalcBlksFree Purpose: Counts the number of free blocks in the BAM that is in RAM. Call address: $C1DB Input requirements: $0C-$0D R5 Pointer to buffer with track 18 sector 0. Output: $0A-$0B R4 The number of free blocks. Preparatory routines: GetDirHead Description: This routine expects that the BAM has already been read into memory. All that it does is add up the number of free blocks in each track. 1-323 Function Name: FreeBlock Purpose: Clear the BAM bit for a given track and sector Call address: $C2B9 Input requirements: $0C-$0D R6 Track and Sector to free $8200 curDirHead: directory header Output: $8200 curDirHead: BAM bit is cleared Errors: See appendix Preparatory routines: GetDirHead Description: This routine expects that the BAM has already been read into memory. The given BAM bit is cleared.