
	.include	"sound_mod.i"
	.include	"sound_mix.i"

	.align	4	

;*****************************************************************************************************************
;*
;*	ROM 
;*
;*****************************************************************************************************************

	.global		pfreq
	.global		sampletime
	.global		periodTable

pfreq			@dcd	($ffff-(16777216/PLAYBACK_FREQ))  ;22050;	0xFFFF-round(cpuFreq/playbackFreq)
sampletime		@dcd	($ffff-(SAMPLE_BUFFER_LENGTH-1))	;0xFFFF-time
sampleNULL		@dcd	0



periodTable	

	@dcd	856,808,762,720,678,640,604,570,538,508,480,453,428,404,381,360,339,320,302,285,269,254,240,226,214,202,190,180,170,160,151,143,135,127,120,113
	@dcd	850,802,757,715,674,637,601,567,535,505,477,450,425,401,379,357,337,318,300,284,268,253,239,225,213,201,189,179,169,159,150,142,134,126,119,113
	@dcd	844,796,752,709,670,632,597,563,532,502,474,447,422,398,376,355,335,316,298,282,266,251,237,224,211,199,188,177,167,158,149,141,133,125,118,112
	@dcd	838,791,746,704,665,628,592,559,528,498,470,444,419,395,373,352,332,314,296,280,264,249,235,222,209,198,187,176,166,157,148,140,132,125,118,111
	@dcd	832,785,741,699,660,623,588,555,524,495,467,441,416,392,370,350,330,312,294,278,262,247,233,220,208,196,185,175,165,156,147,139,131,124,117,110
	@dcd	826,779,736,694,655,619,584,551,520,491,463,437,413,390,368,347,328,309,292,276,260,245,232,219,206,195,184,174,164,155,146,138,130,123,116,109
	@dcd	820,774,730,689,651,614,580,547,516,487,460,434,410,387,365,345,325,307,290,274,258,244,230,217,205,193,183,172,163,154,145,137,129,122,115,109
	@dcd	814,768,725,684,646,610,575,543,513,484,457,431,407,384,363,342,323,305,288,272,256,242,228,216,204,192,181,171,161,152,144,136,128,121,114,108
	@dcd	907,856,808,762,720,678,640,604,570,538,508,480,453,428,404,381,360,339,320,302,285,269,254,240,226,214,202,190,180,170,160,151,143,135,127,120
	@dcd	900,850,802,757,715,675,636,601,567,535,505,477,450,425,401,379,357,337,318,300,284,268,253,238,225,212,200,189,179,169,159,150,142,134,126,119
	@dcd	894,844,796,752,709,670,632,597,563,532,502,474,447,422,398,376,355,335,316,298,282,266,251,237,223,211,199,188,177,167,158,149,141,133,125,118
	@dcd	887,838,791,746,704,665,628,592,559,528,498,470,444,419,395,373,352,332,314,296,280,264,249,235,222,209,198,187,176,166,157,148,140,132,125,118
	@dcd	881,832,785,741,699,660,623,588,555,524,494,467,441,416,392,370,350,330,312,294,278,262,247,233,220,208,196,185,175,165,156,147,139,131,123,117
	@dcd	875,826,779,736,694,655,619,584,551,520,491,463,437,413,390,368,347,328,309,292,276,260,245,232,219,206,195,184,174,164,155,146,138,130,123,116
	@dcd	868,820,774,730,689,651,614,580,547,516,487,460,434,410,387,365,345,325,307,290,274,258,244,230,217,205,193,183,172,163,154,145,137,129,122,115
	@dcd	862,814,768,725,684,646,610,575,543,513,484,457,431,407,384,363,342,323,305,288,272,256,242,228,216,203,192,181,171,161,152,144,136,128,121,114

;*****************************************************************
;*
;* changevolume_mod
;*
;* r0 = volume $0..200 (mehr ist boost)
;*	

