;*---------------------------------------------------------------------------
;  :Modul.	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.3 1999/01/18 01:12:08 jah Exp jah $
;  :History.	30.08.97 extracted from slave sources
;		17.01.99 replacement counter added
;			 count in dbf is now variable (vision-md4)
;  :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 = LONG amount of replacments
;	D1/A0-A1 destroyed

_stfix		moveq	#0,d0
		subq.l	#7,a1
.s0		cmp.w	#$303c,(a0)		;move.w #xy,d0
		bne	.s1
		cmp.l	#$51c8fffe,(4,a0)	;dbf d0,*
		bne	.s1
		move.w	(2,a0),d1		;std is $12c=300
						;in vision-md4 variable $100-$1f4
		divu	#34,d1
		move.w	#$4eb9,(a0)+		;JSR xxxxxxxx.L
		pea	(.wait,pc)
		move.l	(a7)+,(a0)+
		move.w	d1,(a0)
		addq.l	#1,d0
.s1		addq.l	#2,a0
		cmp.l	a0,a1
		bhi	.s0
		rts

.wait		movem.l	d1/a0,-(a7)
		move.l	(8,a7),a0
		move.w	(a0)+,d1
		move.l	a0,(8,a7)
.1		move.b	$dff006,d0
.2		cmp.b	$dff006,d0
		beq	.2
		dbf	d1,.1
		movem.l	(a7)+,d1/a0
		rts

