;
;	File:		SWIMDefs.aii
;
;	Contains:	Equates for the IOP based SWIM driver.
;
;	Written by:	Gary G. Davidian
;
;	Copyright:	© 1987-1990 by Apple Computer, Inc., all rights reserved.
;
;	Change History (most recent first):
;
;		 <2>	  1/2/90	GGD		NEEDED FOR ZONE-5: Changes needed to support the Raw Track I/O
;									command.
;	   <1.4>	12/11/89	GGD		NEEDED FOR ZONE-5: Added record formats for new DiskDuplicator
;									support requests. Added record formats for new Get RAW Data
;									support requests.
;	   <1.3>	  7/8/89	CCH		Added EASE comments to file.
;	  <•1.2>	 6/15/89	GGD		Updated to use equates for the latest rev of the IOP chip,
;									re-formated tab stops in source.
;	   <1.1>	  2/5/89	GGD		Updated for latest version of SWIMDrvr.
;	   <1.0>	 11/9/88	CCH		Adding to EASE.
;
;	To Do:
;


SwimIOCtlReg	equ 	$3*IODelayCount+$2*IODurationCount

; SWIM Addresses

wData			equ 	IOBase+$40		; Write a data byte
wMark			equ 	IOBase+$41		; Write a mark byte
wCRC			equ 	IOBase+$42		; Write a 2-byte CRC (1 access does both)
wIWMConfig		equ 	wCRC			; Set IWM configuration (when StartAction=0)
wParams 		equ 	IOBase+$43		; Set the 16 parameter registers
wPhase			equ 	IOBase+$44		; Set phase lines states and directions
wSetup			equ 	IOBase+$45		; Set the current configuration
wZeroes 		equ 	IOBase+$46		; Mode reg: 1's clr bits, 0's=don't care
wOnes			equ 	IOBase+$47		; Mode reg: 1's set bits, 0's=don't care
rData			equ 	IOBase+$48		; Read a data byte
rCorrection 	equ 	rData			; Read the correction factor
rMark			equ 	IOBase+$49		; Read a mark byte
rError			equ 	IOBase+$4A		; Error register
rParams 		equ 	IOBase+$4B		; Parameters (16 bytes deep at this addr)
rPhase			equ 	IOBase+$4C		; Phase lines states and directions
rSetup			equ 	IOBase+$4D		; Read the current configuration
rStatus 		equ 	IOBase+$4E		; Status (returns current mode reg value)
rHandshake		equ 	IOBase+$4F		; Handshake register

; SWIM register bit masks

; wIWMConfig

IWMtimerOverride equ	%10000000		; Override IWM timer
IWMtimer2X		equ 	%01000000		; IWM timer takes twice as long to timeout
IWMlatchAsync	equ 	%00100000		; latch data bit 7 in async mode

; rError

UnderrunFIFO	equ 	%00000001		; Underrun FIFO
MarkInData		equ 	%00000010		; Mark In Data
OverrunFIFO 	equ 	%00000100		; Overrun FIFO
CorrectionError equ 	%00001000		; Correction Error
TransTooNarrow	equ 	%00010000		; Transition Too Narrow
TransTooWide	equ 	%00100000		; Transition Too Wide
TransUnresolved equ 	%01000000		; Unresolved Transition
;not used		equ 	%10000000		; not used

; rPhase / wPhase

ph0 			equ 	%00000001		; phase line 0 output data
ph1 			equ 	%00000010		; phase line 1 output data
ph2 			equ 	%00000100		; phase line 2 output data
ph3 			equ 	%00001000		; phase line 3 output data
ph0en			equ 	%00010000		; phase line 0 output enable
ph1en			equ 	%00100000		; phase line 1 output enable
ph2en			equ 	%01000000		; phase line 2 output enable
ph3en			equ 	%10000000		; phase line 3 output enable
ca0 			equ 	ph0
ca1 			equ 	ph1
ca2 			equ 	ph2
lstrb			equ 	ph3
ph0123en		equ 	ph0en+ph1en+ph2en+ph3en

enPh0L			equ 	%00010000
enPh0H			equ 	%00010001
enPh1L			equ 	%00100000
enPh1H			equ 	%00100010
enPh2L			equ 	%01000000
enPh2H			equ 	%01000100
enPh3L			equ 	%10000000
enPh3H			equ 	%10001000

; rSetup / wSetup

