Implementation of the WD17xx in the Z80 Emulator

Command Summary

	Type	Command		 B7 B6 B5 B4 B3 B2 B1 B0

	1	Restore		 0  0  0  0  h  V  r1 r0 | r1, r0 = Dont Care
	1	Seek		 0  0  0  1  h  V  r1 r0 | r1, r0 = Dont Care
	1	Step		 0  0  1  u  h  V  r1 r0 | r1, r0 = Dont Care
	1	Step In		 0  1  0  u  h  V  r1 r0 | r1, r0 = Dont Care
	1	Step Out	 0  1  1  u  h  V  r1 r0 | r1, r0 = Dont Care
	2	Read		 1  0  0  m  F2 E  0  0  | E = Dont Care
	2	Write		 1  0  1  m  F2 E  F1 a0 | E, F1, a0 = Dont Care
	3	Read Address	 1  1  0  0  0  E  0  0  | E = Dont Care
	3	(Read Track)	 1  1  1  0  0  E  0  s  | E, s = dont care
	3	Write Track	 1  1  1  1  0  E  0  0  | E = dont care
	4	Force Interupt	 1  1  0  1  I3 I2 I1 I0 | Ix = imm, index, rdy to nrdy, nrdy to rdy  

the m bit is implemented, normal exit for multiple reads and writes is via RNF or Force Interrupt. 

the bit F2 can either be the "b" bit or the "S" bit 

 as the "b" (block length) bit, it is Dont care (all sectors are IBM standard size encoded)
 as the "S" (side select) bit, it selects which side of a disk is selected

the bit F1 can be either  "0", "a1" or "C"

 as "0" it is a dont care
 as the "a1" (Address Mark 1) bit, it is a dont care
 as the "C" (Compare Side enable) bit, it is a dont care (compare side is always done)

The use of F2 can affect how a program works with the simulated WD17xx, so its use can be selected as an Option (Use WD1795 side select). (NOTE - some FDCs, like the VF2, do not use the side select bit in the WD Command, even though the VF2 uses a WD1795, so F2 should be selected as the "b" bit to prevent the WD commands from erroneously selecting the wrong side)

Since "b" is always a dont care and assumed to be 1, all disks are assumed to be IBM standard block sizes where 

	ID 	Size
	00	128
	01	256
	02	512
	03	1024

Using these rules, the simulated WD17xx should work as a WD177x,WD179x.

Force interrupt works correctly. Interrupts can be generated immediately, on Ready to Not ready, on not ready to ready, and on each index pulse. Index pulses are generated for each ready drive, at either 300 RPM or 360 RPM (depending on the type (8 or 5 inch)).

Force Interrupt can generates an interrupt when used with the FDC16/64. DRQ can not generate an interrupt for the FDC16/64, however any interrupt as a result of WD INTRQ can. Most interrupts are immediate since the WD finishes all but read and write commands before the access to the IO port is completed.


Status type 1

S7 Not Ready - if no Disk Image is Open
S6 Write Protect - if Disk Image is R/O
S5 Head Loaded - 1 to indicate loaded is asked to load, else 0 to indicate not loaded
S4 Seek Error - 1 to indicate error only if V flag set, 
		then only if track is not in Image file(implies Compare side)
S3 CRC error - always 0- no error
S2 T0 - set if cylinder = 0
S1 index - always 0
S0 Busy - always 0 (because type 1s complete before returning to instruction after load of CMD REG)

status type 2 and 3

S7 Not Ready - if no Disk Image is Open
S6 Write Protect - if Disk Image is R/O
s6 Record Type - always 0 (data mark)
S5 Write Fault - if Disk Image is R/O or RNF during write
s5 Record Type - always 0 (data mark)
S4 RNF - if RNF (wrong side or off disk)
S3 CRC - always 0
S2 Lost data - if not enough reads of Data to satisfy transfer
S1 DRQ - set during tranfers, reset at end or if timeout
S0 Busy - 0 if command completes or times out, 1 if tranfer under way.

The Read Track command is not implemented and alway return Not Ready, Not Busy

The Write Track command does not work the same as the real WD17xx's WRTRK command. During the write Track a counter is initialized to indicate (based on the Clock and density (and RPM)) the number of bytes to be transferred. When the number of bytes has been transferred the command terminates. It does NOT check index pulses. During the Write Track, each sector is written with the Data from the Data Field to the Sector indicated in the Address Field on the currently selected side and cylinder.. 

Type 1 commands all complete immediately, so they always return not busy.

The 16FDC seek complete register is slightly altered to trick the CDOS into thinking a seek starts and then ends. the software expects it. The first read of the extended status reg returns seek not complete and then the second read returns seek complete. The WD status register does NOT do this. it returns not busy, on the first read, after a type 1 command. (note - may affect interrupt service logic)

Since the WD17xx simulation routines use the Z80 Emulator's disk IO routines, the same error messages are reported for reads and writes. Since read track address issues a read, the errors are for reads. (Read track address actually reads sector 1 of the last track accessed for the selected drive.)

NOTE--if the software reads the WD status register and then chooses not to issue any more WD commands, no error is reported. Attempts to access a drive never occur if the drive is not ready, and therefore no error message is issued, by the z80 emulator. If the software chooses not to report an error, then you never find out about it.

If you need to see ALL disk access attempts, turn on Disk Debug Mode.

Sometimes errors are normal. The software may be testing a drive to see if it is clocked as *, 5, 3, HD, Double density, or dual sided. Therefore, since error messages from the z80 emulator can be irritating, as well as normal, you can turn them off. 