changevolume_mod

	stmfd	sp!,{r1}

	ldr	r1,=sampleXAll
	str	r0,[r1,#MASTER_VOLUME]		;Master Volume
	
	ldmfd	sp!,{r1}
	bx	lr

;*****************************************************************
;*
;* init_mod
;*
;* r0 = mod
;*	
	
	.global		init_mod
	
init_mod

	stmfd	sp!,{r0-r12}

	;**** reset structs
	
	ldr	r12,=modplayer
	mov	r1,#0
	mov	r2,#5
	str	r1,[r12,#MOD_TICK]
	str	r2,[r12,#MOD_TICK_GO]
	str	r1,[r12,#MOD_ROW_POS]
	str	r1,[r12,#MOD_PATTERN_POS]	
	str	r1,[r12,#MOD_HIGHEST_PATTERN]
	str	r1,[r12,#MOD_AKT_PATTERN]
	str	r1,[r12,#MOD_SAMPLES_BASE]

	ldr	r11,=modadr
	str	r0,[r11]
	mov	r11,r0

	;**** find highest pattern
	
	ldrb	r0,[r11,#950]		;songlen 
	
	add	r10,r11,#$3b0
	add	r10,r10,#$8		;952
	
	mov	r3,#0			;song positions
	mov	r2,#0			;highestpos
sonpgs		
	ldrb	r1,[r10,r3]		;
	cmp	r1,r2
	movgt	r2,r1
	
	add	r3,r3,#1
	cmp	r3,#128
	bne	sonpgs

	addr	r12,modplayer
	str	r2,[r12,#MOD_HIGHEST_PATTERN]

	;samplestartbase = mod+1084+((mod->highestpattern+1)*1024);
	
	add	r2,r2,#1
	add	r2,r11,r2, lsl #10 	;mod+(mod->highestpattern+1)*1024
	add	r2,r2,#$400
	add	r2,r2,#$3c		;+1084
	
	str	r2,[r12,#MOD_SAMPLES_BASE]
			
	;save sample addrs
	
	addr	r6,modsmpa
	
	ldr	r4,[r12,#MOD_SAMPLES_BASE]		;samplebase
	add	r5,r11,#20				;sampleinfos
	
	mov	r7,#31
smpalo	
	str	r4,[r6],#4
	ldrh	r8,[r5,#22]				;samplelength
	
	add	r4,r4,r8, lsl #1		
	
	add	r5,r5,#30				;next samplestrukt
	subs	r7,r7,#1
	bne	smpalo

	ldmfd	sp!,{r0-r12}
	bx	lr	
	
;*****************************************************************
;*
;* start_mod
;*
;*	

	.global		start_mod

start_mod		
	
	stmfd	sp!,{r0-r12}
	
	;uses timer 0 as sampling rate source
	;uses timer 1 to count the samples played in order to stop the sound 

	mov	r6,#$4000000
	add	r7,r6,#$100
	add	r8,r6,#$200
	
	;sound conf

	ldr	r0,=$9a0f		;REG_SOUNDCNT_H=0x0b0F;  ABRatio 100%, AB 100%, a left, b right
	mov	r1,#$0080		;REG_SOUNDCNT_X=0x0080; 
	mov	r2,#0			;
	
	strh	r0,[r6,#$80]		;
	strh	r0,[r6,#$82]		;enable DS A&B + fifo ab reset + a&b use timer0 + max volume to L and R
	strh	r1,[r6,#$84]		;turn sound chip on

	;timer conf

	addr	r0,sampletime
	ldr	r0,[r0]		;=$7098
	mov	r1,#$c4
	
	strh	r0,[r7,#$4]		;REG_TM1CNT_L=0x7098; //0xffff-the number of samples to play
	strh	r1,[r7,#$6]		;REG_TM1CNT_H=0xC4; //enable timer1 + irq and cascade from timer 0

	mov	r0,#$10
	mov	r1,#$1
	
	ldr	r9,[r8]
	ldr	r10,[r8,#$8]
	orr	r9,r9,r0
	orr	r10,r10,r1
	strh	r9,[r8,#$0]		;REG_IE=0x10; //enable irq for timer 1 
	strh	r10,[r8,#$8]		;REG_IME=1; //master enable interrupts

	addr	r3,pfreq
	ldr	r0,[r3]
	mov	r1,#$80

	;Formula for playback frequency is: 0xFFFF-round(cpuFreq/playbackFreq)

	strh	r0,[r7,#$0]		;REG_TM0CNT_L=0xFBE8; //16khz playback freq
	strh	r1,[r7,#$2]		;REG_TM0CNT_H=0x0080; //enable timer0
	
	ldmfd	sp!,{r0-r12}
	bx	lr
	

;*****************************************************************
;*
;* stop_mod
;*
;*

	.global		stop_mod
	.type		stop_mod,function

stop_mod
	
	stmfd	sp!,{r0-r12}

	mov	r6,#$4000000
	add	r7,r6,#$100
	add	r8,r6,#$200


	;* stop dma

	mov	r3,#0
	strh	r3,[r6,#$c6]		;stop DMA1	
	strh	r3,[r6,#$d2]		;stop DMA2
	

	;* stop timer 1


	ldrh	r0,[r8,#$0]		;get reg_ie
	bic	r0,r0,#$10		;clear timer 1
	strh	r0,[r8,#$0]		;set
	
	;* stop direkt sound
	
	mov	r0,#0			;clear all
	strh	r0,[r6,#$82]		;soundcnt_h

	ldmfd	sp!,{r0-r12}
	
	bx	lr		
	
;*****************************************************************************************************************
;*
;*	IWRAM 
;*
;*****************************************************************************************************************
	

	.section    	.iwram,"ax"
	.arm
	.align		4	
	
;****************************************************************	
;*
;* decodeAndSet (Setzt NoteX (r4) in Chanel sampleX (r3))
;*
;* r3  = sampleX?
;* r4  = ChanelData
;* r9  = chanel?
;* r11 = modadr
;* r12 = modplay
	
decodeAndSet

	stmfd	sp!,{r0-r12,lr}

;	Byte 1 = 7..0  nindex7:0
;	Byte 2 = 6..5  periodenindex9:8  4..0  samplenummer
;	Byte 3 = 15..8 effekt
;	Byte 4 = 7..0  effekt

	mov	r5,r4,lsr #24			;pindex
	mov	r6,r4,lsr #21
	and	r6,r6,#$3
	orr	r5,r5,r6,lsl #8
	
	mov	r6,r4,lsr #16		
	and	r6,r6,#$1f			;samplenummer
	
	mov	r7,r4,lsl #16
	mov	r7,r7,lsr #16			;effekt
	
	;sub	r6,r6,#1
	
	;**** get sample info
	
	mov	r8,#$400
	sub	r8,r8,#1	;3ff
	
	cmp	r5,r8
	moveq	r8,#0				;noplay
	beq	no_period_infos
	
	sub	r0,r6,#1			;sample 1 -> 0
	
	add	r10,r11,#20			;sampleinfos
	add	r10,r10,r0,lsl #5		;+*32
	sub	r10,r10,r0,lsl #1		;-*2
	
	ldrb	r8,[r10,#24]			;finetune
	mov	r2,r8, lsl #7			;*32*4
	add	r2,r2,r8, lsl #4		;+*4*4  = *36*4
	
	addr	r8,periodTable
	add	r8,r8,r2			;finetune offset
	ldr	r8,[r8,r5, lsl #2]		;+index*4

no_period_infos

	;* r3  = sampleX?
	
	;  r5  =  periodenoffset
	;  r6  =  sampleNummer
	;  r7  =  effekt
	;  r8  =  periode oder 0
	;  r9  =  chanel?
	;  r10 =  sampleinfo (wenn r8 nicht 0) 
	;  r11 = modadr
	;  r12 = modplay


	cmp	r6,#0
	beq	sample_is_null

	
	;**** ein Instrument gefunden
	
	str	r6,[r9,#CHANEL_LAST_INSTRUMENT]	;last_instrument = this instrument
	
	sub	r0,r6,#1			;sample 1 -> 0
	add	r10,r11,#20			;sampleinfos
	add	r10,r10,r0, lsl #5		;+*32
	sub	r10,r10,r0, lsl #1		;-*2
	
	ldrb	r1,[r10,#25]			;get sample volume 0..64
	str	r1,[r9,#CHANEL_VOLUME]		;set Volume
	cmp	r5,#0
	strne	r5,[r9,#CHANEL_PERIODE_OFFSET]

sample_is_null	

	
	str	r8,[r9,#CHANEL_PERIODE]		;store Periode
	cmp	r8,#0
	strne	r8,[r9,#CHANEL_LA_PERIODE]
	
	; Effekt detecoding
	
	str	r7,[r9,#CHANEL_EFFEKT]	
	cmp	r7,#0
	blne	decode_effects
	
	;there is a instrument we have to set loops and address

	ldr	r6,[r9,#CHANEL_LAST_INSTRUMENT]	;get instrument
	cmp	r6,#0
	beq	no_instrument
	
	;instrument da -> setze Volume!!!
	
	ldr	r2,[r9,#CHANEL_VOLUME]	;sample volume 
	mov	r2,r2, lsl #3
	str	r2,[r3,#INSTR_VOLUME]	;save volume
	
	ldr	r8,[r9,#CHANEL_PERIODE]	
	cmp	r8,#0			;is there a periode
	beq	no_instrument
	
	;instrument & periode da -> reload data address/loops
	
	addr	r1,modsmpa		;sampleaddrs
	sub	r6,r6,#1
	
	ldr	r1,[r1,r6, lsl #2]	;get sampleaddr
	
	ldrh	r5,[r10,#26]		;loop start
	ldrh	r6,[r10,#28]		;loop end
	
	mov	r5,r5, lsl #12		;2048*2
	add	r6,r5,r6, lsl #12
		
	str	r1,[r3,#INSTR_SAMPLE]	;sample Data
	str	r6,[r3,#INSTR_LOOPEND]	;loop End
	str	r5,[r3,#INSTR_LOOPSTART]	;loop Start 
	
no_instrument	

	ldr	r1,[r9,#CHANEL_PERIODE]	;get Periode
	cmp	r1,#0
	beq	no_pos_reset

	;periode da -> berechne frequenz & reset instrument	
	;(((7093789/2)*2048)/24000)/period
	
	ldr	r0,=302667		;24kHz
	;ldr	r0,=454002		;16kHz
	bl	fdiv			;r1 = (freqstep)samplefrequence
	
	str	r0,[r3,#INSTR_FREQSTEP]		;set new sample Step
	ldr	r0,[r9,#CHANEL_SAMPLE_START]	;load SampleStart (Changed by effekt 9)
	mov	r0,r0, lsl #12			;2048*2
	str	r0,[r3,#INSTR_POS]		;instruction pos = 0
	mov	r0,#0				;start at begin
	str	r0,[r9,#CHANEL_SAMPLE_START]	;set SampleStart = 0

	
no_pos_reset
no_play

	ldmfd	sp!,{r0-r12,lr}
	bx	lr	

;****************************************************************	
;*
;* tick_processing 
;*
;* r9 = chanel1
;* r8 = sampleX1
;*

	.global		effekt_end_t	

tick_processing

	stmfd	sp!,{r0-r12,lr}


	addr	r11,modadr
	ldr	r11,[r11]
	addr	r12,modplayer
	ldr	r7,[r9,#CHANEL_EFFEKT]
	and	r6,r7,#$ff
	mov	r7,r7, lsr #8


	addr	r0,effect_tbl_t
	ldr	r0,[r0,r7, lsl #2]
	mov	lr,pc
	bx	r0

effekt_end_t

	ldmfd	sp!,{r0-r12,lr}
	bx	lr


	@include	sound_mod_effekts.s

;****************************************************************	
;*
;* decode Effekts
;*
;* r3  = sampleX?
;* r4  = ChanelData
;* r9  = chanel?
;* r11 = modadr
;* r12 = modplay

	.global		effekt_end	

decode_effects
	
	stmfd	sp!,{r0-r12,lr}
	
	;**** EFFEKT DETECTION
	
	mov	r4,r7, lsr #8			;Effekt
	and	r7,r7,#$ff			;XY
	
	addr	r0,effect_tbl
	ldr	r0,[r0,r4, lsl #2]
	mov	lr,pc
	bx	r0
	
	
	
effekt_end	
	
	ldmfd	sp!,{r0-r12,lr}
	bx	lr
	
;****************************************************************	
;*
;* decode E-Effekts
;*
;* r3  = sampleX?
;* r4  = ChanelData
;* r9  = chanel?
;* r11 = modadr
;* r12 = modplay	
	
	.global		decode_e_effects	
	
decode_e_effects
	
	;************ EXY EFFEKTS ************
	
	mov	r4,r4, lsl #8
	orr	r4,r4,r7, lsr #8		;EX
	and	r7,r7,#$f		;Y
	
	addr	r0,effect_tbl_e
	ldr	r0,[r0,r4, lsl #2]
	mov	lr,pc
	bx	r0
	b	effekt_end
	
	
	
;*****************************************************************
;*
;* check_mod (läuft im irq)
;*
;*
;*

check_mod
	stmfd	sp!,{lr}	

	
	addr	r12,modplayer
	addr	r11,modadr
	ldr	r11,[r11] 
	
	ldr	r0,[r12,#MOD_TICK]
	ldr	r1,[r12,#MOD_TICK_GO]
		
	cmp	r0,r1			;#MOD_TICK > #MOD_TICK_GO
	moveq	r0,#0			;yes clear tick
	addne	r0,r0,#1		;else add tick
	str	r0,[r12,#MOD_TICK]	;
	bne	no_playtime		;no #MOD_TICK_GO nothing to do
	
	;***************************************************************************

;u	b	u	

	;**** get rows & patterns

	ldr	r1,[r12,#MOD_ROW_POS]
	ldr	r2,[r12,#MOD_PATTERN_POS]
	
	;**** get pattern
	
	add	r10,r11,r2		;+patternpos
	ldrb	r3,[r10,#952]		;patterindexarray
	
	str	r3,[r12,#MOD_AKT_PATTERN]
	
	;****

	add	r10,r11,#$400
	add	r10,r10,#$03c		;mod+1084 = patternarray

	add	r10,r10,r3, lsl #10	;adr = (pattern*1024) + (mod+1084)
	add	r10,r10,r1, lsl #4	;adr = rowpos * 16

	; r3  = sampleX?
	; r4  = ChanelData
	; r9  = chanel1
	; r11 = modadr
	; r12 = modplay

	ldr	r4,[r10]		;Chanel 1
	addr	r9,chanel1
	addr	r3,sampleX1

	bl	decodeAndSet

	ldr	r4,[r10,#4]		;Chanel 2
	addr	r9,chanel2
	addr	r3,sampleX2
	bl	decodeAndSet
	
	ldr	r4,[r10,#8]		;Chanel 3
	addr	r9,chanel3
	addr	r3,sampleX3
	bl	decodeAndSet
	
	ldr	r4,[r10,#12]		;Chanel 4
	addr	r9,chanel4
	addr	r3,sampleX4
	bl	decodeAndSet
	
	
	
	;**** add rows and patterns

	ldrb	r0,[r11,#950]		;songlen
	
	ldr	r1,[r12,#MOD_ROW_POS]
	ldr	r2,[r12,#MOD_PATTERN_POS]
	
	add	r1,r1,#1
	cmp	r1,#64			;if > 64 
	moveq	r1,#0			;ROW=0
	addeq	r2,r2,#1		;PATTERN POS++
	cmp	r2,r0			;if PATTERN POS >= SONGLEN
	movge	r2,#0			;PATTERN POS = 0
	
	str	r1,[r12,#MOD_ROW_POS]
	str	r2,[r12,#MOD_PATTERN_POS]


no_playtime

	addr	r9,chanel1
	addr	r8,sampleX1
	bl	tick_processing

	addr	r9,chanel2
	addr	r8,sampleX2
	bl	tick_processing
	
	addr	r9,chanel3
	addr	r8,sampleX3
	bl	tick_processing
	
	addr	r9,chanel4
	addr	r8,sampleX4
	bl	tick_processing

	ldmfd	sp!,{lr}	
	bx	lr

	

;***************************************************** IRAM

	
		
samplepos	@dcd	0

sampleDB1	@dcd	samplebufferA,samplebufferB
sampleDB2	@dcd	samplebufferC,samplebufferD	
	
	
;****
;* irq_mod
;*
;*	
	
	.global	irq_mod
	
irq_mod	

	stmfd	sp!,{r4-r12,lr}

	mov	r0,#$4000000
	add	r1,r0,#$100
	add	r2,r0,#$200


	;stop dma

	mov	r3,#0
	strh	r3,[r0,#$c6]		;REG_DMA1CNT_H=0; //stop DMA	
	strh	r3,[r0,#$d2]		;REG_DMA2CNT_H=0; //stop DMA	
	
	;switch buffers
	
	addr	r4,sampleDB1		;left
	
	ldmia	r4,{r5,r6}
	str	r6,[r4]
	str	r5,[r4,#4]
	
	addr	r4,sampleDB2		;right
	
	ldmia	r4,{r5,r6}
	str	r6,[r4]
	str	r5,[r4,#4]
	
		
	;reload dma 1 & dma 2
	
	addr	r4,sampleDB1
	addr	r5,sampleDB2
	
	ldr	r3,[r4]			;bufferA-B
	ldr	r4,[r5]			;bufferC-D
	
	str	r3,[r0,#$bc]		;REG_DMA1SAD=(unsigned long)_binary_lo1234_pcm_start; //dma1 source
	str	r4,[r0,#$c8]		;REG_DMA2SAD=(unsigned long)_binary_lo1234_pcm_start; //dma1 source
	
	add	r3,r0,#$a0
	str	r3,[r0,#$c0]		;REG_DMA1DAD=0x040000a0; //write to FIFO A address
	
	add	r3,r0,#$a4
	str	r3,[r0,#$cc]		;REG_DMA2DAD=0x040000a4; //write to FIFO B address
	
	mov	r3,#$b600
	strh	r3,[r0,#$c6]		;REG_DMA1CNT_H=0xb600; //dma control: DMA enabled+ start on FIFO+32bit+repeat+increment source&dest
	strh	r3,[r0,#$d2]		;REG_DMA2CNT_H=0xb600; //dma control: DMA enabled+ start on FIFO+32bit+repeat+increment source&dest
	
	;*

	;copy
	
	mov	r0,#$4000000
	addr	r3,lineL
	ldrh	r4,[r0,#$6]	;VCount
	str	r4,[r3]

	
	mov	r0,#$5000000
	mov	r1,#$f
	;strh	r1,[r0]
	
	addr	r4,sampleDB1
	ldr	r1,[r4,#4]			;buffer
	
	addr	r9,sampleX1
	addr	r10,sampleX2
	
	bl	mix_chanels	

	addr	r4,sampleDB2
	ldr	r1,[r4,#4]			;buffer
	
	addr	r9,sampleX3
	addr	r10,sampleX4
	
	bl	mix_chanels
		
	mov	r0,#$5000000
	mov	r1,#$0
	;strh	r1,[r0]	
		
	;****

	mov	r0,#$4000000
	addr	r3,lineH
	ldrh	r4,[r0,#$6]	;VCount
	str	r4,[r3]
	
	bl	check_mod

		
	ldmfd	sp!,{r4-r12,lr}	
	bx	lr	
	


;*****************************************************************************************************************
;*
;*	WRAM 
;*
;*****************************************************************************************************************


		.section    	.ewram,"ax"
		.align	4



	.global		samplebufferA
	.global		samplebufferB
	.global		samplebufferC
	.global		samplebufferD
	.global		lineL
	.global		lineH
	.global		modadr	
	
modadr		.word		0

lineL		@dcd	0
lineH		@dcd	0	

;*****************************************************************
;*
;* Variablen
;*
;*	
	
		
		.global		modplayer
		.global		modsmpa
		.global		chanel1
		.global		chanel2
		.global		chanel3
		.global		chanel4
		.global		sampleXAll
		.global		sampleX1
		.global		sampleX2
		.global		sampleX3
		.global		sampleX4
		
	
modplayer	@dcd	0	;tick
		@dcd	5	;tick_go
		@dcd	0	;rowpos
		@dcd	0	;patternpos
		@dcd	0	;highest pattern
		@dcd	0	;akt. pattern
		@dcd	0	;samples start
		

modsmpa		.zero	31*4	;@dup	dcd	31,0	
	
chanel1		@dcd	64	;Volume
		@dcd	0	;Periode
		@dcd	0	;Instrument		
		@dcd	0	;SampleStart
		@dcd	0	;SampleFreq
		@dcd	0	;Chanel Effekt
		@dcd	0	;Last Aktive Period
		@dcd	0	;Periodenoffset
chanel2		@dcd	64	;Volume
		@dcd	0	;Periode
		@dcd	0	;Instrument	
		@dcd	0	;SampleStart
		@dcd	0	;SampleFreq
		@dcd	0	;Chanel Effekt
		@dcd	0	;Last Aktive Period
		@dcd	0	;Periodenoffset
chanel3		@dcd	64	;Volume
		@dcd	0	;Periode
		@dcd	0	;Instrument
		@dcd	0	;SampleStart	
		@dcd	0	;SampleFreq
		@dcd	0	;Chanel Effekt
		@dcd	0	;Last Aktive Period
		@dcd	0	;Periodenoffset
chanel4		@dcd	64	;Volume
		@dcd	0	;Periode
		@dcd	0	;Instrument
		@dcd	0	;SampleStart	
		@dcd	0	;SampleFreq
		@dcd	0	;Chanel Effekt
		@dcd	0	;Last Aktive Period
		@dcd	0	;Periodenoffset

sampleXAll	@dcd	$200				;master Volume 


sampleX1	@dcd	sampleNULL			;&data	;r0
		@dcd	(16000*2048)/PLAYBACK_FREQ	;freq step	;r3
		@dcd	0				;pos	;r4
		@dcd	0*2048				;loopend
		@dcd	0*2048				;loopstart
		@dcd	$200				;vol
		@dcd	0*2048				;length

sampleX2	@dcd	sampleNULL				;&data	;r0
		@dcd	(16100*2048)/PLAYBACK_FREQ	;freq step	;r3
		@dcd	0				;pos	;r4
		@dcd	0*2048				;loopend
		@dcd	0*2048				;loopstart
		@dcd	$200				;vol
		@dcd	0*2048				;length

sampleX3	@dcd	sampleNULL 			;&data	;r0
		@dcd	(16200*2048)/PLAYBACK_FREQ	;freq step	;r3
		@dcd	0				;pos	;r4
		@dcd	0*2048				;loopend
		@dcd	0*2048				;loopstart
		@dcd	$200				;vol
		@dcd	0*2048				;length

sampleX4	@dcd	sampleNULL				;&data	;r0
		@dcd	(22050*2048)/PLAYBACK_FREQ	;freq step	;r3
		@dcd	0				;pos	;r4
		@dcd	0*2048				;loopend
		@dcd	0*2048				;loopstart
		@dcd	$200				;vol
		@dcd	0*2048				;length
	
samplebufferA	.zero	SAMPLE_BUFFER_LENGTH
samplebufferB	.zero	SAMPLE_BUFFER_LENGTH		
samplebufferC	.zero	SAMPLE_BUFFER_LENGTH
samplebufferD	.zero	SAMPLE_BUFFER_LENGTH	

		.end