
;		;GENERALIZED MUSIC/SOUND DRIVER ROUTINE
;		;WITH VOLUME ENVELOPING
;
;		;X REGISTER SELECTS CHANNEL
;		;Y REGISTER INDEXES THRU SONG & ENVELOPES
;
;
;
;		;LOGIC TO SELECT SONG TO PLAY GOES HERE
;
;		BUT FOR NOW . . .
;
	PTR	MLINE,SONG0_PTR
	PTR	BLINE1,SONG1_PTR
;
;
;
	LDX	#0		;INITIALIZE X TO CHANNEL 0
				;INCREMENT X AT END AND DO IT ALL AGAIN	
.SLOOP:	CPX	#1
	BEQ	.CHNL1

.CHNL0:	LDA	SONG0_PTR
	STA	SONG_PTR
	LDA	SONG0_PTR+1
	STA	SONG_PTR+1
	JMP	.NEWS

.CHNL1:	LDA	SONG1_PTR
	STA	SONG_PTR
	LDA	SONG1_PTR+1
	STA	SONG_PTR+1

.NEWS:
	LDA	X,NOTE0_DUR		;NOTE OVER?
	BNE	.ENVL
	STA	X,ENV_INDEX_L		;RESET ENVELOPE FOR NEXT NOTE

	JSR	NEWSND			;GET NEW NOTE OR END SONG

	LDA	X,NOTE0_INDEX
	BEQ	.NXT

.ENVL:	JSR	ENVELOP			;DEVELOP ENVELOPE

	DEC	X,NOTE0_DUR

.NXT:	INX				;SELECT NEXT CHANNEL
	CPX	#2			;FINISHED?
	BNE	.SLOOP