HeadSelEnable	equ 	%00000001		; enable Q3/Head Select to be an output
Select35		equ 	%00000010		; 3.5 selected
GCRMode 		equ 	%00000100		; select GCR mode
ClockDiv2		equ 	%00001000		; internal clock frequency / 2
EnableECM		equ 	%00010000		; enables the Error Correction Machine
IBMDrive		equ 	%00100000		; IBM type drive
TransSpaceDis	equ 	%01000000		; Trans-Space logic disabled
MotorTimeOut	equ 	%10000000		; enable 1/2 second motor timeout

; rHandshake

MarkInFIFO		equ 	%00000001		; next byte read from FIFO is a Mark
CRCNotZero		equ 	%00000010		; CRC register is not Zero
DriveRdData 	equ 	%00000100		; state of the RdData signal from the drive
DriveSense		equ 	%00001000		; state of the Sense signal from the drive
DriveEnabled	equ 	%00010000		; a drive is explicitly enabled, or timing out
rErrorValid 	equ 	%00100000		; error register is non-zero
Dat2Bytes		equ 	%01000000		; 2 bytes valid / available in the FIFO
Dat1Byte		equ 	%10000000		; 1 byte valid / available in the FIFO

; wZeros / wOnes / rStatus

ClearFIFO		equ 	%00000001		; Clear the FIFO
Drive1Enabled	equ 	%00000010		; select Drive 1
Drive2Enabled	equ 	%00000100		; select Drive 2
StartAction 	equ 	%00001000		; start Read / Write operation
WriteMode		equ 	%00010000		; set the chip into Write mode
HeadSelect		equ 	%00100000		; select head (side) 0 or 1
;reserved		equ 	%01000000		; reserved, reads back as a one
MotorOn 		equ 	%10000000		; Causes selected drive to be enabled

; disk drive pulse addresses / data

wDirNextAdr 	equ 	0*HeadSelect+0*ca2+0*ca1+0*ca0
wDirPrevAdr 	equ 	0*HeadSelect+1*ca2+0*ca1+0*ca0
wStepOnAdr		equ 	0*HeadSelect+0*ca2+0*ca1+1*ca0
wStepOffAdr 	equ 	0*HeadSelect+1*ca2+0*ca1+1*ca0
wMotorOnAdr 	equ 	0*HeadSelect+0*ca2+1*ca1+0*ca0
wMotorOffAdr	equ 	0*HeadSelect+1*ca2+1*ca1+0*ca0
wEjectOffAdr	equ 	0*HeadSelect+0*ca2+1*ca1+1*ca0
wEjectOnAdr 	equ 	0*HeadSelect+1*ca2+1*ca1+1*ca0
;				equ 	1*HeadSelect+0*ca2+0*ca1+0*ca0	; undefined
;				equ 	1*HeadSelect+1*ca2+0*ca1+0*ca0	; undefined
wDiskInPlAdr	equ 	1*HeadSelect+0*ca2+0*ca1+0*ca0	; don't know for sure if you can
wNoDiskInPlAdr	equ 	1*HeadSelect+1*ca2+0*ca1+0*ca0	; really write to these addresses
wMFMModeOnAdr	equ 	1*HeadSelect+0*ca2+0*ca1+1*ca0
wGCRModeOffAdr	equ 	wMFMModeOnAdr
wMFMModeOffAdr	equ 	1*HeadSelect+1*ca2+0*ca1+1*ca0
wGCRModeOnAdr	equ 	wMFMModeOffAdr
;				equ 	1*HeadSelect+0*ca2+1*ca1+0*ca0	; undefined
;				equ 	1*HeadSelect+1*ca2+1*ca1+0*ca0	; undefined
;				equ 	1*HeadSelect+0*ca2+1*ca1+1*ca0	; undefined
;				equ 	1*HeadSelect+1*ca2+1*ca1+1*ca0	; undefined

; disk drive sense addresses

rDirPrevAdr 	equ 	0*HeadSelect+0*ca2+0*ca1+0*ca0
rStepOffAdr 	equ 	0*HeadSelect+0*ca2+0*ca1+1*ca0
rMotorOffAdr	equ 	0*HeadSelect+0*ca2+1*ca1+0*ca0
rEjectOnAdr 	equ 	0*HeadSelect+0*ca2+1*ca1+1*ca0
rRdData0Adr 	equ 	0*HeadSelect+1*ca2+0*ca1+0*ca0
rMFMDriveAdr	equ 	0*HeadSelect+1*ca2+0*ca1+1*ca0
rDoubleSidedAdr equ 	0*HeadSelect+1*ca2+1*ca1+0*ca0
rNoDriveAdr 	equ 	0*HeadSelect+1*ca2+1*ca1+1*ca0
rNoDiskInPlAdr	equ 	1*HeadSelect+0*ca2+0*ca1+0*ca0
rNoWrProtectAdr equ 	1*HeadSelect+0*ca2+0*ca1+1*ca0
rNotTrack0Adr	equ 	1*HeadSelect+0*ca2+1*ca1+0*ca0
rNoTachPulseAdr equ 	1*HeadSelect+0*ca2+1*ca1+1*ca0
rIndexPulseAdr	equ		rNoTachPulseAdr
rRdData1Adr 	equ 	1*HeadSelect+1*ca2+0*ca1+0*ca0
rMFMModeOnAdr	equ 	1*HeadSelect+1*ca2+0*ca1+1*ca0
rGCRModeOffAdr	equ 	rMFMModeOnAdr
rNotReadyAdr	equ 	1*HeadSelect+1*ca2+1*ca1+0*ca0
rNotRevisedAdr	equ 	1*HeadSelect+1*ca2+1*ca1+1*ca0
r1MegMediaAdr	equ 	rNotRevisedAdr


