jmp start

; Direct Drive programming
; Author : J. Van Houtven
; Fruithoflaan 105 bus 42,
; B-2600 Berchem (Belgium)

; *** Constants

EXECBASE=	4

; *** Hardware regs

CIAAPRA=	$bfe001

; *** Exec.library function offsets

Disable=	-120
Enable=		-126

start:

move.l	EXECBASE,a6
jsr	Disable(a6)


move.l	Drive,d0
bsr	MotorOn

btst	#3,$bfe001	; Write Protect bit3=0 => Write Protected
beq	WriteProtected

move.l	#$fffffff,d1
GreenLoop:
move.w	#$00f0,$dff180
dbf	d1,GreenLoop
bra	WaitLMB

WriteProtected:
move.l	#$fffffff,d1
RedLoop:
move.w	#$0f00,$dff180
dbf	d1,RedLoop

WaitLMB:
btst	#6,CIAAPRA
bne	WaitLMB

move.l	Drive,d0
bsr	DeSelect 	

move.l	EXECBASE,a6
jsr	Enable(a6)

rts

Select:
;
; D0: Drive number
;
move.l	d0,-(a7)
add.l	#3,d0
or.b	#%01111000,$bfd100
bclr	d0,$bfd100

move.l	#$b000,d0
SelectL1:
dbf	d0,SelectL1

move.l	(a7)+,d0
rts

DeSelect:
;
; D0: Drive number
;
move.l	d0,-(a7)
add.l	#3,d0
bset	d0,$bfd100
move.l	(a7)+,d0
rts

MotorOn:
;
; D0: Drive number
;
bsr	DeSelect
bclr	#7,$bfd100
bsr	Select
rts

; *** Variables
;

Drive:	dc.l	1

