; FILE: Source:modules/SpeedyIDE.ASM          REV: 3 --- Speed up scsi.device access

;
; Speed up scsi.device IDE disk access
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Written by Harry Sintonen.
; This source code is Public Domain.
;

	incdir	"include:"
	include	"blizkickmodule.i"	; Some required...

	SECTION	PATCH,CODE
_DUMMY_LABEL
	BK_PTC

; Code is run with following incoming parameters:
;
; a0=ptr to ROM start (buffer)	eg. $1DE087B8
; a1=ptr to ROM start (ROM)	eg. $00F80000 (do *not* access!)
; d0=ROM lenght in bytes	eg. $00080000
; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
;    CALL: jsr (a2)
;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
;     OUT: d0=ptr to resident (buf) or NULL
; a3=ptr to _InstallModule routine (can be used to plant a "module"):
;    CALL: jsr (a3)
;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
;     OUT: d0=success
; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
;    CALL: jsr (a4)
;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
;     OUT: -
; d6=dosbase, a6=execbase
;
; Code should return:
;
; d0=true if succeeded, false if failed.
; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)

	cmp.w	#37,($C,a0)
	bhs.b	.cont
	moveq	#0,d0
.fail	rts

.cont	lea	(scsiname,pc),a1
	jsr	(a2)
	tst.l	d0
	beq.b	.fail

	move.l	d0,a0			; a0=beg of search
	lea	(16384,a0),a1		; a1=end of search

	move.l	#$700F32D0,d1
	move.l	#$32D032D0,d2
	bsr.b	.find
	beq.b	.not_found
	move.l	d0,a2

	move.l	#$700F3099,d1
	move.l	#$30993099,d2
	bsr.b	.find
	beq.b	.not_found
	move.l	d0,a3

	move.l	#$700722D0,d1
	move.l	a2,a0
	bsr.b	.set

	move.l	#$70072099,d1
	move.l	a3,a0
	bsr.b	.set

	moveq	#1,d0
	rts

.not_found	moveq	#0,d0
	rts

.find	movem.l	a0-a1,-(sp)
.findl	addq.l	#2,a0
	cmp.l	a1,a0
	bhs.b	.fnot_found
	cmp.l	(a0),d1
	bne.b	.findl
	cmp.l	(4,a0),d2
	bne.b	.findl
	cmp.l	(8,a0),d2
	bne.b	.findl
	cmp.l	(12,a0),d2
	bne.b	.findl
	cmp.l	(16,a0),d2
	bne.b	.findl
	move.l	a0,d0
.fexit	movem.l	(sp)+,a0-a1
	rts
.fnot_found	moveq	#0,d0
	bra.b	.fexit

.set	move.l	d1,(a0)+
	moveq	#16-1-1,d0
.setl	move.w	d1,(a0)+
	dbf	d0,.setl
	rts


scsiname	dc.b	'scsi.device',0


	SECTION	VERSION,DATA

	dc.b	'$VER: SpeedyIDE_PATCH 1.0 (21.5.97)',0

