SEEK

.Page
;++
;		Seek
;--
;
; REGISTERS
;  OUT
;	All =	Destroyed
;
; CALLS
;
;++
.Page


Seek	.Equ *
	Jsr	Init			; Global setup routine & return w/ 'a' = 0
	Jsr	CmdClnUp			; Clear GoByte and ErrStat

SeekAlt	.Equ *				; Alternate entry w/o 'init' of variables
	Ldx	#00
	Stx	TrkFlg			; Assume no head movement & motor already on
	Stx	MtrFlg
	Stx	Direct			; Assume '0' (toward spindle) direction
	Dex
	Stx	HostSeek			; Tell 68K that I am seeking

	Lda	MtrOn			; if = 'FF' then motor is already on
	Bne	$20
	Dec	MtrFlg			; tell me to wait full 400 msec
	Jsr	TrnMtrOn			; turn the motor on

$20	Lda	IIob+Track
	Cmp	CurTrack
	Bne	Seek1			; Wrong track
	Lda	MtrFlg
	Beq	SeekEnd			; same track and motor already on so select side
	Bne	JstMtr			; Just wait for motor to settle

Seek1	.Equ *				; 'A' has IIob+Track already
	Dec	TrkFlg			; Indicate that needs head positioning
	Sec
	Sbc	CurTrack			; Abs(destination-current) = amt to move
	Bcs	pstv			; If ccC = 1 then positive result
	Eor	#0FF
	Adc	#1			; Take two's complement
	Inc	Direct			; Set outward direction (away from spindle)

pstv	.Equ *
	Sta	StpAmt
	Lda	HeaDelay			; Assume only wait forf head settling
	Sta	Delay

Seek2	.Equ *
	Jsr	TrkClss			; Return w/ 'Y' = class of IIob+Track
	Cpy	CurClass
	Beq	$60
	Jsr	SetSpdy			; Set the speed w/ 'Y' = trk class index
	Lda	StpAmt
	Jsr	ClcScDly			; Calc speed change delay time, return in 'A'
	Sta	Delay
$60	Jsr	DoSeek			; Finally do the actual seek

JstMtr	Lda	MOnDly
	Ldx	MtrFlg
	Bne	$80
	Lda	Delay
$80	Jsr	Wait			; Wait for motor, speed change, & head settling
	Lda	IIob+Track
	Sta	CurTrack
	Jsr	SpdChk			; Check the speed & adjust if neccessary
SeekEnd	.Equ *
	Jsr	TrnMtrOn			; For flakey PAL problems
	Ldx	#0
	Stx	HostSeek			; No more seeking
	Jmp	SelSide			; Select proper side

;++
;
;		ProgErr
;
; This code will do many things.  It will either deselect the drive, turn off
; the motors, park the heads first, clear the GoByte, and ErrStat, and maybe
; jump to itself forever.
;
;
; REGISTERS
;  IN
;	A =	Any value
;	X =	Any value
;	Y =	Any value
;  OUT
;	ALL =	Destroyed
;
;--

ESAD	.Equ *				; Used by drop dead command
	Jsr	PrkClr0			; Turn off motor and clear the GoByte
ProgErr1	Jmp	ProgErr1			; Loop forever!
PrkClr0	.Equ *				; Park the heads and clear the GoByte
	Jsr	MtrOff
	Lda	#00
	Jmp	CmdClnUp