;*---------------------------------------------------------------------------
;  :Program.	blitfix_dn_58a6.s
;  :Contents.	routine to fix program that does not correctly wait for
;		blitter finish
;		the instruction which writes the "bltsize" register will be
;		patched with a routine which will wait for blitter finish
;		after writing "bltsize"
;  :Version.	$Id: blitfix_dn_58a6.s 1.1 1998/06/14 20:54:50 jah Exp $
;  :History.	30.08.97 extracted from Turrican slave
;  :Requires.	-
;  :Copyright.	Public Domain
;  :Language.	68000 Assembler
;  :Translator.	Barfly V1.131
;  :To Do.
;---------------------------------------------------------------------------*
;
; this will patch the following instructions:
;		move.w	d0,($58,a6)
;		move.w	d1,($58,a6)
;		move.w	d2,($58,a6)
;		move.w	d3,($58,a6)
;		move.w	d4,($58,a6)
;		move.w	d5,($58,a6)
;		move.w	d6,($58,a6)
;		move.w	d7,($58,a6)
;
; IN:	A0 = APTR start of memory to patch
;	A1 = APTR end of memory to patch
;	A2 = APTR space for patch routine MUST be < $8000 !!!
; OUT:	D0-D1/A0-A1 destroyed

_blitfix_dn_58a6
		movem.l	a2-a4,-(a7)

		move.l	a2,d1			;D1 = jmp table

		lea	(.wait_d0),a3
		lea	(.wait_end),a4
.cpy		move.w	(a3)+,(a2)+
		cmp.l	a3,a4
		bne	.cpy
	IFD PATCHCOUNT
		clr.l	(a2)+
		clr.l	(a2)
	ENDC

.loop		move.w	(a0)+,d0
		and.w	#$fff8,d0
		cmp.w	#$3d40,d0		;move.w dx,($58,a6)
		bne	.next
		cmp.w	#$0058,(a0)
		bne	.next
		move.w	-(a0),d0		;old opcode
		move.w	#$4eb8,(a0)+		;JSR $XXXX.w
		move.w	d1,(a0)
		and.w	#7,d0			;register number
	IFD PATCHCOUNT
		addq.b	#1,(-4,a2,d0)
	ENDC
		mulu	#6,d0
		add.w	d0,(a0)+		;jmp address
.next		cmp.l	a0,a1
		bhs	.loop

		movem.l	(a7)+,a2-a4
		rts

.wait_d0	move.w	d0,($58,a6)
		bra.b	.wait
.wait_d1	move.w	d1,($58,a6)
		bra.b	.wait
.wait_d2	move.w	d2,($58,a6)
		bra.b	.wait
.wait_d3	move.w	d3,($58,a6)
		bra.b	.wait
.wait_d4	move.w	d4,($58,a6)
		bra.b	.wait
.wait_d5	move.w	d5,($58,a6)
		bra.b	.wait
.wait_d6	move.w	d6,($58,a6)
		bra.b	.wait
.wait_d7	move.w	d7,($58,a6)
.wait		BLITWAIT a6
		rts
.wait_end

