;*---------------------------------------------------------------------------
;  :Modul.	blitfix_imm_58a0.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_58a0.s 1.4 2000/04/16 16:46:17 jah Exp $
;  :History.	15.03.99 generated from blitfix_imm_58a5.s
;		19.03.99 checked area fixed, a2 now returns pointer
;		09.04.00 interrupt blit check added
;  :Requires.	-
;  :Copyright.	Public Domain
;  :Language.	68000 Assembler
;  :Translator.	Barfly V1.131
;  :To Do.
;---------------------------------------------------------------------------*
;
; this will patch the following instruction:
;		move.w	#XXXX,($58,a0)
;
; 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 unchanged
;	A2 = APTR points to the end of patch routine

_blitfix_imm_58a0
		movem.l	a0-a1,-(a7)

	IFD PATCHCOUNT
		clr.w	(6,a2)
	ENDC

		subq.l	#4,a1
.loop		cmp.w	#$317c,(a0)+		;move.w #xxxx,($xxxx,a0)
		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)+

	IFD PATCHCOUNT
		addq.w	#2,a2
	ENDC

		movem.l	(a7)+,a0-a1
		rts

.movewait	move.l	a1,-(a7)
		move.l	(4,a7),a1
		move.w	(a1)+,($58,a0)
		move.l	a1,(4,a7)
		move.l	(a7)+,a1
		BLITWAIT a0
	IFD INTBLITCHECK
		move.l	d0,-(a7)
		move	sr,d0
		and.w	#$0700,d0
		beq	.intok
		illegal
.intok		move.l	(a7)+,d0
	ENDC
		rts
