***
*** NAME:	GlueMon v1.00 - Deliplayer version
*** 		(Original replay name unknown!)
*** 
*** AUTHOR:	Original replay (c) 1991 by GlueMaster / Northstar
*** 		Resourced and Deli-adapted by [·M·n·O·] (Lasse Jari Hansen)
***
*** E-MAIL:	ljh@sigma.ou.dk
***
*** HISTORY:	08-Nov-96 (Release)
***		21-Oct-96 (Deli-adaption)
***		  -Feb-92 (Stinger-adaption)
***		  -Jan-92 (Original Resourced)
***
*** INFO:	Original replay and music was used in the reset-part of
*** 		`His Master's Noise' - a musicdisk by Mahoney & Kaktus
*** 		finished Oct. 1991!
***
***		It uses calculated drums.
***
***		To my knowledge there has only been released 10 tunes
***		for this replay, these are...
***
***			Bestick
***			Game Music 1
***			Gnu-Song
***			Gurksaft
***			Jobba
***			Loader
***			Popcorn
***			Songname
***			Trudelut
***			Woodsock	;all by GlueMaster!
***
***		and are included in this release. (I have taken the liberty
***		of appending 8 bytes to each of	the modules for easy
***		recognition: "GLUE" and ~"GLUE")
***
***		Source released for educational purposes.
***		Feel free to contact me for bug reports or help.
***

pl_ver		=	1
pl_rev		=	11

DTP_GetNumPatterns	=	$8000448a

		incdir	"INCLUDE:"
		include	"misc/DeliPlayer.i"

;
;
		SECTION Player,Code
;
;

		PLAYERHEADER PlayerTagArray

		dc.b '$VER: GlueMon(?) player module V1.0 '
		dc.b ' '
		dc.b 0
		even

PlayerTagArray	dc.l	DTP_RequestDTVersion,16
		dc.l	DTP_PlayerVersion,(pl_ver<<16)+pl_rev
		dc.l	DTP_PlayerName,PName
		dc.l	DTP_Creator,CName
		dc.l	DTP_DeliBase,delibase
		dc.l	DTP_Check2,Chk
		dc.l	DTP_CheckLen,ChkLen
		dc.l	DTP_Flags,PLYF_SONGEND
		dc.l	DTP_Interrupt,Int
		dc.l	DTP_InitPlayer,InitPlay
		dc.l	DTP_EndPlayer,EndPlay
		dc.l	DTP_InitSound,InitSnd
		dc.l	DTP_EndSound,EndSnd
		dc.l	DTP_Volume,SetVol
		dc.l	DTP_Balance,SetVol

		dc.l	DTP_ModuleName,modname
		dc.l	DTP_GetNumPatterns,get_patts
		dc.l	TAG_DONE

*-----------------------------------------------------------------------*
;
; Player/Creatorname

PName		dc.b 'GlueMon',0
CName		dc.b 'GlueMaster / Northstar,',10
		dc.b 'adapted by [·M·n·O·]',0
my_song_end_first_flag
		dc.b	0
		even
delibase	dc.l 0
modname		dc.l	GLUE_modname

*-----------------------------------------------------------------------*
;
; Test the module

Chk		move.l	dtg_ChkData(a5),a0	; GlueMon ?
		moveq	#-1,d0			; module unknown (default)
		cmp.l	#$474C5545,(a0)		; "GLUE"
		bne.s	.ChkEnd
		cmp.l	#~$474C5545,4(a0)	; ~"GLUE"
		bne.s	.ChkEnd
		moveq	#0,d0			; module recognised
.ChkEnd		rts

ChkLen	=	*-Chk				; DELI copies routine ?

*-----------------------------------------------------------------------*
;
; Interrupt for Replay

Int		movem.l	d0-a6,-(sp)
		bsr	GLUE_music
		movem.l	(sp)+,d0-a6
		rts

InitPlay	moveq	#0,d0
		move.l	dtg_GetListData(a5),a0	; Function
		jsr	(a0)

		lea	GLUE_data(pc),a1
		addq.l	#8,a0			;GLUE + ~GLUE
		move.l	a0,(a1)			;set module
		lea	GLUE_modname(pc),a1
		moveq	#8-1,d0
.movname	move.b	(a0)+,(a1)+
		dbra	d0,.movname

		move.l	dtg_AudioAlloc(a5),a0	; Function
		jsr	(a0)			; returncode is already set !
		rts

EndPlay		move.l	dtg_AudioFree(a5),a0	; Function
		jsr	(a0)
		rts

InitSnd		movem.l	d0-a6,-(sp)
		lea	my_song_end_first_flag(pc),a0
		sf	(a0)

		bsr	GLUE_init
		movem.l	(sp)+,d0-a6
		rts

EndSnd		movem.l	d0-a6,-(sp)
		bsr	GLUE_end
		movem.l	(sp)+,d0-a6
		rts

SetVol		lea	GLUE_vol(pc),a0
		move	dtg_SndVol(a5),(a0)
		lea	GLUE_LBal(pc),a0
		move	dtg_SndLBal(a5),(a0)
		lea	GLUE_RBal(pc),a0
		move	dtg_SndRBal(a5),(a0)
		rts

get_patts	movem.l	d1-a6,-(sp)
		move.l	GLUE_data(pc),a0
		lea	151(a0),a1
		moveq	#0,d0
.setbigpat	cmp.b	(a1)+,d0
		bhs.s	.sbploop
		move.b	-1(a1),d0
.sbploop	cmp.b	#$ff,(a1)
		bne.s	.setbigpat
		addq	#1,d0
		movem.l	(sp)+,d1-a6
		rts

**********************************************************

***
***  GLUEMASTER REPLAY v?.?? (NOTE: DRUMBUFFER -> CHIPMEM)
***

glue_end	lea	$dff000,a6
		moveq	#0,d0
		move	d0,$a8(a6)
		move	d0,$b8(a6)
		move	d0,$c8(a6)
		move	d0,$d8(a6)
		move	#$f,$96(a6)
		rts

glue_music	tst	glue_1f60
		beq.s	.ok
		rts
.ok		lea	glue_drum1,a3
		move.l	glue_24c2,d1
		moveq	#7,d0
glue_1f7a	rol.l	#7,d1
		add.l	#$6eca756d,d1
		eori.l	#$9e59a92b,d1
		move.l	d1,(a3)+
		dbra	d0,glue_1f7a
		move.l	d1,glue_24c2
		lea	$dff000,a6
glue_1f9a	cmp	#0,glue_250a
		bls.b	glue_1fac
glue_1fa4	sub	#0,glue_250a
glue_1fac	cmp	#0,glue_250c
		bls.b	glue_1fbe
glue_1fb6	sub	#0,glue_250c
glue_1fbe	cmp	#0,glue_250e
		bls.b	glue_1fd0
glue_1fc8	sub	#0,glue_250e
glue_1fd0	cmp	#0,glue_2510
		bls.b	glue_1fe2
glue_1fda	sub	#0,glue_2510
glue_1fe2	addq.b	#1,glue_2512
glue_1fe8	cmp.b	#0,glue_2512
		bcc.b	glue_2004
		move.l	GLUE_data(pc),a4
		cmp	#$524d,18(a4)
		bne	glue_22c8
		bra	glue_22b4

glue_2004	clr.b	glue_2512
		add	#4,glue_261a
glue_2012	cmp	#256,glue_261a
		bcs.b	glue_205c
		clr	glue_261a
		addq	#1,glue_2518
		move	glue_2518,d0
		move.l	GLUE_data(pc),a0
		lea	151(a0),a0
		move.b	(a0,d0),d1
		cmp.b	#$ff,d1
		bne.b	glue_2048
		clr	glue_2518
		move.b	(a0),d1

		movem.l	d0-a6,-(sp)	;************ added by [·M·n·O·]
		lea	my_song_end_first_flag(pc),a0
		tst.b	(a0)
		bne.s	.doit
		st	(a0)
		bra.s	.dont
.doit		move.l	delibase(pc),a0
		move.l	dtg_SongEnd(a0),a0
		jsr	(a0)
.dont		movem.l	(sp)+,d0-a6	;************ added by [·M·n·O·]

glue_2048	and	#$ff,d1
		asl	#2,d1
		lea	glue_patterns(pc),a0
		move.l	(a0,d1),a2
		move.l	a2,glue_2514
glue_205c	move.l	glue_2514,a0
		move	glue_261a,d0
		move.b	(a0,d0),d1
		cmp.b	#$fe,d1
		bne.b	glue_207a
		clr	glue_250a
		bra.b	glue_2090

glue_207a	cmp.b	#$ff,d1
		beq.b	glue_2090
		bsr	glue_22ea
		move	d1,$a6(a6)
glue_2088	move	#0,glue_250a
glue_2090	move.b	1(a0,d0),d1
		cmp.b	#$fe,d1
		bne.b	glue_20a2
		clr	glue_250c
		bra.b	glue_20b8

glue_20a2	cmp.b	#$ff,d1
		beq.b	glue_20b8
		bsr	glue_22ea
		move	d1,$b6(a6)
glue_20b0	move	#0,glue_250c
glue_20b8	move.b	2(a0,d0),d1
		cmp.b	#$fe,d1
		bne.b	glue_20ca
		clr	glue_250e
		bra.b	glue_20e0

glue_20ca	cmp.b	#$ff,d1
		beq.b	glue_20e0
		bsr	glue_22ea
		move	d1,$c6(a6)
glue_20d8	move	#0,glue_250e
glue_20e0	move.l	GLUE_data(pc),a4
		cmp	#$524d,18(a4)
		beq.b	glue_211c
		move.b	3(a0,d0),d1
		cmp.b	#$fe,d1
		bne.b	glue_2100
		clr	glue_2510
		bra	glue_22c8

glue_2100	cmp.b	#$ff,d1
		beq	glue_22c8
		bsr	glue_22ea
		move	d1,$d6(a6)
glue_2110	move	#0,glue_2510
		bra	glue_22c8

glue_211c	move.b	3(a0,d0),d1
		cmp.b	#$ff,d1
		beq	glue_22b4
		cmp.b	#$c8,d1
		bne.b	glue_2158
		move.l	#glue_drum2,a0
		move	#$0710,glue_24be
		move	#$ff01,glue_24c0
		move	#$0040,glue_2510
		move.b	#8,glue_1fda+3
		bra	glue_22a4

glue_2158	cmp.b	#$c9,d1
		bne.b	glue_2188
		move.l	#glue_drum1,a0
		move	#$0710,glue_24be
		move	#$0014,glue_24c0
		move	#$0040,glue_2510
		move.b	#4,glue_1fda+3
		bra	glue_22a4

glue_2188	cmp.b	#$ca,d1
		bne.b	glue_21b8
		move.l	glue_2506,a0
		move	#$01c4,glue_24be
		move	#$ffce,glue_24c0
		move	#$0040,glue_2510
		move.b	#4,glue_1fda+3
		bra	glue_22a4

glue_21b8	cmp.b	#$cb,d1
		bne.b	glue_21e8
		move.l	glue_2506,a0
		move	#$025c,glue_24be
		move	#$ffce,glue_24c0
		move	#$0040,glue_2510
		move.b	#4,glue_1fda+3
		bra	glue_22a4

glue_21e8	cmp.b	#$cc,d1
		bne.b	glue_2218
		move.l	glue_2506,a0
		move	#$0388,glue_24be
		move	#$ffce,glue_24c0
		move	#$0040,glue_2510
		move.b	#4,glue_1fda+3
		bra	glue_22a4

glue_2218	cmp.b	#$cd,d1
		bne.b	glue_2246
		move.l	glue_2506,a0
		move	#$04b8,glue_24be
		move	#$ffce,glue_24c0
		move	#$0040,glue_2510
		move.b	#4,glue_1fda+3
		bra.b	glue_22a4

glue_2246	cmp.b	#$ce,d1
		bne.b	glue_2274
		move.l	#glue_drum1,a0
		move	#$025c,glue_24be
		move	#$fff6,glue_24c0
		move	#$0030,glue_2510
		move.b	#16,glue_1fda+3
		bra.b	glue_22a4

glue_2274	cmp.b	#$cf,d1
		bne.b	glue_22a4
		move.l	#glue_drum1,a0
		move	#$025c,glue_24be
		move	#$fff6,glue_24c0
		move	#$0028,glue_2510
		move.b	#2,glue_1fda+3
		bra	glue_22a4

glue_22a4	move	#8,$96(a6)
		move.l	a0,$d0(a6)
		move	#$8008,$96(a6)
glue_22b4	move	glue_24c0,d1
		sub	d1,glue_24be
		move	glue_24be,$d6(a6)

glue_22c8	movem.l	d0/d2,-(a7)		;;
		move	GLUE_LBal(pc),d0	;set LEFT vol
		mulu	GLUE_Vol(pc),d0
		lsr	#6,d0
		move	glue_250a(pc),d2	;chan 1
		mulu	d0,d2
		lsr	#6,d2
		move	d2,$a8(a6)
		move	glue_2510(pc),d2	;chan 4
		mulu	d0,d2
		lsr	#6,d2
		move	d2,$d8(a6)
		move	GLUE_RBal(pc),d0	;set RIGHT vol
		mulu	GLUE_Vol(pc),d0
		lsr	#6,d0
		move	glue_250c(pc),d2	;chan 2
		mulu	d0,d2
		lsr	#6,d2
		move	d2,$b8(a6)
		move	glue_250e(pc),d2	;chan 3
		mulu	d0,d2
		lsr	#6,d2
		move	d2,$c8(a6)
		movem.l	(a7)+,d0/d2
		rts

glue_22ea	lea	glue_periods(pc),a1
		and	#$fe,d1
		move	(a1,d1),d1
		rts

glue_init	movem.l	d0-a6,-(a7)
		move	#1,glue_1f60
		lea	$dff000,a6
		move.l	glue_data(pc),a5
		move	#$f,$96(a6)
		move.l	a5,d0
		add.l	#$16,d0
		move.l	d0,$a0(a6)
		move	#$10,$a4(a6)
		add.l	#$20,d0
		move.l	d0,$b0(a6)
		move	#$10,$b4(a6)
		add.l	#$20,d0
		move.l	d0,$c0(a6)
		move	#$10,$c4(a6)
		add.l	#$20,d0
		move.l	d0,glue_2506
		move.l	d0,$d0(a6)
		move	#$10,$d4(a6)
		move	#$800f,$96(a6)
		move.b	21(a5),d1
		and	#$ff,d1
		asl	#2,d1
		move	d1,glue_2012+2
		move	d1,d2
		sub	#4,d2
		move	d2,glue_261a
		move.b	150(a5),d0
		move.b	d0,d2
		sub.b	#2,d2
		and	#$ff,d2
		move	d2,glue_2518
		add.b	#151,d0
		and.l	#$ff,d0
		add.l	a5,d0
		lea	glue_patterns(pc),a0
		and.l	#$ffff,d1
		moveq	#64-1,d7
glue_23a6	move.l	d0,(a0)+
		add.l	d1,d0
		dbra	d7,glue_23a6
		move.b	08(a5),glue_2088+3
		move.b	09(a5),glue_1fa4+3
		move.b	10(a5),glue_1f9a+3
		move.b	11(a5),glue_20b0+3
		move.b	12(a5),glue_1fb6+3
		move.b	13(a5),glue_1fac+3
		move.b	14(a5),glue_20d8+3
		move.b	15(a5),glue_1fc8+3
		move.b	16(a5),glue_1fbe+3
		move.l	GLUE_data(pc),a4
		cmp	#$524d,$0012(a4)
		beq.b	glue_241c
		move.b	17(a5),glue_2110+3
		move.b	18(a5),glue_1fda+3
		move.b	19(a5),glue_1fd0+3
		bra.b	glue_2422

glue_241c	clr.b	glue_1fd0+3
glue_2422	move.b	20(a5),glue_1fe8+3
		move.b	20(a5),d0
		sub.b	#1,d0
		move.b	d0,glue_2512
		clr.l	glue_250a
		clr.l	glue_250e
		clr	glue_1f60
		clr	$a8(a6)
		clr	$b8(a6)
		clr	$c8(a6)
		clr	$d8(a6)
glue_245at	movem.l	(a7)+,d0-a6
		rts

glue_periods	dc	$d60,$ca0,$be8,$b40,$a98,$a00,$970,$8e8
		dc	$868,$7f0,$780,$710,$6b0,$650,$5f4,$5a0
		dc	$54c,$500,$4b8,$474,$434,$3f8,$3c0,$388
		dc	$358,$328,$2fa,$2d0,$2a6,$280,$25c,$23a
		dc	$21a,$1fc,$1e0,$1c4,$1ac,$194,$17d,$168
		dc	$153,$140,$12e,$11d,$10d,$fe,$f0,$e2,$d6

glue_24be	dc	0
glue_24c0	dc	0
glue_24c2	dc.l	0

glue_2506	dc.l	0
glue_250a	dc	0
glue_250c	dc	0
glue_250e	dc	0
glue_2510	dc	0
glue_2512	dc	0
glue_2514	dc.l	0
glue_2518	dc	0
glue_patterns	blk.l	64,0
glue_261a	dc	0

glue_1f60	dc	0
GLUE_data	dc.l	0
GLUE_vol	dc	0
GLUE_LBal	dc	0
GLUE_RBal	dc	0
GLUE_modname	dcb.b	9,0
		even

		section	drums,BSS_c

glue_drum1	ds.b	32
glue_drum2	ds.b	32


