*************************************************
* Agony In Game Music 2 by Jeroen Tel (1990).	*
* Adapted by Mr.STYCKX / Nicolas Pomarède	*
*						*
* Original replay was in $973e.			*
*						*
* EaglePlayer / Delitracker port : 06/04/97	*
*	Volume					*
*	Balance					*
*	SubSong					*
*	SongEnd					*
*	EP_Voices				*
*	EP_StructInit (Analyzer)		*
* Uses Voices B, C, D				*
*						*	
*************************************************

	opt	o+

	output	ram:CUST.Agony2_MON


AGO_TEST	=		0	; 0 => BUILD COMPLETE CUSTOM MODULE
					; 1 => BUILD SMALL CODE FOR TESTING

	section	AGO,code_c



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


	IFEQ	AGO_TEST-0			; COMPLETE VERSION


	PLAYERHEADER PlayerTagArray

	dc.b '$VER: Agony InGame Music #2 (1990) custom player V1.0, '
	dc.b 'ripped and adapted by Mr.STYCKX (04/97)',0

	EVEN

PlayerTagArray
	dc.l	DTP_CustomPlayer,1		; CustomPlayer - Tag (important !!!)
	dc.l	DTP_Flags,PLYF_CUSTOM!PLYF_SONGEND

	dc.l	DTP_PlayerVersion,1<<16+0	; v1.0
	dc.l	EP_PlayerVersion,1
	dc.l	DTP_PlayerName,PName
	dc.l	DTP_Creator,CName

	dc.l	DTP_InitPlayer,InitPlay		; alloc audio
	dc.l	DTP_EndPlayer,EndPlay		; free audio
	dc.l	DTP_InitSound,AGO_init		; init custom data
	dc.l	DTP_EndSound,AGO_end		; clear DMA

	dc.l	DTP_SubSongRange,AGO_SubSongRange

	dc.l	DTP_Interrupt,AGO_Play

	dc.l	DTP_Volume,AGO_Volume
	dc.l	DTP_Balance,AGO_Volume

	dc.l	EP_Voices,AGO_SetVoices
	dc.l	EP_StructInit,AGO_StructInit

	dc.l	EP_Flags,EPB_Voices!EPB_Analyzer!EPB_Volume!EPB_Balance!EPB_Songend

	dc.l	TAG_DONE


PName	dc.b	"Agony InGame #2 v1.0",0
CName	dc.b	"Music by Jeroen Tel / MON (1990).",$a
	dc.b	"Adapted by Mr.STYCKX (06/04/97)",0

	EVEN


	ELSEIF				; TESTVERSION

	bra	AGO_Debug

	ENDC



;--------------- Constant depending on the module


ABS_START	=	$973e		; original start

INIT_		=	ABS_START	; init rout
VBL_		=	$97c2		; replay rout

DMAON_		=	$98da		; set DMA ON 
DMAOFF_		=	$996c		; set DMA OFF

PER_		=	$98ae		; set Per
VOL_		=	$98bc		; set Vol
START_		=	$9ab2		; set Start
LEN_		=	$9abc		; set Len
RSTART_		=	$9902		; set Repeat Start
RLEN_		=	$9912		; set Repeat Len





RelocMus
	tst.w	RelocFlag
	bne.s	.done
	lea	MusicData(pc),a0
	move.l	a0,d0
	sub.l	#ABS_START,d0

	add.l	d0,$9ea4-ABS_START(a0)
	add.l	d0,$9eac-ABS_START(a0)
	add.l	d0,$9eb4-ABS_START(a0)
	add.l	d0,$9ebc-ABS_START(a0)
	add.l	d0,$9ec4-ABS_START(a0)

	lea	$9ecc-ABS_START(a0),a1
	lea	$a0cc-ABS_START(a0),a2
.loop	add.l	d0,(a1)+
	cmp.l	a2,a1
	blt.s	.loop

	st	RelocFlag
.done	rts

RelocFlag	dc.w	0



;------ Set DMA ON

SetON	and.w	AGO_DMA_EP(pc),d0
	move.w	d0,$96(a5)
	rts



;------ Set DMA OFF

SetOFF	move.w	d1,$96(a5)
	rts



;------ Set DMA Per

SetPer	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
	move.w	d2,UPS_Voice1Per(a6)
	move.w	d2,$a6(a4)
	movem.l	(sp)+,d7/a6
	rts



;------ Set DMA Vol

SetVol	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
	move.w	d0,UPS_Voice1Vol(a6)
	lea	AGO_MasterVolA(pc),a6
	lsr.w	#1,d7			; addresses words
	mulu	(a6,d7.w),d0
	lsr.w	#6,d0
	move.w	d0,$a8(a4)
	movem.l	(sp)+,d7/a6
	rts



;------ Set DMA Start

SetStart
	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
	move.l	d1,UPS_Voice1Adr(a6)
	move.l	d1,$a0(a4)
	movem.l	(sp)+,d7/a6
	rts



;------ Set DMA Len

SetLen	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
	move.w	d1,UPS_Voice1Len(a6)
	move.w	d1,$a4(a4)
	movem.l	(sp)+,d7/a6
	rts



;------ Set DMA Repeat Start

SetRStart
	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
;;	move.l	d1,UPS_Voice1Adr(a6)
	move.l	d1,$a0(a4)
	movem.l	(sp)+,d7/a6
	rts


;------ Set DMA Repeat Len

SetRLen	movem.l	d7/a6,-(sp)
	lsl.w	#2,d7
	lea	AGO_StructA(pc),a6
	move.l	(a6,d7.w),a6
;;	move.w	d1,UPS_Voice1Len(a6)
	move.w	d1,$a4(a4)
	movem.l	(sp)+,d7/a6
	rts






;---------------------------------------------------------------
; Common part for custom module

	include	b:Agony_MON/AgonyCommon.s



;---------------------------------------------------------------
; Replay + music data

	dc.l	'MONS','TART'
MusicData
	incbin	b:Agony_MON/Agony2.bin



;---------------------------------------------------------------
; END
