****************************************************************
****************************************************************
(main)player.asm

      	ORG     $9000

	PSHS	U,X,DP,B,A,CC

	ORCC	#$50
	LDA	#$FB
	ANDA	$E7CF
	STA	$E7CF
	LDA	#$3F
	STA	$E7CD
	LDA	#$04
	ORA	$E7CF
	STA	$E7CF
	LDX	#$A000
	STX	pos_song
	BRA	loop

	PULS 	U,X,DP,B,A,CC
	RTS

fine	fcb	0
pos_song fcb 	$A0,$00




****************************************************************
*
*
*	bank 5
*	read pattern info
*	switch to bank
*	read pattern data
*	output to DAC
*	advance in pattern
*	if necessary, advance in song
*	try to be less than 64, fixed timing
*
****************************************************************

loop
	LDB	#05
	STB	$E7E5
	LDX	pos_song
	LDB	,x+
	LDA	,x+
	TFR	x,y
* switch to pattern bank
	STB	$E7E5
	CLRB
	ADDA	#$A0
	TFR	D,X
	LDB	fine
	ABX	
	LDA	,x
	STA	$E7CD
	INCB	
	CMPB	#160
	BEQ	end_chunk
	STB	fine
	BRA	wait1
wait1   BRA     wait2
wait2   BRA     end
end_chunk
	CLR	fine
	STY	pos_song	
	
end
*  85 cycles for now ... wait 43
	MUL
	MUL	
	MUL
	NOP
	NOP
	BRA	pre_end
pre_end	BRA	loop



****************************************************************
*
*	Attente de la VBL	
*
****************************************************************
VSYNC
VSYNC_1
	TST	$E7E7
	BPL	VSYNC_1
VSYNC_2
	TST	$E7E7
	BMI	VSYNC_2

	RTS


