;ax = r7
;ay = r8
;bx = r9
;by = r10
;cx = r11
;cy = r12	
;count = r2

	.set		fract		,4096
	.set		fractn		,12

	.global		spline3p_init
	.type		spline3p_init,function
	.global		spline3p_calc
	.type		spline3p_calc,function


spline3p_init

	;Interpoliere (bei 3Punkten Mittelpunkt (B) neu berrechnen (aus A & C) )
	;-> bx = (4*bx-ax-cx)/2
	;   by = (4*by-ay-cy)/2
	
	rsb	r9,r7,r9, lsl #2	;4*bx-ax
	sub	r9,r9,r11	;-cx
	mov	r9,r9, asr #1	;/2
	
	rsb	r10,r8,r10, lsl #2
	sub	r10,r10,r12
	mov	r10,r10, asr #1

	bx	lr

	;cqw = count²
	;b1 = cqw Sar frn
	;b2 = (count - (b1)) Shl 1 
	;b3 =  (fr) - ((count Shl 1)) + (b1)

spline3p_calc

	mul	r6,r2,r2
	
	mov	r4,r6, asr #fractn		;b1
	
	sub	r5,r2,r4
	add	r5,r5,r5			;b2
	
	mov	r6,#fract
	sub	r6,r6,r2, lsl #1
	add	r6,r6,r4			;b3
	
	;xf = ((ax * b1)  + (bx * b2)  + (cx * b3))Sar frn  
		
	mul	r0,r7,r4
	mla	r0,r9,r5,r0
	mla	r0,r11,r6,r0
		
	mov	r0,r0, asr #fractn
	
	;yf = ((ay * b1) + (by * b2) + (cy * b3))Sar frn
	
	mul	r1,r8,r4
	mla	r1,r10,r5,r1
	mla	r1,r12,r6,r1
		
	mov	r1,r1, asr #fractn
	
	bx 	lr
	
	.end