
                         Floppy drive documentation
                         --------------------------

	Since there's very little information available on the subject, I'm
documenting it as I go along.  Floppy drives are a pain in the ass to
program!  This should also help anyone who wants to improve the Retro/Tunes
driver.


My sources:
	* Specs for 8272A floppy controller
	* A short overview in an old book (c. 1986)
	* Examples: Linux, FreeBSD, Oberon-3

I/O Ports:
	3F0	Status register A (R)
	3F1	Status register B (R)
	3F2	Digital output (W)
	3F4	Main status register (R)
	3F5	Command status register -- for access to 4 internal regs
	3F7	PS/2 digital input (R)
	3F7	PS/2 configuration control (W)

Command execution:
	Command phase:
		Wait for 3F4 bit 6 to be 0 (ready to receive on 3F5)
		Send commands to 3F5
	Execution phase:
		FDC executes command
		INT 6 when done
	Result phase:
		INT 6 sets bit 7 (MSB) of byte 40:3E in BIOS data area when
			operation is complete. Reset before next operation.


Commands:
	Read data
	Read deleted data
	Write data
	Write deleted data
	Read track (diagnostic)
	Read ID
	Format track
	Scan equal
	Scan low or equal
	Scan high or equal
	Recalibrate
	Sense interrupt status
	Specify step & head load time
	Sense drive status
	Seek (move head)
	Version
	Invalid command

Routines & macros used in my floppy driver:
	write_port	port, value
	send_command	n, data		(data is n bytes)
	motor_on	drive
	motor_off	drive
	seek		drive, head, cylinder
	read_sector	drive, cylinder, head, sector
	write_sector	drive, cylinder, head, sector
	sense_drive	drive
	init_dma	r/w, address
	delay		milliseconds

On a 1.44 MB disk:
	Cylinder: 0 to 80
	Head: 0 or 1
	Sector: 1 to 18

Problems I encountered:
	- Timing: The motor needs time to spin up (up to 1 second). After a
seek operation completes, the head needs roughly 25 ms to settle. When
reading a disk, just keep retrying. Also, don't bother waiting for the
spin-up when you're reading.. it usually spins up fast. When you're writing,
*do* wait for the specified spin-up time.
	- Errors: I get lots of "can't find sector ID" errors.  This usually
indicated a major bug (like trying to read from a non-existent
track/head/sector).