; IWM Addresses

ph0L			equ 	IOBase+$40		; phase 0 low
ph0H			equ 	IOBase+$41		; phase 0 high
ph1L			equ 	IOBase+$42		; phase 1 low
ph1H			equ 	IOBase+$43		; phase 1 high
ph2L			equ 	IOBase+$44		; phase 2 low
ph2H			equ 	IOBase+$45		; phase 2 high
ph3L			equ 	IOBase+$46		; phase 3 low
ph3H			equ 	IOBase+$47		; phase 3 high
mtrOff			equ 	IOBase+$48		; motor off
mtrOn			equ 	IOBase+$49		; motor on
intDrive		equ 	IOBase+$4A		; enable internal drive
extDrive		equ 	IOBase+$4B		; enable external drive
q6L 			equ 	IOBase+$4C		; q 6 low
q6H 			equ 	IOBase+$4D		; q 6 high
q7L 			equ 	IOBase+$4E		; q 7 low
q7H 			equ 	IOBase+$4F		; q 7 high

ca0L			equ 	ph0L
ca0H			equ 	ph0H
ca1L			equ 	ph1L
ca1H			equ 	ph1H
ca2L			equ 	ph2L
ca2H			equ 	ph2H
lstrbL			equ 	ph3L
lstrbH			equ 	ph3H

IWMmode 		equ 	$17 			; mode register value


; SWIM			IWM Addresses mapping

; wData 		ph0L
; wMark 		ph0H
; wCRC			ph1L
; wParams		ph1H
; wPhase		ph2L
; wSetup		ph2H
; wZeroes		ph3L
; wOnes 		ph3H
; rData 		mtrOff
; rCorrection	mtrOff
; rMark 		mtrOn
; rError		intDrive
; rParams		extDrive
; rPhase		q6L
; rSetup		q6H
; rStatus		q7L
; rHandshake	q7H


; Message Assignments

RCVState		equ 	RCVMsg2State
RCVData 		equ 	RCVMsg2Data
XMTState		equ 	XMTMsg2State
XMTData 		equ 	XMTMsg2Data


; SWIM Driver  IOP -> HOST Request encodings

DiskInsertedXmtReq		equ 	$01 	; Disk Inserted event
DiskEjectedXmtReq		equ 	$02 	; Disk Ejected event
DiskStatusChangedXmtReq equ 	$03 	; Disk Status Changed

XmtKind 				equ 	XMTData+$00 	; (byte)		Request Kind
XmtDriveNumber			equ 	XMTData+$01 	; (byte)		Drive Number
XmtErrorCode			equ 	XMTData+$02 	; (word)		Error Code
XmtDriveStatus			equ 	XMTData+$04 	; (?? bytes)	Drive Status Information


; SWIM Driver  HOST -> IOP Request encodings

InitializeReq			equ 	$01 	; Initialize Driver
ShutDownReq 			equ 	$02 	; Shut down driver
StartPollingReq 		equ 	$03 	; Start Polling Drives
StopPollingReq			equ 	$04 	; Stop Polling Drives
SetHFSTagAddrReq		equ 	$05 	; Set HFS tag host address
DriveStatusReq			equ 	$06 	; Drive Status
EjectReq				equ 	$07 	; Eject
FormatReq				equ 	$08 	; Format disk
FormatVerifyReq 		equ 	$09 	; Verify disk formatting
WriteReq				equ 	$0A 	; Write blocks to disk
ReadReq 				equ 	$0B 	; Read blocks from disk
ReadVerifyReq			equ 	$0C 	; Read and compare blocks from disk
CacheControlReq 		equ 	$0D 	; track cache control
TagBufferControlReq 	equ 	$0E 	; tag buffer control
GetIconReq				equ 	$0F 	; get media or drive Icon
DiskDupInfoReq			equ 	$10 	; get Disk Duplicator information
GetRawDataReq			equ		$11		; Read RAW disk data (for copy protection)

