;				**********************************************
;				** THE MUZAX PLAY ROUTINE FOR NOISE TRACKER ** 
;				  ******************************************


MUZAX:

	jsr	Cryptic_init

end:	rts
Cryptic_init:
	lea	Cryptic_data,a0
	add.l	#$03b8,a0
	moveq	#$7f,d0
	moveq	#0,d1
Cryptic_init1:
	move.l	d1,d2
	subq.w	#1,d0
Cryptic_init2:
	move.b	(a0)+,d1
	cmp.b	d2,d1
	bgt.s	Cryptic_init1
	dbf		d0,Cryptic_init2
	addq.b	#1,d2
Cryptic_init3:
	lea		Cryptic_data,a0
	lea		Cryptic_sample1(pc),a1
	asl.l	#8,d2
	asl.l	#2,d2
	add.l	#$438,d2
	add.l	a0,d2
	moveq	#$1e,d0
Cryptic_init4:
	move.l	d2,(a1)+
	moveq	#0,d1
	move.w	42(a0),d1
	asl.l	#1,d1
	add.l	d1,d2
	add.l	#$1e,a0
	dbf		d0,Cryptic_init4
	lea		Cryptic_sample1(PC),a0
	moveq	#0,d0
Cryptic_clear:
	move.l	(a0,d0.w),a1
	clr.l	(a1)
	addq.w	#4,d0
	cmp.w	#$7c,d0
	bne.s	Cryptic_clear
	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	clr.l	Cryptic_partnrplay
	clr.l	Cryptic_partnote
	clr.l	Cryptic_partpoint
	move.b	Cryptic_data+$3b6,Cryptic_maxpart+1
	rts
	rts
Cryptic_music:
	addq.w	#1,Cryptic_counter
Cryptic_cool:
	cmp.w	#6,Cryptic_counter
	bne.s	Cryptic_notsix
	clr.w	Cryptic_counter
	bra		Cryptic_rout2
Cryptic_notsix:
	lea		Cryptic_aud1temp(PC),a6
	tst.b	3(a6)
	beq.s	Cryptic_arp1
	lea		$dff0a0,a5		
	bsr.s	Cryptic_arprout
Cryptic_arp1:
	lea	Cryptic_aud2temp(PC),a6
	tst.b	3(a6)
	beq.s	Cryptic_arp2
	lea		$dff0b0,a5
	bsr.s	Cryptic_arprout
Cryptic_arp2:
	lea		Cryptic_aud3temp(PC),a6
	tst.b	3(a6)
	beq.s	Cryptic_arp3
	lea		$dff0c0,a5
	bsr.s	Cryptic_arprout
Cryptic_arp3:
	lea		Cryptic_aud4temp(PC),a6
	tst.b	3(a6)
	beq.s	Cryptic_arp4
	lea		$dff0d0,a5
	bra.s	Cryptic_arprout
Cryptic_arp4:
	rts
Cryptic_arprout:
	move.b	2(a6),d0
	and.b	#$0f,d0
	tst.b	d0
	beq		Cryptic_arpegrt
	cmp.b	#$01,d0
	beq.s	Cryptic_portup
	cmp.b	#$02,d0
	beq.s	Cryptic_portdwn
	cmp.b	#$0a,d0
	beq.s	Cryptic_volslide
	rts
Cryptic_portup:
	moveq	#0,d0
	move.b	3(a6),d0
	sub.w	d0,22(a6)
	cmp.w	#$71,22(a6)
	bpl.s	Cryptic_ok1
	move.w	#$71,22(a6)
Cryptic_ok1:	
	move.w	22(a6),6(a5)
	rts
Cryptic_portdwn:
	moveq	#0,d0
	move.b	3(a6),d0
	add.w	d0,22(a6)
	cmp.w	#$538,22(a6)
	bmi.s	Cryptic_ok2
	move.w	#$538,22(a6)
Cryptic_ok2:	
	move.w	22(a6),6(a5)
	rts
Cryptic_volslide:
	moveq	#0,d0
	move.b	3(a6),d0
	lsr.b	#4,d0
	tst.b	d0
	beq.s	Cryptic_voldwn
	add.w	d0,18(a6)
	cmp.w	#64,18(a6)
	bmi.s	Cryptic_ok3
	move.w	#64,18(a6)
Cryptic_ok3:	
	move.w	18(a6),8(a5)
	rts
