;*---------------------------------------------------------------------------
;  :Modul.	blitfix_imm_58a5.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_imm_58a5.s 1.2 1998/11/22 14:29:48 jah Exp $
;  :History.	13.09.98 generated from blitfix_imm_58a4.s
;		13.09.98 now it saves all registers
;  :Requires.	-
;  :Copyright.	Public Domain
;  :Language.	68000 Assembler
;  :Translator.	Barfly V1.131
;  :To Do.
;---------------------------------------------------------------------------*
;
; this will patch the following instruction:
;		move.w	#XXXX,($58,a5)
;
; 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:	-

_blitfix_imm_58a5
		movem.l	a0/a2,-(a7)
	IFD PATCHCOUNT
		clr.w	(6,a2)
	ENDC

.loop		cmp.w	#$3b7c,(a0)+		;move.w #xxxx,($xxxx,a5)
		bne	.next
		cmp.w	#$0058,(2,a0)
		bne	.next
		move.w	(a0),(2,a0)		;save blitsize
		subq.w	#2,a0
		move.w	#$4eb8,(a0)+		;JSR $xxxx.w
		move.w	a2,(a0)+
	IFD PATCHCOUNT
		addq.w	#1,(6,a2)
	ENDC
.next		cmp.l	a0,a1
		bhs	.loop

		move.w	#$4ef9,(a2)+		;JMP $xxxxxxxx.l
		lea	.movewait,a0
		move.l	a0,(a2)+
		
		movem.l	(a7)+,a0/a2
		rts

.movewait	move.l	a0,-(a7)
		move.l	(4,a7),a0
		move.w	(a0)+,($58,a5)
		move.l	a0,(4,a7)
		move.l	(a7)+,a0
		BLITWAIT a5
		rts

