	module pt3player

	if !pt3_init
curs=$
	org pt3player.Psa_beg_addr
	dw module+201
	org pt3player.Psa_loop_addr
	dw module+201+({module+102}&255)
	org pt3player.Psa_chn_addr
	dw module+{module+103}

	org pt3player.smpPP_addr
	dw module+105

	org pt3player.curtempo
	db {module+100}&255

;fix sample and ornament addresses
	org module+105
smp0={$}+module
	dup 32
	dw {$}+module
	edup
orn0={$}+module
	dup 16
	dw {$}+module
	edup

	org As_adr
	dw smp0
	org Bs_adr
	dw smp0
	org Cs_adr
	dw smp0

	org Ao_adr
	dw orn0
	org Bo_adr
	dw orn0
	org Co_adr
	dw orn0

	macro FINDMAX
curpattern={findmaxaddr}&255
	if curpattern==#ff
	else
	if curpattern>maxpattern
maxpattern=curpattern
	endif
findmaxaddr=findmaxaddr+1
	endif
	endm

;find max pattern number
maxpattern=0
findmaxaddr=module+201
curpattern=0
	dup 255
	FINDMAX
	;include "findmax.asm"
	edup
	display "max pattern number(*3)=",maxpattern

;fix track addresses (patterns*3 = maxpattern+3 words)
	org findmaxaddr+1
	dup maxpattern+3
	dw {$}+module
	edup

	org Ach_adr
	dw ZERO_M;tab_frq+191 ;contains 0 to read position list
	org Bch_adr
	dw ZERO_M;tab_frq+191 ;
	org Cch_adr
	dw ZERO_M;tab_frq+191 ;

	org #4000
	;org pt3player.true_tab_frq
	if ({module+99}&255)==0
	display "using freq table #0"
	incbin "tb_PT.$c!"
	endif
	if ({module+99}&255)==1
	display "using freq table #1"
	incbin "tb_ST.$c!"
	endif
	if ({module+99}&255)==2
	display "using freq table #2"
	incbin "tb_REAL.$c!"
	endif
	if ({module+99}&255)==3
	display "using freq table #3"
	incbin "tb_ASM.$c!"
	endif

	org pt3player.true_tab_frq
	dup pt3_frqsz
	dw {$-pt3player.virtual_tab_frq+#4000}
	edup

	org Xni_not
	include "pt3parse.asm"
	;XNI_NOT
	;EFFECTS

	org curs
	endif

	endmodule