Cryptic_voldwn:
	moveq	#0,d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	sub.w	d0,18(a6)
	bpl.s	Cryptic_ok4
	clr.w	18(a6)
Cryptic_ok4:	
	move.w	18(a6),8(a5)
	rts
Cryptic_arpegrt:
	move.w	Cryptic_counter(PC),d0
	cmp.w	#1,d0
	beq.s	Cryptic_loop2
	cmp.w	#2,d0
	beq.s	Cryptic_loop3
	cmp.w	#3,d0
	beq.s	Cryptic_loop4
	cmp.w	#4,d0
	beq.s	Cryptic_loop2
	cmp.w	#5,d0
	beq.s	Cryptic_loop3
	rts
Cryptic_loop2:
	moveq	#0,d0
	move.b	3(a6),d0
	lsr.b	#4,d0
	bra.s	Cryptic_cont
Cryptic_loop3:
	moveq	#$00,d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	bra.s	Cryptic_cont
Cryptic_loop4:
	move.w	16(a6),d2
	bra.s	Cryptic_endpart
Cryptic_cont:
	add.w	d0,d0
	moveq	#0,d1
	move.w	16(a6),d1
	and.w	#$fff,d1
	lea		Cryptic_arpeggio(PC),a0
Cryptic_loop5:
	move.w	(a0,d0),d2
	cmp.w	(a0),d1
	beq.s	Cryptic_endpart
	addq.l	#2,a0
	bra.s	Cryptic_loop5
Cryptic_endpart:
	move.w	d2,6(a5)
	rts
Cryptic_rout2:
	lea		Cryptic_data,a0
	move.l	a0,a3
	add.l	#$0c,a3
	move.l	a0,a2
	add.l	#$3b8,a2
	add.l	#$43c,a0
	move.l	Cryptic_partnrplay(PC),d0
	moveq	#0,d1
	move.b	(a2,d0),d1
	asl.l	#8,d1
	asl.l	#2,d1
	add.l	Cryptic_partnote(PC),d1
	move.l	d1,Cryptic_partpoint
	clr.w	Cryptic_dmacon
	lea		$dff0a0,a5
	lea		Cryptic_aud1temp(PC),a6
	bsr		Cryptic_playit
	lea		$dff0b0,a5
	lea		Cryptic_aud2temp(PC),a6
	bsr		Cryptic_playit
	lea		$dff0c0,a5
	lea		Cryptic_aud3temp(PC),a6
	bsr		Cryptic_playit
	lea		$dff0d0,a5
	lea		Cryptic_aud4temp(PC),a6
	bsr		Cryptic_playit
	move.w	#$01f4,d0
Cryptic_rls:	
	dbf		d0,Cryptic_rls
	move.w	#$8000,d0
	or.w	Cryptic_dmacon,d0
	move.w	d0,$dff096
	lea		Cryptic_aud4temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	Cryptic_voice3
	move.l	10(a6),$dff0d0
	move.w	#1,$dff0d4
Cryptic_voice3:
	lea		Cryptic_aud3temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	Cryptic_voice2
	move.w	#1,$dff0c4
Cryptic_voice2:
	lea		Cryptic_aud2temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	Cryptic_voice1
	move.l	10(a6),$dff0b0
	move.w	#1,$dff0b4
Cryptic_voice1:
	lea		Cryptic_aud1temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	Cryptic_voice0
	move.l	10(a6),$dff0a0
	move.w	#1,$dff0a4
Cryptic_voice0:
	move.l	Cryptic_partnote(PC),d0
	add.l	#$10,d0
	move.l	d0,Cryptic_partnote
	cmp.l	#$400,d0
	bne.s	Cryptic_stop
Cryptic_higher:
	clr.l	Cryptic_partnote
	addq.l	#1,Cryptic_partnrplay
	moveq	#0,d0
	move.w	Cryptic_maxpart(PC),d0
	move.l	Cryptic_partnrplay(PC),d1
	cmp.l	d0,d1
	bne.s	Cryptic_stop
	clr.l	Cryptic_partnrplay
	;st	Pflag
Cryptic_stop:
	tst.w	Cryptic_status
	beq.s	Cryptic_stop2
	clr.w	Cryptic_status
	bra.s	Cryptic_higher
Cryptic_stop2:
	rts
