ritrackdisklib
This library reads and writes the sectors of a floppy disk directly, through trackdisk.device or another device of the same kind, without the file system. A sector holds 512 bytes; a double-density disk has 11 sectors per track, 1760 in all, numbered from 0.
The units are the drives 0 to 3 (DF0: to DF3:). OpenDisk opens a unit
and must come first; CloseDisk closes it again, and the units still
open are closed when the program ends. Every other command except
DiskMotor names the unit it works on and returns 0 for a unit that is
not open. The sector commands return the device’s error code, 0 if they
worked (for example 29 when there is no disk in the drive). Since 0 is
also the result for a unit that is not open, If ReadSector(...) is
true on an error, not on success; open the unit first and test the
result for 0.
trackdisk.device keeps the sectors written to the current track in a
buffer of its own; MotorOff and CloseDisk write it to the disk, so
switch the motor off before the disk is taken out.
The library works on every Kickstart. Kickstart 1.x moves the sector
data only to and from chip memory; there the library passes a buffer
that is elsewhere through a chip memory buffer of its own.
DiskStatus, DiskIO, BootProg and DiskMotor work in Amiga mode
only.
Reading the boot block of the disk in DF0:
Dim buf.l(255)
If OpenDisk(0)
MotorOn 0
e=ReadSector(0,0,&buf(0),2)
MotorOff 0
CloseDisk 0
NPrint "error ",e
EndIfBased on the RI TrackDisk Lib guide by Red When Excited.
Library number 91.
Commands
BootProg
Marks the 1024 bytes at memoryaddress as a DOS boot block, puts a checksum in, and writes them to the first two sectors. Returns the device’s error code, 0 if it worked.
Statement or function, result .l. Help text: unit#,memoryaddress
Arguments: .l, .l
Amiga mode only. The checksum is the one Kickstart checks, so the Amiga boots from the disk if the boot code in the block is right.
CloseDisk
Switches the motor off and closes the unit. Returns -1 if the unit was open, else 0.
Statement or function, result .l. Help text: unit#
Arguments: .l
Before the motor stops, the sectors that trackdisk.device still holds
in its track buffer are written to the disk, as with MotorOff.
DiskIO
The address of the unit’s I/O request (an IOStdReq), for calling the device directly; 0 if the unit is not open.
Function, result .l. Help text: unit#
Arguments: .l
Amiga mode only.
DiskMotor
Returns -1 if the motor of one of the drives that the library has open is on, else 0. It has no unit argument.
Function, result .b. Help text: ; Returns -1 if motor is on
No arguments.
Amiga mode only. The library knows the state from its own commands:
the motor is on after MotorOn and after a ReadSector,
WriteSector, FormatTrack, WriteBoot or BootProg that worked,
and off after MotorOff and CloseDisk. What other programs do with
the drives is not seen.
DiskStatus
Returns a value other than 0 if the unit’s last request has finished, else 0.
Function, result .l. Help text: unit#
Arguments: .l
Amiga mode only. The commands of this library wait for their request to finish, so after them the result is not 0.
FormatTrack
Formats track track# and the tracks after it, writing the data at buffer. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#,track#,buffer[,numtracks]
2 forms:
.l, .l, .l.l, .l, .l, .l
Without a count it formats one track of 11 sectors, and the buffer must hold 5632 bytes. The count is a number of sectors, not of tracks: 11 formats one track, 22 two, and so on. trackdisk.device formats only whole tracks and refuses another count with the error code -4.
MotorOff
Switches the motor of the unit’s drive off. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#
Arguments: .l
First it has trackdisk.device write the sectors it still holds in its track buffer to the disk. The device writes that buffer only when it moves to another track, so switch the motor off, or close the unit, before the disk is taken out.
MotorOn
Switches the motor of the unit’s drive on. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#
Arguments: .l
OpenDisk
Opens a unit (0 to 3) of trackdisk.device, or of the device devicename$, for the other commands. Returns -1 if it worked, else 0.
Statement or function, result .l. Help text: unit#[,devicename$]
2 forms:
.l.l, $
Without devicename$ the unit is always one of trackdisk.device; a
device name counts only for the OpenDisk it is given to. A unit
outside 0 to 3 and a unit that is already open are refused with 0;
an open unit stays as it is.
ReadSector
Reads numsectors sectors, or one, from sector sector# on into the memory at buffer. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#,sector#,buffer[,numsectors]
2 forms:
.l, .l, .l.l, .l, .l, .l
The buffer must hold 512 bytes per sector. On Kickstart 1.x a buffer outside chip memory is read through a chip memory buffer of the library, one track at a time; without chip memory for it, nothing is read and the result is 31.
WriteBoot
Writes a boot block of 1024 bytes to the first two sectors of the disk - a bootable standard boot block, or the one at bootdata. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#[,bootdata]
2 forms:
.l.l, .l
Without bootdata the boot block starts the disk’s file system like
the one that the Workbench’s Install writes, and keeps the file
system type (OFS or FFS) of the boot block already on the disk. It
needs 1024 bytes of chip memory and returns 31 without them. With
bootdata the data is written as it is; BootProg also puts the
checksum in.
WriteSector
Writes numsectors sectors, or one, from the memory at buffer to the disk, from sector sector# on. As a function it returns the device’s error code, 0 if it worked.
Statement or function, result .b. Help text: unit#,sector#,buffer[,numsectors]
2 forms:
.l, .l, .l.l, .l, .l, .l
trackdisk.device keeps the sectors of the current track in its track
buffer until MotorOff or CloseDisk. On Kickstart 1.x a buffer
outside chip memory is written through a chip memory buffer of the
library, as with ReadSector.