; A2091ToFast
; Written in 1998 by C.Weber (chris1@hallertau.net)
; Don't take the code as a good example of good coding.
; See it as was it is: the result of a long night.

DRIVERSIZE equ $3240
BASEADDRESS equ $e92000

 move.l 4,a6

 move.l #NO_MEM_TXT,d6
 move.l #$10001,d1
 move.l #DRIVERSIZE,d0
 jsr    -198(a6)
 tst.l  d0
 beq    Error_NoMemory
 move.l d0,a4

 move.l #BASEADDRESS,a0
 move.l a4,a1
 move.l #(DRIVERSIZE+3)/4-1,d0
copyloop:
 move.l (a0)+,(a1)+
 dbf    d0,copyloop

 move.l #SCSI_HANDLER_NOT_FOUND_TXT,d6
 move.l #ScsiTaskName,a1
 jsr    -294(a6) ;FindTask
 move.l d0,a2
 tst.l  d0
 beq    SCSI_HANDLER_NOT_FOUND
 
 jsr    -120(a6) ;Disable

 move.l #DEVICE_BUSY_TXT,d6
 move.l 54(a2),a3 ;tc_spreg
 move.l 62(a2),d7 ;tc_spupper
 sub.l  a3,d7 ;d7=spupper-spreg
 cmp.l  #98,d7
 bne    Error_Device_Busy
 
 move.l #STACK_ERROR1_TXT,d6
 cmp.w  #$00e9,$4a(a3)
 bne    Error_Device_Not_Found
 move.l $4a(a3),d0
 sub.l  #BASEADDRESS,d0
 add.l  a4,d0
 move.l d0,$4a(a3)

Error_Device_Not_Found:
Error_Device_Busy:
 jsr    -126(a6) ;Enable

 move.l #IOREQ_HANDLER_NOT_FOUND_TXT,d6
 move.l #ScsiIoReqTask,a1
 jsr    -294(a6) ;FindTask
 move.l d0,a2
 tst.l  d0
 beq.s  SCSI_HANDLER_NOT_FOUND
 
 jsr    -120(a6) ;Disable

 move.l 54(a2),a3 ;tc_spreg
 move.l 62(a2),d7 ;tc_spupper
 sub.l  a3,d7 ;d7=spupper-spreg
 cmp.l  #98,d7
 bne    Error_Device_Busy
 
 move.l #STACK_ERROR2_TXT,d6
 cmp.w  #$00e9,$32(a3)
 bne    Error_Device_Not_Found
 move.l $32(a3),d0
 sub.l  #BASEADDRESS,d0
 add.l  a4,d0
 move.l d0,$32(a3)

 move.l #STACK_ERROR3_TXT,d6
 cmp.w  #$00e9,$4a(a3)
 bne    Error_Device_Not_Found
 move.l $4a(a3),d0
 sub.l  #BASEADDRESS,d0
 add.l  a4,d0
 move.l d0,$4a(a3)

 move.l #A2091ToFastInstalled_TXT,d6
Error_Device_Not_Found2:
Error_Device_Busy2:
 jsr    -126(a6) ;Enable

SCSI_HANDLER_NOT_FOUND:
Error_NoMemory:
 move.l #DosName,a1
 moveq  #0,d0
 jsr    -552(a6)
 move.l d0,a6
 jsr    -60(a6) ;Output
 move.l d0,d1
 move.l d6,d2 ;Fehlermeldung
 move.l d2,a0
CountLength:
 tst.b  (a0)+
 bne.s  CountLength
 move.l a0,d3
 sub.l  d2,d3
 subq.l #1,d3
 jsr    -48(a6) ;Write
  
 moveq  #0,d0
 rts

DosName: 		dc.b "dos.library",0
ScsiTaskName: 	dc.b "A590/A2091 SCSI handler",0
ScsiIoReqTask: dc.b "A590/A2091 IORequest handler",0

SCSI_HANDLER_NOT_FOUND_TXT: 	dc.b "Error: A590/A2091 SCSI handler task not found.",10,0
IOREQ_HANDLER_NOT_FOUND_TXT: 	dc.b "Error: A590/A2091 IORequest handler task not found.",10,0

NO_MEM_TXT: 					dc.b "Not enough memory for 12864 bytes!!!. Not installed!",10,0
A2091ToFastInstalled_TXT: 	dc.b "A2091ToFast successfully installed",10,0
DEVICE_BUSY_TXT: 				dc.b "Stackframe not as expected. Probably device is busy.",10,"Installation canceled",10,0
STACK_ERROR1_TXT: 			dc.b "Stackframe 1 wrong. Maybe you own a other driver than me.",10,"Installation canceled",10,0
STACK_ERROR2_TXT: 			dc.b "Stackframe 2 wrong. Maybe you own a other driver than me.",10,"Installation canceled",10,0
STACK_ERROR3_TXT: 			dc.b "Stackframe 3 wrong. Maybe you own a other driver than me.",10,"Installation canceled",10,0
 end