Cryptic_playit:
	move.l	(a0,d1.l),(a6)
	addq.l	#4,d1
	moveq	#0,d2
	move.b	2(a6),d2
	and.b	#$f0,d2
	lsr.b	#4,d2
	move.b	(a6),d0
	and.b	#$f0,d0
	or.b	d0,d2
	tst.b	d2
	beq.s	Cryptic_nosamplechange
	moveq	#0,d3
	lea	Cryptic_samples(PC),a1
	move.l	d2,d4
	asl.l	#2,d2
	mulu	#$1e,d4
	move.l	(a1,d2),4(a6)
	move.w	(a3,d4.l),8(a6)
	move.w	2(a3,d4.l),18(a6)
	move.w	4(a3,d4.l),d3
	tst.w	d3
	beq.s	Cryptic_displace
	move.l	4(a6),d2
	add.l	d3,d2
	move.l	d2,4(a6)
	move.l	d2,10(a6)
	move.w	6(a3,d4.l),8(a6)
	move.w	6(a3,d4.l),14(a6)
	move.w	18(a6),8(a5)
	bra.s	Cryptic_nosamplechange
Cryptic_displace:
	move.l	4(a6),d2
	add.l	d3,d2
	move.l	d2,10(a6)
	move.w	6(a3,d4.l),14(a6)
	move.w	18(a6),8(a5)
Cryptic_nosamplechange:
	move.w	(a6),d0
	and.w	#$fff,d0
	tst.w	d0
	beq.s	Cryptic_retrout
	move.w	(a6),16(a6)
	move.w	20(a6),$dff096
	move.l	4(a6),(a5)
	move.w	8(a6),4(a5)
	move.w	(a6),d0
	and.w	#$fff,d0
	move.w	d0,6(a5)
	move.w	20(a6),d0
	or.w	d0,Cryptic_dmacon
Cryptic_retrout:
	tst.w	(a6)
	beq.s	Cryptic_nonewper
	move.w	(a6),22(a6)
Cryptic_nonewper:
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#$0b,d0
	beq.s	Cryptic_posjmp
	cmp.b	#$0c,d0
	beq.s	Cryptic_setvol
	cmp.b	#$0d,d0
	beq.s	Cryptic_break
	cmp.b	#$0e,d0
	beq.s	Cryptic_setfil
	cmp.b	#$0f,d0
	beq.s	Cryptic_setspeed
	rts
Cryptic_posjmp:
	not.w	Cryptic_status
	moveq	#0,d0
	move.b	3(a6),d0
	subq.b	#1,d0
	move.l	d0,Cryptic_partnrplay
	rts
Cryptic_setvol:
	move.b	3(a6),8(a5)
	rts
Cryptic_break:
	not.w	Cryptic_status
	rts
Cryptic_setfil:
	moveq	#0,d0
	move.b	3(a6),d0
	and.b	#1,d0
	rol.b	#1,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts
Cryptic_setspeed:
	move.b	3(a6),d0
	and.b	#$0f,d0
	beq.s	Cryptic_back
	clr.w	Cryptic_counter
	move.b	d0,Cryptic_cool+3
Cryptic_back:	rts
Cryptic_aud1temp:
	dcb.w	10,0
	dc.w	1
	dcb.w	2,0
Cryptic_aud2temp:
	dcb.w	10,0
	dc.w	2
	dcb.w	2,0
Cryptic_aud3temp:
	dcb.w	10,0
	dc.w	4
	dcb.w	2,0
Cryptic_aud4temp:
	dcb.w	10,0
	dc.w	8
	dcb.w	2,0
Cryptic_partnote:	dc.l	0
Cryptic_partnrplay:	dc.l	0
Cryptic_counter:	dc.w	0
Cryptic_partpoint:	dc.l	0
Cryptic_samples:	dc.l	0
Cryptic_sample1:	dcb.l	31,0
Cryptic_maxpart:	dc.w	0
Cryptic_dmacon:	dc.w	0
Cryptic_status:	dc.w	0
Cryptic_arpeggio:
	dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c
	dc.w $023a,$021a,$01fc,$01e0,$01c5,$01ac,$0194,$017d
	dc.w $0168,$0153,$0140,$012e,$011d,$010d,$00fe,$00f0
	dc.w $00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097
	dc.w $008f,$0087,$007f,$0078,$0071,$0000,$0000,$0000