ReqKind 				equ 	RCVData+$00 	; (byte)		Request Kind
ReqDriveNumber			equ 	RCVData+$01 	; (byte)		Drive Number
ReqControlKind			equ 	RCVData+$01 	; (byte)		DriverControl sub-command
ReqErrorCode			equ 	RCVData+$02 	; (word)		Error Code
ReqFormatKind			equ 	RCVData+$04 	; (word)		Format Kind
ReqAdditionalParams 	equ 	RCVData+$04 	; (long)		control / status csParam
ReqDriveStatus			equ 	RCVData+$04 	; (?? bytes)	Drive Status Information
ReqDriveKinds			equ 	RCVData+$04 	; (28 bytes)	Drive kinds (returned by init)
ReqRAMAddress			equ 	RCVData+$04 	; (long)		Main CPU RAM Address
ReqDupVersion			equ 	RCVData+$04 	; (word)		Disk Duplicator Version
ReqHdrFmtKind			equ 	RCVData+$06 	; (byte)		Format byte from the last sector hdr (0=use default)
ReqFmtInterleave		equ 	RCVData+$07 	; (byte)		Format Interleave (0=use default)
ReqBlockNumber			equ 	RCVData+$08 	; (long)		Disk Starting Block Number
ReqFmtDataAddress		equ		RCVData+$08 	; (long)		CPU RAM Address of format sector data
ReqBlockCount			equ 	RCVData+$0C 	; (long)		Transfer Block Count
ReqFmtTagAddress		equ		RCVData+$0C 	; (long)		CPU RAM Address of format tag data
ReqMfsTagData			equ 	RCVData+$10 	; (12 bytes)	MFS Disk Tag Information
ReqRawClockAddress		equ 	RCVData+$04 	; (long)		Buffer for packed MFM clock bits
ReqRawDataAddress		equ 	RCVData+$08 	; (long)		Buffer for RAW data bytes
ReqRawByteCount			equ		RCVData+$0C		; (long)		Number of RAW bytes to read
ReqRawSearchMode		equ		RCVData+$10		; (word)		RAW Read search mode
ReqRawCylinder			equ		RCVData+$12		; (word)		RAW Read cylinder number
ReqRawHead				equ		RCVData+$14		; (byte)		RAW Read head number
ReqRawSector			equ		RCVData+$15		; (byte)		RAW Read sector number


; Search modes for RAW read requests

SearchImmediate			equ		0				; don't search, read immediatly
SearchForAddress		equ		1				; find address field, read raw after address
SearchForData			equ		2				; find data field,  read raw after data
SearchForIndex			equ		3				; find index, read raw after index


; Status Message field offsets

StatTrackH		equ 	$04 	; High byte of Current Track Location
StatTrackL		equ 	$05 	; Low  byte of Current Track Location
StatWrProtected equ 	$06 	; bit7=1=write protected
StatDiskInPlace equ 	$07 	; 0 = no disk place, 1 or 2 = disk in place
StatInstalled	equ 	$08 	; 0 = don't know, 1=installed, $FF=not installed
StatSides		equ 	$09 	; bit7=0=single sided, bit7=1=double sided
; drive queue element is not returned from IOP
StatTwoSidedFmt equ 	$0A 	; $FF=2-sided disk, $00=1-sided disk
StatNewIntface	equ 	$0B 	; $00=old drive interface (400K), $FF=new (800K and later)
StatDiskErrorsH equ 	$0C 	; High byte of disk error count
StatDiskErrorsL equ 	$0D 	; Low  byte of disk error count

StatDriveInfoB3 equ 	$0E 	; start of data for drive info control call
StatDriveInfoB2 equ 	$0F 	; high 2 bytes unused for now
StatDriveAttr	equ 	$10 	; disk drive attributes
StatDriveType	equ 	$11 	; type of disk drive

;								; start of data for extended drive status control call
StatMfmDrive	equ 	$12 	; $FF=SuperDrive, otherwise zero
StatMfmDisk 	equ 	$13 	; $FF=MFM disk in drive, otherwise zero
StatMfmFormat	equ 	$14 	; $FF=1440K, $00=720K
StatDiskCtlr	equ 	$15 	; $FF=SWIM, $00=IWM

StatCurrentFmtH equ 	$16 	; High byte of bit mask of current format
StatCurrentFmtL equ 	$17 	; Low  byte of bit mask of current format
StatFmtAllowedH equ 	$18 	; High byte bit mask of allowable formats
StatFmtAllowedL equ 	$19 	; Low  byte bit mask of allowable formats

