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

	.section    	.iwram,"ax"
	.arm
	.align		4
	
@**: change Sampleoffset

@effekt_sample_offset:

@:	mov	r7,r7 lsl 9			@sampleoffset = effektparam * 0x100
@:	str	r7,[r9,#CHANEL_SAMPLE_START]
@:	bx	lr
	
@**: Volume Slide	
		
	.global		effekt_volumeslide				
			
effekt_volumeslide:
	
	and	r0,r7,#0x0f			@r0 = y
	mov	r1,r7, lsr #8			@r1 = x
	ldr	r2,[r12,#MOD_TICK_GO]		@r2 = Speed
	sub	r2,r2,#1			@Speed-1
	
	ldr	r4,[r9,#CHANEL_VOLUME]		@get Volume	
	mla	r4,r1,r2,r4			@Volume=Volume + x * Speed
	rsb	r0,r0,#0			@-y
	mla	r4,r0,r2,r4			@Volume=Volume - y * Speed
	
	cmp	r4,#64
	movgt	r4,#64
	cmp	r4,#0
	movlt	r4,#0
	
	str	r4,[r9,#CHANEL_VOLUME]		@set Volume	
	bx	lr
	
@**: Postion Jump
	
	.global		effekt_position_jump	
	
effekt_position_jump:
	
	mvn	r2,#0		@rowpos 	= -1
	mov	r1,r7		@patternpos 	= xy
	
	str	r2,[r12,#MOD_ROW_POS]
	
	ldrb	r0,[r11,#950]		@songlen
	
	cmp	r1,r0			@if PATTERN POS >= SONGLEN
	movge	r1,#0			@PATTERN POS = 0
	
	str	r1,[r12,#MOD_PATTERN_POS]	
	
	bx	lr
	

@**: Volume Set 

	.global		effekt_setvolume

effekt_setvolume:

	cmp	r7,#64
	movgt	r7,#64
	cmp	r7,#0
	movlt	r7,#0
	str	r7,[r9,#CHANEL_VOLUME]		@sample Volume	
	bx	lr
	
@**: Pattern Break

	.global		effekt_patternbreak

effekt_patternbreak:
	and	r0,r7,#0x0f			@r0 = y
	mov	r1,r7, lsr #8			@r1 = x
	
	mov	r2,r1, lsl #3			@*8
	add	r2,r2,r1, lsl #1			@*8 = *10
	
	add	r2,r2,r0			@rowpos = x*10+y
	sub	r2,r2,#1			@		-1
	
	ldrb	r0,[r11,#950]		@songlen
	
	ldr	r1,[r12,#MOD_PATTERN_POS]
	
	add	r1,r1,#1		@pattern++
	
	cmp	r2,#64			@if > 64 
	moveq	r2,#0			@ROW=0
	addeq	r1,r1,#1		@PATTERN POS++
	cmp	r1,r0			@if PATTERN POS >= SONGLEN
	movge	r1,#0			@PATTERN POS = 0
	
	str	r2,[r12,#MOD_ROW_POS]
	str	r1,[r12,#MOD_PATTERN_POS]
	
	bx	lr	

@**: Speed	
	
@effekt_speed:

@:	cmp	r7,#20				@<20 Speed >20-ff tempo
@:	sublt	r7,r7,#1
@:	strlt	r7,[r12,#MOD_TICK_GO]		@Speed
	
@:	bx	lr		
	
	
@*******************************************************: E - EFFEKTS

@**: Fine Volume Slide Up
			
e_effekt_finevolumeslideup:
	
	.global		e_effekt_finevolumeslideup
	
	ldr	r0,[r9,#CHANEL_VOLUME]
	add	r0,r0,r7
	cmp	r0,#64
	movgt	r0,#64
	str	r0,[r9,#CHANEL_VOLUME]
	bx	lr
	
	@** Fine Volume Slide Down
			
	.global		e_effekt_finevolumeslidedown
			
e_effekt_finevolumeslidedown:
	
	ldr	r0,[r9,#CHANEL_VOLUME]
	subs	r0,r0,r7
	movmi	r0,#0
	str	r0,[r9,#CHANEL_VOLUME]
	bx	lr

@**: Fine Porta Up
		
	.global		e_effekt_fineportaup		
			
e_effekt_fineportaup:
	
	ldr	r0,[r9,#CHANEL_PERIODE]
	add	r0,r0,r7
	str	r0,[r9,#CHANEL_PERIODE]
	bx	lr
	
@**: Fine Porta Down
		
	.global		e_effekt_fineportadown	
		
e_effekt_fineportadown:
	
	ldr	r0,[r9,#CHANEL_PERIODE]
	sub	r0,r0,r7
	str	r0,[r9,#CHANEL_PERIODE]
	bx	lr
	
@**: Set Fine Tune	
	
	.global		e_effekt_setfinetune	
	
e_effekt_setfinetune:
	

	ldr	r0,[r9,#CHANEL_LAST_INSTRUMENT]
	cmp	r0,#0
	bxeq	lr
	
	sub	r0,r0,#1
	add	r1,r11,#20		@sampleinfos=modadr+20+30*samplenumber
	add	r1,r1,r0, lsl #5		@+*32
	sub	r1,r1,r0, lsl #1		@-*2
	
	strb	r7,[r1,#24]		@set finetune	
	bx	lr
	
	
@********************************************************: tick effekt

@**: Set Portadown

	.global		t_effekt_portadown	

t_effekt_portadown:

	mov	r4,lr

	ldr	r0,[r9,#CHANEL_LA_PERIODE]
	add	r1,r0,r6
	str	r1,[r9,#CHANEL_LA_PERIODE]
	
	ldr	r0,=302667		
	bl	fdiv			
	str	r0,[r8,#INSTR_FREQSTEP]	
	
	bx	r4	

@**: Set Portaup
	
	.global		t_effekt_portaup	
	
t_effekt_portaup:

	mov	r4,lr	
	
	ldr	r0,[r9,#CHANEL_LA_PERIODE]
	sub	r1,r0,r6				@Periode - XY
	str	r1,[r9,#CHANEL_LA_PERIODE]
	
	ldr	r0,=302667		@24kHz
	bl	fdiv			@r1 = (freqstep)samplefrequence
	str	r0,[r8,#INSTR_FREQSTEP]		@set new sample Step
	
	bx	r4
	
@**: Set Arpeggio

	.global		t_arpeggio	
	
t_arpeggio:

	mov	r4,lr	

	@r7 = f00
	@r6 = 0xy
	
	cmp	r6,#0
	bxeq	lr			@000 is no effekt
	
	ldr	r0,[r12,#MOD_TICK]	@get tickpos
	and	r0,r0,#0x3		@012
	
	ldr	r5,[r9,#CHANEL_PERIODE_OFFSET]
	

	mov	r8,#0		@+ 0 	finetunes
	
	cmp	r0,#1		@+ x 	finetunes
	moveq	r8,r6 
	
	cmp	r0,#2		@- y 	finetunes
	rsbeq	r8,r6,#0
	
	mov	r1,r8, lsl #7		@*32*4
	add	r1,r1,r8, lsl #4	@+*4*4  = *36*4
	
	ldr r8,=periodTable
	add	r8,r8,r1		@finetune offset
	ldr	r1,[r8,r5, lsl #2]	@+index*4
	
	ldr	r0,=302667		@24kHz
	bl	fdiv			@r1 = (freqstep)samplefrequence
	str	r0,[r3,#INSTR_FREQSTEP]		@set new sample Step
	
	bx	r4
	
	
	.end
	
				