;*---------------------------------------------------------------------------
;  :Program.	stfix.s
;  :Contents.	routine to fix the old soundtracker playback routine
;		this old routine used in many games and demos contains an
;		empty dbf loop which wont work correctly on faster machines
;		the dbf loop will be replaced by a wait based on the vertical
;		raster position
;  :Version.	$Id: stfix.s 1.1 1998/06/14 20:53:41 jah Exp $
;  :History.	30.08.97 extracted from slave sources
;  :Requires.	-
;  :Copyright.	Public Domain
;  :Language.	68000 Assembler
;  :Translator.	Barfly V1.131
;  :To Do.
;---------------------------------------------------------------------------*
;
; bad stuff (contained 2 times):
;		move.w	#$12c,d0	;303c 012c
;	.loop	dbf	d0,.loop	;51c8 fffe
;
; the routine will scan the given memory area and patch the bad stuff
;
; IN:	A0 = APTR start of memory to patch
;	A1 = APTR end of memory to patch
; OUT:	d0-d1/a0-a1 destroyed

_stfix		subq.l	#7,a1
.s0		cmp.w	#$303c,(a0)
		bne	.s1
		cmp.w	#$012c,(2,a0)
		bne	.s1
		cmp.l	#$51c8fffe,(4,a0)
		bne	.s1
		move.w	#$4eb9,(a0)+		;JSR xxxxxxxx.L
		pea	(.wait,pc)
		move.l	(a7)+,(a0)
.s1		addq.l	#2,a0
		cmp.l	a0,a1
		bhi	.s0
		rts

.wait		move.l	d1,-(a7)
		moveq	#8,d1			;8.5 * 63.5µs = 0.54 ms
.1		move.b	$dff006,d0
.2		cmp.b	$dff006,d0
		beq	.2
		dbf	d1,.1
		move.l	(a7)+,d1
		addq.l	#2,(a7)
		rts

