{-----------  Dandelion Processor Program - I/O Processor  -----------

  DESCRIPTION:      Floppy Disk Task Definitions.

  Jim JXF     :   1-Sep-84 17:24:11: Add copyright notice
  Jim JXF     :  July 27, 1982  10:28 AM: New IO Page Format
  Jim JXF     :  May 21, 1982  7:12 AM: Change DmaFunc -- no mask needed
  Roy RXO :  February 24, 1981  12:24 PM
  Dan dD    :  January 26, 1981  1:15 PM

  File: FloppyDefs.asm
  Stored:  [Iris]<WMicro>DLion>FloppyDefs.asm
  Written by Roy RXO .

  Modification History:
	- Created (January 2, 1981  12:02 PM)
	- added Format parameters (January 8, 1981  1:56 PM)
	- transferred Explanation from FloppyTask (January 9, 1981  3:29 PM)
	- Tried to run at full speed by allowing the chip to read and write
	  runs of sectors. (January 12, 1981  10:49 AM)
	- 8085 Interrupt mask definitions deleted (February 24, 1981  12:23 PM)
}

{ 	Copyright (C) 1981, 1982 by Xerox Corporation.  All rights reserved.}


{  The Floppy Task interfaces with the Floppy Head in the CP, and the floppy
disk controller hardware.  The task is activated when the CSBWatcher notices that
there is a non-zero IOCB pointer in the Floppy CSB (word 1).  The task then inspects
the value of the command in the IOCB, and executes the appropriate command.  After
the command is executed, the floppy task writes the Result word in the IOCB, updates
the Sector Count, does a Naked Notify, and then clears the IOCB pointer in the CSB.

Due to interleaving, the current value of IOCB.SectorCnt will not be correct after an
error completon of a sector command.  This is because the sectors completed correctly
will not be adjacent.  Thus, after a sector command completion error, the number of
sectors still to be done is corrected to reflect the minimum number of ADJACENT 
sectors correctly done, and IOCB.SectorCnt is adjusted accordingly. The minimum number,
i.e. one sector for each interleave cycle in which at least one sector has completed
correctly, is used, since the calculation of the adjacent sectors completed corectly in
the last interleave cycle is complex, and was not deemed necessary for the code it
would require.  

***** On January 23, 1981 interrupts were added and interleaving deleted.  This allows the floppy to transfer data at full speed.

Floppy Disk CSB format - Addresses (in main memory)  14049 - 14050 (Hex):

	word 0:		Interrupt mask
	word 1:		Reset (-1 command inserted, IOP clears on completion)

Floppy Disk IOCB format - Addresses (in main memory)  in n 64K bank:

Buffer description:
	word 0,1:	Long buffer pointer
	word 2:		Buffer size (in words)
Context:
	word 3:		Sector Length (in words)
	word 4:		bit 11: Troy/IBM' format, bit 12: Double/Single' density, other bits don't care 
Disk Address:
	word 5:		Cylinder [0..76]
	word 6:		bits 0:7 - Head [0..1], bits 8:15 - sector number 
	word 7:		Sector count
Operation result:
	word 8:		Result of operation
Command:
	word 9:		bit 0 - Single Buffer bit, bits 7:15 - Command
		Note: Runs of sectors can be specified for Read Sector, Write Sector, 
		Write Deleted Sector, and Read ID.
	word 10:	Escape command (unused if Command#8)
		1 = Clear DiskChange
The following two words are used only by the Format Track command.
	word 11:	Bits 0:7 - Encoded Sector length (00=>128 bytes,
				   01=>256 bytes, 10=>512 bytes, 11=>1024
				   bytes),
			Bits 8:15- Sector Length/4
	word 12:	Bits 0:7 - number of fill chars in Gap Three
			Bits 8:15- number of tracks to format
	words 13:15	(reserved)

The following are the possible command values:
	0  -  NOP:  Do a ForceInterrupt command and resturn the status
	1  -  Read Sector:  Read a run of sectors on the disk.  The run should not
		cross a track boundary.
	2  -  Write Sector:  Write a run of sectors on the disk.  The run should not
		cross a track boundary.
	3  -  Write Deleted Sector:  Write a run of deleted sectors on the disk.  The run
		should not cross a track boundary.
	4  -  Read ID:  Read a run of ID records on the disk.
	5  -  Format Track:  Format the specified track.
	6  -  Recalibrate:  Restore the disk.
	7  -  Initialize:  Initialize the disk controller.
	8  -  Escape:  Interpret the following word in the IOCB as a low-level command.
		1:  Clear Disk Change

Note: Runs of sectors can be specified for Read Sector, Write Sector,
Write Deleted Sector, and Read ID.  Runs of operations are handled by
double buffering disk operations.  A run of tracks (all on same side)
may be specified for the Format Track command.  In that the command the
SectorCnt is the number of sectors per track.

IOCB Result Format:

This is the format of the Result word written in the IOCB by the IOP.
The Mesa Head will use this Result word to form the returned status value.

Bit 0:	diskChange 
Bit 1:	0
Bit 2:	twoSided 
Bit 3:	DiskID (0 = SA800, 1=SA850) 
Bit 4:	error (an error completion occurred) 
Bit 5:	0
Bit 6:	recalibrateError
Bit 7:	dataLost (only on Read and Write commands) 

Bit 8:	notReady
Bit 9:	writeProtect (only on Seek, and Write commands, 0 otherwise) 
Bit 10:	deletedData (only on Read Sector command, undefined otherwise) 
Bit 11:	recordNotFound (on Read ID, Read Sector, Write Sector)
Bit 12:	crcError 
Bit 13:	track00 
Bit 14:	undefined 
Bit 15:	busy (should never be 1) 



Notes:
  -  Interleave factor has been hardwaired into the code as 2.  Change by changing 
      in allocation of IntFactor.

Assumptions:
  -  Sector count in IOCB is [1..255].  A zero value wil be interpretted as 256.
      Sector run should not cross a Track boundary (except Read ID).
}


;  Floppy Task definitions:

;  CP address info.
CPIOCBHi	equ	0	;  64K bank of IOCB addresses

; CSB indexes:
CsbWUMask	equ	0	;  Interrupt mask in CSB (local)

; IOCB indexes:
;  Local memory: byte index,  main memory:  word index.
IocbBufPtr	equ	0	;  IOCB Buffer Pointer (low word) (local memory)
IocbBufPtrHi	equ	2	;  IOCB Buffer Pointer (high word) (local memory)
IocbBufSize	equ	4	;  IOCB Buffer Size (local memory)
IocbSectorLen	equ	6	;  IOCB Sector length (local memory)
IocbMiscContext	equ	8	;  IOCB miscellaneous context (local memory)
IocbCylinder	equ	10	;  IOCB Cylinder (local memory)
IocbSector	equ	12	;  IOCB Sector (local memory)
IocbHead	equ	13	;  IOCB Head number (local memory)
IocbSectorCnt	equ	14	;  IOCB Sector count (local memory)
IocbResult	equ	16	;  IOCB Result (local memory)
IocbResultHi	equ	17	;  IOCB Result (high) (local memory)
IocbCommand	equ	18	;  IOCB Command (local memory)
IocbCommandHi	equ	19	;  IOCB IocbCommand (high) (local memory)
IocbEscCommand	equ	20	;  IOCB Escape Command (local memory)
;  The following parameters are used only by the Format Track command
IocbEncSectorLen	equ	22	;  IOCB encoded sector length
IocbQuarterSectorLen	equ	23	;  IOCB (SectorLength)/4
IocbGap3Len	equ	24	;  IOCB length of Gap 3 on disk
IocbSectorsPerTrack	equ	25	;  IOCB number of tracks to format

CPIocbSectorCnt	equ	7	;  IOCB Sector count (main memory)

MiscContextMask	equ	18H	;  IOCB miscellaneous context mask
nMiscContextMask	equ	0FFH-MiscContextMask	;  Compl. of misc. context mask
ErrorMask	equ	8H	;  Error bit in IOCB ResultHi
LostDataMask	equ	1H	;  LostData bit in IOCB ResultHi
HeadMask	equ	1H	;  Head mask in IOCB.Head

ClrDiskChgCmd	equ	1	;  Escape command: Clear Disk Change


;  1797 Floppy Controller definitions:

;  Commands:
ForceInt0Cmd	equ	0D0H	;  Force Interrupt, I = 0000 (no interrupt)
ForceInt1Cmd	equ	0D1H	;  Force Interrupt, I = 0001 (immediate interrupt)
ResCmd		equ	8H	; Restore command (h=1, V=0, r1r0=0)
StepInCmdNoV	equ	5AH	; StepIn command (h=1, V=0, r1r0=2) (slow enough for SA800)
SkCmd		equ	1CH	; Seek command (h=1, V=1, r1r0=0)
SkCmdR1		equ	1DH	; Seek command (h=1, V=1, r1r0=1)
SkCmdNoV	equ	1AH	; Seek command (h=1, V=0, r1r0=2) (slow enough for SA800)
RSectorCmd	equ	080H	; Read Sector command (E=0) (1793)
WSectorCmd	equ	0A0H	; Write Sector command (E=0) (1793)
RAddrCmd	equ	0C0H	; Read Address command
RAddrDataLen	equ	3H	; Read Address data length (words)

DeletedDataMask	equ	1H	;  Deleted data bit in WriteSector command
nDeletedDataMask	equ	0FFH-DeletedDataMask	;  Complement of mask
Type2SMask	equ	2H	;  S bit flag mask in Read/Write Sector Cmd (1797)
nType2SMask	equ	0FFH-Type2SMask	;  Complement of S bit flag mask

;  Status bits.
;  All types
FDCNotReady	equ	80H		;  Not ready
FDCCRCError	equ	8H		;  CRC error
FDCWrProt	equ	40H		;  WriteProtect
FDCBusyMask	equ	1H		; Busy Status bit
; Type I:
FDCSeekError	equ	10H		;  Seek error
FDCHeadLoad	equ	20H		;  HLD and HLT
FDCTk0Mask	equ	4H		; Track 00 bit mask in status
; Type II and III:
FDCRNFMask	equ	10H		;  Record Not Found
FDCLostData	equ	4H		;  Lost Data
FDCDRQMask	equ	2H		; Data Request Status bit

; Error Masks for Type I commands
Type1ErrorMask	equ	FDCNotReady+FDCSeekError+FDCCRCError+FDCBusyMask
Type1HardMask	equ	FDCNotReady+FDCBusyMask
; Error Mask for Type II read commands
ReadErrorMask	equ	FDCNotReady+FDCRNFMask+FDCCRCError+FDCLostData+FDCBusyMask
ReadHardMask	equ	FDCNotReady+FDCBusyMask
; Error Mask for Type II write commands
WriteErrorMask	equ	FDCNotReady+FDCWrProt+FDCRNFMask+FDCCRCError+FDCLostData+FDCBusyMask
WriteHardMask	equ	FDCNotReady+FDCWrProt+FDCBusyMask

;  Constants for FDCState:
;DisableFDC	equ	80H	; Enable Waits, Disable controller, Disable Drive, defined
								; in "SysDefs"
DefFDCStateVal	equ	85H	; Enable Waits, Enable controller, Enable Drive	
					;  Side=0, DDen = 0
DDenMask	equ	8H	;  Double density bit in FDCState
Side1Mask	equ	20H	;  Side 1 mask in FDCState
nSide1Mask	equ	0FFH-Side1Mask	;  Complement of Side 1 mask in FDCState
DriveSelectMask	equ	1H	;  Drive Select mask in FDCState
nDriveSelectMask	equ	0FFH-DriveSelectMask	;  Complement of Drive Select mask
PreCompStart	equ	43	;  First track to have PreComp in double density
FDCEnPreCompMask	equ	40H	;  Enable PreComp mask in FDCState
nFDCEnPreCompMask	equ	0FFH-FDCEnPreCompMask	;  Complement of Enable PreComp mask

;  FDC Status register (external) definitions.
FDCIntMask	equ	80H	; FDC Int Req in IntReq register
DiskChangeMask	equ	80H	; DiskChange mask in status register (external)
FDCEndCountMask	equ	40H	; FDC end count in status register (external)

;  Masks for Result word.
;  1's in mask indicate where nothing is tobe OR'd into Result.
Type1ZeroMaskLo	equ	20H
nType1ZeroMaskLo	equ	0FFH-Type1ZeroMaskLo
Type1ZeroMaskHi	equ	4FH
nType1ZeroMaskHi	equ	0FFH-Type1ZeroMaskHi
Type2ZeroMaskLo	equ	06H
nType2ZeroMaskLo	equ	0FFH-Type2ZeroMaskLo
Type2ZeroMaskHi	equ	4FH
nType2ZeroMaskHi	equ	0FFH-Type2ZeroMaskHi
RecalibrateErrorMask	equ	2H		;  Recalibrate Error in DiskStatusHi

;  Dma defs.
FloppyChannelMask	equ	1H	;  Floppy is channel 0
OutDmaFunc	equ	DmaFuncRead	;  Read memory
InDmaFunc	equ	DmaFuncWrite	;  Write memory


	END	FloppyDefs