StatDiskSizeB3	equ 	$1A 	; Byte 3 of size of current drive, if fixed media drive. (HD-20)
StatDiskSizeB2	equ 	$1B 	; Byte 2 of size of current drive, if fixed media drive. (HD-20)
StatDiskSizeB1	equ 	$1C 	; Byte 1 of size of current drive, if fixed media drive. (HD-20)
StatDiskSizeB0	equ 	$1D 	; Byte 0 of size of current drive, if fixed media drive. (HD-20)

StatIconFlags	equ 	$1E 	; bit 0 - call for Media Icon, bit 1 - call for Drive Icon

StatSpare		equ 	$1F 	; (1 spare byte left)


; Drive number assignments

intDriveNumber	equ 	1				; drive number 1 is internal drive
extDriveNumber	equ 	2				; drive number 2 is external drive
FirstHD20DriveNumber	equ 	5		; first HD20 is drive 5
maxHD20Cnt		equ 	4				; 4 HD20's allowed

NumberOfDrives	equ 	FirstHD20DriveNumber+maxHD20Cnt
MaxDriveNumber	equ 	NumberOfDrives-1

;		Disk Drive Kinds

noDriveKind 			equ 	0		; no drive connected
unknownDriveKind		equ 	1		; unspecified drive kind
SSGCRDriveKind			equ 	2		; single sided 400K GCR disk drive
DSGCRDriveKind			equ 	3		; double sided 400K/800K GCR disk drive
DSMFMGCRDriveKind		equ 	4		; double sided 400K/800K GCR, 720K, 1440K MFM disk drive
HD20DriveKind			equ 	7		; HD20 20MB hard disk

;		Disk Media Kinds

NoMediaKind 	equ 	0				; no disk media in drive
unknownMediaKind equ	1				; unknown disk media
HD20MediaKind	equ 	2				; HD20 20MB hard disk media
LoDenMediaKind	equ 	3				; 400K, 800K, 720K Media (Low density)
HiDenMediaKind	equ 	4				; 1440K Media (High density)

;		Disk Format Kinds

uncheckedFormat equ 	0				; disk format has not been checked
unknownFormat	equ 	1				; disk format could not be determined
HD20Format		equ 	2				; HD20 20MB hard disk
GCR400Kformat	equ 	3				; single sided	400K GCR disk
GCR800Kformat	equ 	4				; double sided	800K GCR disk
MFM720Kformat	equ 	5				; double sided	720K MFM disk
MFM1440Kformat	equ 	6				; double sided 1440K MFM disk HD media
GCRonHDformat	equ 	7				; 400K or 800K GCR format on HD media (user error)


; Error codes

noErr			equ 	0				; no Error (success)
openErr 		equ 	-23 			; Initialize when already initialized
wPrErr			equ 	-44 			; diskette is write protected
paramErr		equ 	-50 			; Error in parameter list
nsDrvErr		equ 	-56 			; no such drive (tried to mount a bad drive num)
noDriveErr		equ 	-64 			; drive not installed
offLinErr		equ 	-65 			; r/w requested for an off-line drive
noNybErr		equ 	-66 			; couldn't find 5 nybbles in 200 tries
noAdrMkErr		equ 	-67 			; couldn't find valid addr mark
dataVerErr		equ 	-68 			; read verify compare failed
badCksmErr		equ 	-69 			; addr mark checksum didn't check
badBtSlpErr 	equ 	-70 			; bad addr mark bit slip nibbles
noDtaMkErr		equ 	-71 			; couldn't find a data mark header
badDCksum		equ 	-72 			; bad data mark checksum
badDBtSlp		equ 	-73 			; bad data mark bit slip nibbles
wrUnderrun		equ 	-74 			; write underrun occurred
cantStepErr 	equ 	-75 			; step handshake failed
tk0BadErr		equ 	-76 			; track 0 detect doesn't change
initIWMErr		equ 	-77 			; Can't initialize disk controller chip
spdAdjErr		equ 	-79 			; unable to correctly adjust disk speed
seekErr 		equ 	-80 			; track number wrong on address mark
sectNFErr		equ 	-81 			; sector number never found on a track
fmt1Err 		equ 	-82 			; can't find sector 0 after track format
fmt2Err 		equ 	-83 			; can't get enough sync
noIndexErr		equ 	fmt2Err 		; index pulse not found during MFM format
verErr			equ 	-84 			; track failed to verify
gcrOnMFMErr 	equ 	-400			; gcr format on high density media error

