
	incdir	"Include:"
	include "misc/EaglePlayer.i"

	PLAYERHEADER BP_TagListe

	dc.b '$VER: SoundMon 2.0 player module V1.6 (28 Dec 92)',0
	even

BP_TagListe:	dc.l	DTP_PlayerVersion,2
		dc.l	DTP_PlayerName,BP_Name
		dc.l	DTP_Creator,BP_Creator
		dc.l	DTP_Check2,Chk
		dc.l	DTP_Interrupt,BP_Music
		dc.l	DTP_InitPlayer,InitPlay
		dc.l	DTP_EndPlayer,EndPlay
		dc.l	DTP_InitSound,BP_Init
		dc.l	DTP_EndSound,RemSnd
		dc.l	DTP_Volume,SetVol
		dc.l	DTP_Balance,SetVol
		dc.l	EP_Voices,SetVoices

		dc.l	EP_StructInit,BP_GetStructAdr
		dc.l	EP_StructEnd,BP_FreeStructAdr

;		dc.l	EP_SampleInit,SampleInit
;		dc.l	EP_SampleEnd,SampleEnd

		dc.l	EP_Get_ModuleInfo,GetInfos
		dc.l	EP_Free_ModuleInfo,FreeInfos

		dc.l	EP_Flags,EPB_Save!EPB_Restart!EPB_Volume!EPB_Balance!EPB_Voices!EPB_Analyzer!EPB_SongEnd

		dc.l	0
	
BP_RightVol	dc.w	64
BP_LeftVol	dc.w	64

BP_Voice1	dc.w	1		;
BP_Voice2	dc.w	1		;
BP_Voice3	dc.w	1		;
BP_Voice4	dc.w	1		;
BP_OldVoice1	dc.w	0		; Don`t change !!!
BP_OldVoice2	dc.w	0		;
BP_OldVoice3	dc.w	0		;
BP_OldVoice4	dc.w	0		;
BP_SongEndBase:	dc.l	0		;

*------------------------ Player & Creatorname -------------------------*
BP_Name:	dc.b	"SoundMon",0
BP_Creator:	dc.b	"Brian Postma,",10
		dc.b	"adapted by Eagleeye of DEFECT",0
BP_Prefix:	dc.b	"BP.",0
		even

*------------------- Tag-Item Struktur für Module-Info -----------------*
InfoBuffer:	dc.l	MI_SongName,0			;0
		dc.l	MI_Samples,0			;8
		dc.l	MI_MaxSamples,15		;16
		dc.l	MI_SynthSamples,0		;24
		dc.l	MI_MaxSynthSamples,15		;32
		dc.l	MI_Steps,0			;40
CalcSize:	dc.l	MI_CalcSize,0			;48
		dc.l	MI_Prefix,BP_Prefix
		dc.l	0

BP_StructAdr:	ds.b	UPS_SizeOf

*-------------------------- Get StructAdr ------------------------------*
BP_GetStructAdr:lea	BP_StructAdr(pc),a0
BP_FreeStructAdr:rts

*----------------- Get Infos (Create InfoTag-Itemliste) ----------------*
GetInfos:	lea	InfoBuffer(pc),a0
		move.l	BP_Data(pc),a1
		move.l	a1,4(a0)
		move.w	$1e(a1),46(a0)
		subq.w	#1,46(a0)		;Last Step

		move.l	a1,a2
		moveq	#0,d0
		moveq	#0,d1
		moveq	#14,d3
.NextSample:	lea	$20(a2),a2
		cmp.b	#$ff,(a2)
		beq.s	.SynthSample
		tst.l	$18(a2)
		beq.s	.NextSample2
.Sample:	addq.l	#1,d0
		bra.b	.NextSample2
.SynthSample:	addq.l	#1,d1
.NextSample2:	dbf	d3,.NextSample
		move.l	d0,12(a0)		;Sample
		move.l	d1,28(a0)		;Synth-Sample
FreeInfos:	rts

*-------------------- SoundMon V2.0 Check-Routine -----------------------*
Chk:		move.l	dtg_ChkData(a5),a0
		move.l	$1a(a0),d0
		lsr.l	#8,d0
		subi.l	#"V.2",d0
		rts

*-----------------------------------------------------------------------*
InitPlay:	lea	BP_OldVoice1(pc),a0		;Voices 0 setzen=alle an
		clr.l	(a0)+
		clr.l	(a0)+
		move.l	DTG_SongEnd(a5),a1
		move.l	a1,(a0)			; SongEndBase

		moveq	#0,d0
		move.l	dtg_GetListData(a5),a0	; Function
		jsr	(a0)
		move.l	a0,BP_Data
		move.l	dtg_AudioAlloc(a5),a0	; Function
		jmp	(a0)			; returncode is already set !

*-----------------------------------------------------------------------*
EndPlay:	move.l	dtg_AudioFree(a5),a0		; Function
		jmp	(a0)

*-----------------------------------------------------------------------*
RemSnd:		lea	$dff000,a0
		clr.w	$a8(a0)
		clr.w	$b8(a0)
		clr.w	$c8(a0)
		clr.w	$d8(a0)
		move.w	#$F,$96(a0)			; End Sound
		rts

*-----------------------------------------------------------------------*
*		d0 Bit 0-3 = Set Voices Bit=1 Voice on			*
SetVoices:	lea	BP_Voice1(pc),a0
		lea	BP_StructAdr(pc),a1
		moveq	#1,d1
		move.w	d1,(a0)+			Voice1=0 setzen
		btst	#0,d0
		bne.s	.NoVoice1
		clr.w	-2(a0)
		clr.w	$dff0a8
		clr.w	UPS_Voice1Vol(a1)
.NoVoice1:	move.w	d1,(a0)+			Voice2=0 setzen
		btst	#1,d0
		bne.s	.NoVoice2
		clr.w	-2(a0)
		clr.w	$dff0b8
		clr.w	UPS_Voice2Vol(a1)
.NoVoice2:	move.w	d1,(a0)+			Voice3=0 setzen
		btst	#2,d0
		bne.s	.NoVoice3
		clr.w	-2(a0)
		clr.w	$dff0c8
		clr.w	UPS_Voice3Vol(a1)
.NoVoice3:	move.w	d1,(a0)+			Voice4=0 setzen
		btst	#3,d0
		bne.s	.NoVoice4
		clr.w	-2(a0)
		clr.w	$dff0d8
		clr.w	UPS_Voice4Vol(a1)
.NoVoice4:	move.w	d0,UPS_DmaCon(a1)
		moveq	#0,d0
		rts

*-----------------------------------------------------------------------*
SetVol:		move.w	DTG_SndLBal(a5),d0
		mulu	DTG_SndVol(a5),d0
		lsr.w	#6,d0				; durch 64
		move.w	d0,BP_LeftVol			; Left Volume

		move.w	DTG_SndRBal(a5),d0
		mulu	DTG_SndVol(a5),d0
		lsr.w	#6,d0				; durch 64
		move.w	d0,BP_RightVol			; Right Volume


		lea	BP_OldVoice1(pc),a0
		lea	$dff0a0,a5
		moveq	#3,d1
.SetNew		move.w	(a0)+,d0
		bsr.s	BP_SetVoices
		addq.l	#8,a5
		addq.l	#8,a5
		dbf	d1,.SetNew
		rts


	;*****************************************
	;**** Sound-Mon-Pro-SetVoices-Routine ****
	;*****************************************
BP_SetVolume7:	movem.l	d0/a5,-(a7)
		moveq	#0,d0
		move.b	2(a2),d0
		bra.b	BP_SetVolume3
BP_SetVolume6:	movem.l	d0/a5,-(a7)
		move.w	6(a3,d7.l),d0
		bra.b	BP_SetVolume3
BP_SetVolume5:	movem.l	d0/a5,-(a7)
		move.l	d4,d0
		move.l	a3,a5
		bra.b	BP_SetVolume4
BP_SetVolume:	movem.l	d0/a5,-(a7)
		move.l	d3,d0
		bra.b	BP_SetVolume3
BP_SetVolume2:	movem.l	d0/a5,-(a7)
		move.l	d4,d0
BP_SetVolume3:	move.l	a1,a5
BP_SetVolume4:	bsr.w	BP_SetVoices
		movem.l	(a7)+,d0/a5
		rts

	;**** Setze Voices ****
BP_SetVoices:	cmp.l	#$dff0a0,a5			;Left Volume
		bne.s	.NoVoice1
		move.w	d0,BP_OldVoice1
		move.w	d0,BP_StructAdr+UPS_Voice1Vol
		tst.w	BP_Voice1
		bne.w	.Voice1ON
		move	#0,d0
.Voice1On:	mulu.w	BP_LeftVol(pc),d0
		bra.b	.SetIt
.NoVoice1:	cmp.l	#$dff0b0,a5			;Right Volume
		bne.s	.NoVoice2
		move.w	d0,BP_OldVoice2
		move.w	d0,BP_StructAdr+UPS_Voice2Vol
		tst.w	BP_Voice2
		bne.s	.Voice2On
		moveq	#0,d0
.Voice2On:	mulu.w	BP_RightVol(pc),d0
		bra.b	.SetIt
.NoVoice2:	cmp.l	#$dff0c0,a5			;Right Volume
		bne.s	.NoVoice3
		move.w	d0,BP_OldVoice3
		move.w	d0,BP_StructAdr+UPS_Voice3Vol
		tst.w	BP_Voice3
		bne.s	.Voice3On
		moveq	#0,d0
.Voice3On:	mulu.w	BP_RightVol(pc),d0
		bra.b	.SetIt
.NoVoice3:	move.w	d0,BP_OldVoice4
		move.w	d0,BP_StructAdr+UPS_Voice4Vol
		tst.w	BP_Voice4
		bne.s	.Voice4On
		moveq	#0,d0
.Voice4On:	mulu.w	BP_LeftVol(pc),d0
.SetIt		lsr.l	#6,d0
		move.w	d0,8(a5)
.Return:	rts

*-----------------------------------------------------------------------*
	**************************************************
	**	BP-SoundMon V2.0 - Replay-Routine	**
	**************************************************
;		SECTION Replay,Code_C
BP_Init:	move.w	#15,$dff096
		move.l	BP_Data(pc),a0
		lea	BP_D17,a1
		lea	BP_DataEnd,a2
		moveq	#14,d0
.Co2:		move.l	a2,(a1)+
		dbf	d0,.CO2

		move.l	a0,a1
		lea	BP_d4,a0
		clr.l	(a0)+
		clr.b	(a0)+
		lea	BP_D17,a0
		clr.b	BP_D12
		cmpi.w	#$562e,$1a(a1)
		bne.w	BP_int1
		cmpi.b	#$32,$1c(a1)
		bne.w	BP_int1
		move.b	$1d(a1),BP_D12
BP_int1:	move.l	#$200,d0
		move.w	$1e(a1),d1
		moveq	#1,d2
		mulu	#$4,d1
		subq.w	#$1,d1
BP_int2:	cmp.w	0(a1,d0.l),d2
		bge.w	BP_int3
		move.w	$0(a1,d0.l),d2
BP_int3:	addq.l	#4,d0
		dbf	d1,BP_int2
		move.w	$1e(a1),d1
		mulu	#16,d1
		move.l	#$200,d0
		mulu	#$30,d2
		add.l	d2,d0
		add.l	d1,d0
		move.l	BP_Data(pc),d1
		add.l	d1,d0
		move.l	d0,BP_D14
		clr.l	d1
		move.b	BP_D12,d1
		lsl.l	#6,d1
		add.l	d1,d0
		moveq	#$e,d1

		adda.l	#$20,a1
BP_int4:	move.l	d0,(a0)+
		cmpi.b	#-$1,(a1)
		beq.w	BP_int5
		move.w	$18(a1),d2
		mulu	#2,d2
		add.l	d2,d0
BP_int5:	adda.l	#$20,a1
		dbf	d1,BP_int4
		sub.l	BP_Data(pc),d0			->> SoundMon-Size
		move.l	d0,CalcSize+4
		rts	

BP_Music:	movem.l	d1-d7/a0-a6,-(a7)
		lea	BP_StructAdr(pc),a0

	move.w	#UPSB_Adr!UPSB_LEN!UPSB_Per!UPSB_Vol!UPSB_DMACON,UPS_Flags(a0)

		move.w	#1,UPS_Enabled(a0)

		clr.w	UPS_Voice1Per(a0)
		clr.w	UPS_Voice2Per(a0)
		clr.w	UPS_Voice3Per(a0)
		clr.w	UPS_Voice4Per(a0)

		bsr	BP_MS2

		clr.w	BP_StructAdr+UPS_Enabled

		movem.l	(a7)+,d1-d7/a0-a6
		moveq	#0,d0
		rts	


BP_MS2:		bsr.w	BP_MX7
		subq.b	#1,BP_D10
		move.l	#3,d0
		lea	BP_D3,a0
		move.l	#$dff0a0,a1
BP_MS3:		move.b	$c(a0),d4
		ext.w	d4
		add.w	d4,(a0)
		tst.b	$1e(a0)
		bne.w	BP_MS4


		move.w	(a0),6(a1)

		tst.w	(a0)
		beq.s	.BP_PerRet
			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	(a0),BP_StructAdr+UPS_Voice1Per
			bra.s	.BP_PerRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	(a0),BP_StructAdr+UPS_Voice2Per
			bra.s	.BP_PerRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	(a0),BP_StructAdr+UPS_Voice3Per
			bra.s	.BP_PerRet
.BP_NoVoice3:		move.w	(a0),BP_StructAdr+UPS_Voice4Per
.BP_PerRet


BP_MS4:		move.l	4(a0),(a1)

			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.l	4(a0),BP_StructAdr+UPS_Voice1Adr
			bra.s	.BP_AdrRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.l	4(a0),BP_StructAdr+UPS_Voice2Adr
			bra.s	.BP_AdrRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.l	4(a0),BP_StructAdr+UPS_Voice3Adr
			bra.s	.BP_AdrRet
.BP_NoVoice3:		move.l	4(a0),BP_StructAdr+UPS_Voice4Adr
.BP_AdrRet




BP_Label1:	move.w	8(a0),4(a1)

	tst.w	8(a0)
;	beq.s	.BP_LenRet
			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	8(a0),BP_StructAdr+UPS_Voice1Len
			bra.s	.BP_LenRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	8(a0),BP_StructAdr+UPS_Voice2Len
			bra.s	.BP_LenRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	8(a0),BP_StructAdr+UPS_Voice3Len
			bra.s	.BP_LenRet
.BP_NoVoice3:		move.w	8(a0),BP_StructAdr+UPS_Voice4Len
.BP_LenRet


		tst.b	$b(a0)
		bne.w	BP_MS5
		tst.b	$d(a0)
		beq.w	BP_MS8
BP_MS5:		tst.b	BP_D10
		bne.w	BP_MS6
		move.b	$b(a0),d3
		move.b	$d(a0),d4
		andi.w	#$f0,d4
		andi.w	#$f0,d3
		lsr.w	#4,d3
		lsr.w	#4,d4
		add.w	d3,d4
		add.b	$a(a0),d4
		bsr.w	BP_MX6
		bra.w	BP_MS8

BP_MS6:		cmpi.b	#1,BP_D10
		bne.w	BP_MS7
		move.b	$b(a0),d3
		move.b	$d(a0),d4
		andi.w	#$f,d3
		andi.w	#$f,d4
		add.w	d3,d4
		add.b	$a(a0),d4
		bsr.w	BP_MX6
		bra.w	BP_MS8

BP_MS7:		move.b	$a(a0),d4
		bsr.w	BP_MX6
BP_MS8:		lea	$10(a1),a1
		lea	$20(a0),a0
		dbf	d0,BP_MS3
		tst.b	BP_D10
		bne.w	BP_MS9
		move.b	#3,BP_D10
BP_MS9:		subq.b	#1,BP_D8
		beq.w	BP_MT1
		rts	

BP_MT1:		move.b	BP_D9,BP_D8
		bsr.s	BP_MU1
		move.w	BP_D13,$00dff096
		move.l	#$1f4,d0
BP_MT2:		dbf	d0,BP_MT2
		moveq	#3,d0

		lea	$dff0a0,a1
		move.w	#$1,d1
		lea	BP_D3,a2
		lea	BP_D15,a5
BP_MT3:		btst	#$07,(a2)
		beq.w	BP_MT4
		bsr.w	BP_MW3
BP_MT4:		asl.w	#$1,d1
		lea	$10(a1),a1
		lea	$20(a2),a2
		lea	$24(a5),a5
		dbf	d0,BP_MT3
		rts	

BP_MU1:		clr.w	BP_D13
		move.l	BP_Data(pc),a0
		lea	$dff0a0,a3
		moveq	#3,d0

		move.w	#$1,d7
		lea	BP_D3,a1
BP_MU2:		clr.l	d1
		move.w	BP_D4,d1
		lsl.w	#$4,d1
		move.l	d0,d2
		lsl.l	#$2,d2
		add.l	d2,d1
		addi.l	#$200,d1
		move.w	(a0,d1.l),d2
		move.b	$2(a0,d1.l),BP_D6
		move.b	$3(a0,d1.l),BP_D7
		subq.w	#$1,d2
		mulu	#$30,d2
		clr.l	d3
		move.w	$1e(a0),d3
		lsl.w	#$4,d3
		add.l	d2,d3
		move.l	#$200,d4
		move.b	BP_D5,d4
		add.l	d3,d4
		move.l	d4,a2
		adda.l	a0,a2
		clr.l	d3
		move.b	(a2),d3
		tst.b	d3
		bne.w	BP_MU3
		bra.w	BP_MV0

BP_MU3:		clr.w	$c(a1)
		move.b	$1(a2),d4
		andi.b	#$f,d4
		cmpi.b	#$a,d4
		bne.w	BP_MU4
		move.b	$2(a2),d4
		andi.b	#-$10,d4
		bne.w	BP_MU5
BP_MU4:		add.b	BP_D7,d3
		ext.w	d3
BP_MU5:		move.b	d3,$a(a1)
		lea	BP_D16,a4
		lsl.w	#$1,d3
		move.w	-$2(a4,d3.w),(a1)
		bset	#$7,(a1)
		move.b	#-$1,$2(a1)
		clr.w	d3
		move.b	$1(a2),d3
		lsr.b	#$4,d3
		andi.b	#$0f,d3
		tst.b	d3
		bne.w	BP_MU6
		move.b	$3(a1),d3
BP_MU6:		move.b	$1(a2),d4
		andi.b	#$f,d4
		cmpi.b	#$a,d4
		bne.w	BP_MU7
		move.b	$2(a2),d4
		andi.b	#$f,d4
		bne.w	BP_MU8
BP_MU7:		add.b	BP_D6,d3
BP_MU8:		cmpi.w	#$1,$8(a1)
		beq.w	BP_MU9
		cmp.b	$3(a1),d3
		beq.w	BP_MV0
BP_MU9:		move.b	d3,$3(a1)
		or.w	d7,BP_D13
BP_MV0:		clr.l	d3
		clr.l	d4
		move.b	$1(a2),d3
		andi.b	#$f,d3
		move.b	$2(a2),d4
		tst.b	d3
		bne.w	BP_MV1
		move.b	d4,$b(a1)
BP_MV1:		cmpi.b	#$01,d3
		bne.w	BP_MV2
	;	move.w	d4,$8(a3)		;Vol (Found)
		bsr	BP_SetVolume5

		move.b	d4,$2(a1)
BP_MV2:		cmpi.b	#$2,d3
		bne.w	BP_MV3
		move.b	d4,BP_D8
		move.b	d4,BP_D9
BP_MV3:		cmpi.b	#$3,d3
		bne.w	BP_MV5
		tst.b	d4
		bne.w	BP_MV4
		bset	#1,$bfe001
		bra.w	BP_MW1

BP_MV4:		bclr	#1,$bfe001
BP_MV5:		cmpi.b	#4,d3
		bne.w	BP_MV6
		sub.w	d4,(a1)
		clr.b	$b(a1)
BP_MV6:		cmpi.b	#5,d3
		bne.w	BP_MV7
		add.w	d4,(a1)
		clr.b	$b(a1)
BP_MV7:		cmpi.b	#6,d3
		bne.w	BP_MV8
		move.b	d4,BP_D11
BP_MV8:		cmpi.b	#7,d3
		bne.w	BP_MV9
		subq.b	#1,BP_D11
		beq.w	BP_MV9
		move.w	d4,BP_D4
BP_MV9:		cmpi.b	#8,d3
		bne.w	BP_MW0
		move.b	d4,$c(a1)
BP_MW0:		cmpi.b	#9,d3
		bne.w	BP_MW1
		move.b	d4,$d(a1)
BP_MW1:		lea	$10(a3),a3
		lea	$20(a1),a1
		asl.w	#1,d7
		dbf	d0,BP_MU2
		addq.b	#3,BP_D5
		cmpi.b	#$30,BP_D5
		bne.w	BP_MW2
		clr.b	BP_D5
		addq.w	#1,BP_D4
		move.l	BP_Data(pc),a0
		move.w	$1e(a0),d1
		cmp.w	BP_D4,d1
		bne.w	BP_MW2
		clr.w	BP_d4
	move.l	a0,-(a7)
	move.l	BP_SongEndBase(pc),a0
	jsr	(a0)
	move.l	(a7)+,a0
BP_MW2:		rts	

BP_MW3:		bclr	#$07,(a2)
		tst.l	(a5)
		beq.w	BP_MW5
		clr.w	d3
		move.l	(a5),a4
		moveq	#7,d7
BP_MW4:		move.l	$4(a5,d3.w),(a4)+
		addq.w	#4,d3
		dbf	d7,BP_MW4
BP_MW5:		move.w	(a2),$6(a1)


		tst.w	(a2)
		beq.s	.BP_PerRet
			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	(a2),BP_StructAdr+UPS_Voice1Per
			bra.s	.BP_PerRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	(a2),BP_StructAdr+UPS_Voice2Per
			bra.s	.BP_PerRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	(a2),BP_StructAdr+UPS_Voice3Per
			bra.s	.BP_PerRet
.BP_NoVoice3:		cmp.l	#$dff0d0,a1
			bne.s	.BP_PerRet
			move.w	(a2),BP_StructAdr+UPS_Voice4Per
.BP_PerRet



		clr.l	d7
		move.b	3(a2),d7
		move.l	d7,d6
		lsl.l	#5,d7
		move.l	BP_Data(pc),a3
		cmpi.b	#-1,(a3,d7.w)
		beq.w	BP_MX0
		clr.l	(a5)
		clr.b	$1a(a2)
		clr.w	$1e(a2)
		addi.l	#$18,d7
		lsl.l	#2,d6
		lea	BP_D17,a4
		move.l	-4(a4,d6.l),d4
		beq.w	BP_MW7
		move.l	d4,(a1)
		move.w	(a3,d7.l),4(a1)
;		move.b	2(a2),9(a1)
	move.b	2(a2),d6
	bsr	BP_SetVolume7

		cmpi.b	#-1,2(a2)
		bne.w	BP_MW6
	;move.w	6(a3,d7.l),8(a1)		;Vol	(Found)
	bsr	BP_SetVolume6

BP_MW6:		move.w	4(a3,d7.l),8(a2)		;Vol	(NO)
		clr.l	d6
		move.w	2(a3,d7.l),d6
		add.l	d6,d4
		move.l	d4,4(a2)
		cmpi.w	#1,8(a2)
		bne.w	BP_MW8
BP_MW7:		move.l	#BP_D2,$4(a2)
		bra.w	BP_MW9

BP_MW8:		move.w	8(a2),4(a1)
		move.l	4(a2),(a1)
BP_MW9:		addi.w	#-$8000,d1
		move.w	d1,$dff096
		rts	

BP_MX0:		move.b	#1,$1a(a2)
		clr.w	$e(a2)
		clr.w	$10(a2)
		clr.w	$12(a2)
		move.w	$16(a3,d7.w),$14(a2)
		addq.w	#1,$14(a2)
		move.w	$e(a3,d7.w),$16(a2)
		addq.w	#1,$16(a2)
		move.w	#1,$18(a2)
		move.b	$11(a3,d7.w),$1d(a2)
		move.b	$9(a3,d7.w),$1e(a2)
		move.b	$4(a3,d7.w),$1f(a2)
		move.b	$13(a3,d7.w),$1c(a2)
		move.l	BP_D14,a4
		clr.l	d3
		move.b	1(a3,d7.w),d3
		lsl.l	#6,d3
		adda.l	d3,a4
		move.l	a4,(a1)

			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.l	a4,BP_StructAdr+UPS_Voice1Adr
			bra.s	.BP_AdrRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.l	a4,BP_StructAdr+UPS_Voice2Adr
			bra.s	.BP_AdrRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.l	a4,BP_StructAdr+UPS_Voice3Adr
			bra.s	.BP_AdrRet
.BP_NoVoice3:		move.l	a4,BP_StructAdr+UPS_Voice4Adr
.BP_AdrRet		move.l	a4,$4(a2)


Zwischen1		move.w	2(a3,d7.w),$4(a1)

			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	2(a3,d7.w),BP_StructAdr+UPS_Voice1Per
			bra.s	.BP_PerRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	2(a3,d7.w),BP_StructAdr+UPS_Voice2Per
			bra.s	.BP_PerRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	2(a3,d7.w),BP_StructAdr+UPS_Voice3Per
			bra.s	.BP_PerRet
.BP_NoVoice3:		move.w	2(a3,d7.w),BP_StructAdr+UPS_Voice4Per
.BP_PerRet


		move.w	2(a3,d7.w),$8(a2)		;Vol
		tst.b	4(a3,d7.w)
		beq.w	BP_MX2
		move.l	BP_D14,a4
		clr.l	d3
		move.b	5(a3,d7.w),d3
		lsl.l	#6,d3
		adda.l	d3,a4
		clr.w	d3
		move.b	(a4),d3
		addi.b	#-$80,d3
		lsr.w	#2,d3
		cmpi.b	#-1,2(a2)
		bne.w	BP_MX1
		move.b	$19(a3,d7.w),2(a2)
BP_MX1:		clr.w	d4
		move.b	2(a2),d4
		mulu	d4,d3
		lsr.w	#6,d3
	;	move.w	d3,8(a1)			;Vol3
	bsr	BP_SetVolume

		bra.w	BP_MX3

BP_MX2:		;move.b	2(a2),9(a1)
	bsr	BP_SetVolume7
		cmpi.b	#-1,2(a2)
		bne.w	BP_MX3

;		move.b	$19(a3,d7.w),$9(a1)
		movem.l	d0/a5,-(a7)
		moveq	#0,d0
		move.b	$19(a3,d7.w),d0
		move.l	a1,a5
		bsr	BP_SetVoices
		movem.l	(a7)+,d0/a5

BP_MX3:		move.l	4(a2),a4
		move.l	a4,(a5)
		clr.w	d3
		moveq	#7,d4
BP_MX4:		move.l	(a4,d3.w),4(a5,d3.w)
		addq.w	#4,d3
		dbf	d4,BP_MX4
		tst.b	$11(a3,d7.w)
		beq.w	BP_MW9
		tst.b	$13(a3,d7.w)
		beq.w	BP_MW9
		clr.l	d3
		move.b	$13(a3,d7.w),d3
		lsr.l	#3,d3
		move.b	d3,$1c(a2)
		subq.l	#1,d3
BP_MX5:		neg.b	(a4)+
		dbf	d3,BP_MX5
		bra.w	BP_MW9

BP_MX6:		lea	BP_D16,a4
		ext.w	d4
		asl.w	#1,d4
		move.w	-2(a4,d4.w),6(a1)

	tst.w	-2(a4,d4.w)
	beq.s	.BP_PerRet
			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	-2(a4,d4.w),BP_StructAdr+UPS_Voice1Per
			bra.s	.BP_PerRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	-2(a4,d4.w),BP_StructAdr+UPS_Voice2Per
			bra.s	.BP_PerRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	-2(a4,d4.w),BP_StructAdr+UPS_Voice3Per
			bra.s	.BP_PerRet
.BP_NoVoice3:		move.w	-2(a4,d4.w),BP_StructAdr+UPS_Voice4Per
.BP_PerRet		rts


BP_MX7:		moveq	#3,d0
		lea	BP_D3,a2
		lea	$dff0a0,a1
		move.l	BP_Data(pc),a3
		lea	BP_D15,a5
BP_MX8:		tst.b	$1a(a2)
		beq.w	BP_MX9
		bsr.s	BP_MY0
BP_MX9:		lea	$24(a5),a5
		lea	$20(a2),a2
		lea	$10(a1),a1
		dbf	d0,BP_MX8
		rts	

BP_MY0:		clr.w	d7
		move.b	3(a2),d7
		lsl.w	#5,d7
		tst.b	$1f(a2)
		beq.w	BP_MY1
		subq.w	#1,$18(a2)
		bne.w	BP_MY1
		clr.l	d3
		move.b	8(a3,d7.w),d3
		move.w	d3,$18(a2)
		move.l	BP_D14,a4
		move.b	5(a3,d7.w),d3
		lsl.l	#6,d3
		adda.l	d3,a4
		move.w	$12(a2),d3
		clr.w	d4
		move.b	0(a4,d3.w),d4
		addi.b	#-$80,d4
		lsr.w	#2,d4
		clr.w	d3
		move.b	2(a2),d3
		mulu	d3,d4
		lsr.w	#6,d4
	;	move.w	d4,8(a1)			;Vol4
	bsr	BP_SetVolume2

		addq.w	#1,$12(a2)
		move.w	6(a3,d7.w),d4
		cmp.w	$12(a2),d4
		bne.w	BP_MY1
		clr.w	$12(a2)
		cmpi.b	#1,$1f(a2)
		bne.w	BP_MY1
		clr.b	$1f(a2)
BP_MY1:		tst.b	$1e(a2)
		beq.w	BP_MY3
		subq.w	#1,$16(a2)
		bne.w	BP_MY3
		clr.l	d3
		move.b	16(a3,d7.w),d3
		move.w	d3,$16(a2)
		move.l	BP_D14,a4
		move.b	10(a3,d7.w),d3
		lsl.l	#6,d3
		adda.l	d3,a4
		move.w	$10(a2),d3
		clr.l	d4
		move.b	(a4,d3.w),d4
		ext.w	d4
		ext.l	d4
		clr.l	d5
		move.b	$b(a3,d7.w),d5
		tst.b	d5
		beq.w	BP_MY2
		divs	d5,d4
BP_MY2:		move.w	(a2),d5
		add.w	d4,d5
		move.w	d5,$6(a1)

		tst.w	d5
		beq.s	.BP_PerRet
			cmp.l	#$dff0a0,a1
			bne.s	.BP_NoVoice1
			move.w	d5,BP_StructAdr+UPS_Voice1Per
			bra.s	.BP_PerRet
.BP_NoVoice1		cmp.l	#$dff0b0,a1
			bne.s	.BP_NoVoice2
			move.w	d5,BP_StructAdr+UPS_Voice2Per
			bra.s	.BP_PerRet
.BP_NoVoice2:		cmp.l	#$dff0c0,a1
			bne.s	.BP_NoVoice3
			move.w	d5,BP_StructAdr+UPS_Voice3Per
			bra.s	.BP_PerRet
.BP_NoVoice3:		cmp.l	#$dff0d0,a1
			bne.s	.BP_PerRet
			move.w	d5,BP_StructAdr+UPS_Voice4Per
.BP_PerRet

		addq.w	#1,$10(a2)
		move.w	$c(a3,d7.w),d3
		cmp.w	$10(a2),d3
		bne.w	BP_MY3
		clr.w	$10(a2)
		cmpi.b	#1,$1e(a2)
		bne.w	BP_MY3
		clr.b	$1e(a2)
BP_MY3:		tst.b	$1d(a2)
		beq.w	BP_MY8
		subq.w	#1,$14(a2)
		bne.w	BP_MY8
		tst.l	(a5)
		beq.w	BP_MY8
		clr.l	d3
		move.b	$18(a3,d7.w),d3
		move.w	d3,$14(a2)
		move.l	BP_D14,a4
		move.b	$12(a3,d7.w),d3
		lsl.l	#6,d3
		adda.l	d3,a4
		move.w	$e(a2),d3
		clr.l	d4
		move.b	(a4,d3.w),d4
		move.l	(a5),a4
		addi.b	#-$80,d4
		lsr.l	#3,d4
		clr.l	d3
		move.b	$1c(a2),d3
		move.b	d4,$1c(a2)
		adda.l	d3,a4
		move.l	a5,a6
		adda.l	d3,a6
		addq.l	#4,a6
		cmp.b	d3,d4
		beq.w	BP_MY7
		bgt.w	BP_MY5
		sub.l	d4,d3
		subq.l	#1,d3
BP_MY4:		move.b	-(a6),d4
		move.b	d4,-(a4)
		dbf	d3,BP_MY4
		bra.w	BP_MY7

BP_MY5:		sub.l	d3,d4
		subq.l	#1,d4
BP_MY6:		move.b	(a6)+,d3
		neg.b	d3
		move.b	d3,(a4)+
		dbf	d4,BP_MY6
BP_MY7:		addq.w	#1,$e(a2)
		move.w	$14(a3,d7.w),d3
		cmp.w	$e(a2),d3
		bne.w	BP_MY8
		clr.w	$e(a2)
		cmpi.b	#1,$1d(a2)
		bne.w	BP_MY8
		clr.b	$1d(a2)
BP_MY8:		rts	


BP_Data:	dc.l	0

	section	bp_daten,code_c
BP_D1:		dcb.b	8,0
		dc.b	2,$7f
		dcb.b	8,0
		dc.l	BP_Music
BP_D2:		dcb.b	2,0
BP_D3:		dcb.b	4,0
		dc.l	BP_D2
		dc.b	0,1
		dcb.b	26,0
		dc.l	BP_D2
		dc.b	0,1
		dcb.b	26,0
		dc.l	BP_D2
		dc.b	0,1
		dcb.b	26,0
		dc.l	BP_D2
		dc.b	0,1
		dcb.b	22,0
BP_D4:		dcb.b	2,0
BP_D5:		dcb.b	1,0
BP_D6:		dcb.b	1,0
BP_D7:		dcb.b	1,0
BP_D8:		dc.b	1
BP_D9:		dc.b	6
BP_D10:		dc.b	1
BP_D11:		dc.b	1
BP_D12:		dcb.b	1,0
BP_D13:		dcb.b	2,0
BP_D14:		dcb.b	4,0
BP_D15:		dcb.b	144,0
		dc.b	$1a,$c0,$19,$40,$17,$c0,$16,$80,$15,$40,$14,$00
		dc.b	$12,$e0,$11,$e0,$10,$e0,$f,$e0,$0f,$00,$0e,$20
		dc.b	$d,$60,$c,$a0,$b,$e0,$b,$40,$0a,$a0,$0a,$00
		dc.b	$9,$70,$8,$f0,$8,$70,$7,$f0,$07,$80,$07,$10
		dc.b	$6,$b0,$6,$50,$5,$f0,$5,$a0,$05,$50,$05,$00
		dc.b	$4,$b8,$4,$78,$4,$38,$3,$f8,$03,$c0,$03,$88
BP_D16:		dc.b	$3,$58,$3,$28,$2,$f8,$2,$d0,$02,$a8,$02,$80
		dc.b	$2,$5c,$2,$3c,$2,$1c,$1,$fc,$01,$e0,$01,$c4
		dc.b	$1,$ac,$1,$94,$1,$7c,$1,$68,$01,$54,$01,$40
		dc.b	$1,$2e,$1,$1e,$1,$0e,$0,$fe,$00,$f0,$00,$e2
		dc.b	$0,$d6,$0,$ca,$0,$be,$0,$b4,$00,$aa,$00,$a0
		dc.b	$0,$97,$0,$8f,$0,$87,$0,$7f,$00,$78,$00,$71
		dc.b	$0,$6b,$0,$65,$0,$5f,$0,$5a,$00,$55,$00,$50
		dc.b	$0,$4c,$0,$48,$0,$44,$0,$40,$00,$3c,$00,$39
BP_D17:		ds.l	15

BP_DATAEND:	dc.b	$c8,$ca,$cd,$cf,$cf,$d6

