; File trackalm.asm
; generated by the Basic DSP compiler Ver 0.10
; 1999/11/2, 15:54:56.24

; standard program header for the C31 DSK
	.start ".text", 0x809802 ; RAM block 0
	.start ".data", 0x809C00 ; RAM block 1
ten	.set	10	; const ten 10


; start of the data section
	.data
p11pred	.float	0	; var p11pred float
p11est	.float	10	; var p11est float 10
p12pred	.float	0	; var p12pred float
p12est	.float	0	; var p12est float  0
p22pred	.float	0	; var p22pred float
p22est	.float	10	; var p22est float 10
k1	.float	0	; var k1      float
k2	.float	0	; var k2     float
quarterqr	.float	0	; var quarterqr float
error	.float	0	; var error  float
finvsrda	.float	0,0	; var finvsrda  float 0,0
finvmask	.word	0xff7fffff	; var finvmask  int   0xff7fffff
setsp	.word	0e970300h	; var setsp     int   0e970300h
aicsetsrda	.word	1,5,0x1f,0x99	; var aicsetsrda int  1,5,0x1f,0x99
twaitsrda	.word	0	; var twaitsrda int   0
aiciosrda	.word	0,0	; var aiciosrda int   0,0

; start of the data address section
_pbase	.word	0x808000 ; memory mapped registers
_p11pred	.word	p11pred	; address of p11pred
_p11est	.word	p11est	; address of p11est
_p12pred	.word	p12pred	; address of p12pred
_p12est	.word	p12est	; address of p12est
_p22pred	.word	p22pred	; address of p22pred
_p22est	.word	p22est	; address of p22est
_k1	.word	k1	; address of k1
_k2	.word	k2	; address of k2
_quarterqr	.word	quarterqr	; address of quarterqr
_error	.word	error	; address of error
_finvsrda	.word	finvsrda	; address of finvsrda
_finvmask	.word	finvmask	; address of finvmask
_setsp	.word	setsp	; address of setsp
_aicsetsrda	.word	aicsetsrda	; address of aicsetsrda
_twaitsrda	.word	twaitsrda	; address of twaitsrda
_aiciosrda	.word	aiciosrda	; address of aiciosrda

_stack	.word stack	; address of stack
stack	.word $		; beginning of the stack
; end of the data section

; start of the program section
	.entry BEGIN
	.text
BEGIN	ldp	@.data     ; init the data page
	ldi	@stack, sp ; init the stack pointer
initinterrupt	; :initinterrupt
	push	ar0	; gosub aicset
	ldi	@_aicsetsrda, ar0
	call	aicset
	pop	ar0

mainloop	; :mainloop
	ldf	R6, R0	; x1+=x2
	addf3	R0, R5, R0
	ldf	R0, R5

	ldi	@_p11est, AR1	; p11pred=p11est+p22est
	ldf	*AR1, R0
	ldi	@_p22est, AR1
	ldf	*AR1, R1
	addf3	R1, R0, R0
	ldi	@_p11pred, AR1
	stf	R0, *AR1

	ldi	@_p12est, AR1	; p11pred+=p12est+p12est
	ldf	*AR1, R0
	ldf	*AR1, R1
	addf3	R1, R0, R0
	ldi	@_p11pred, AR1
	addf3	R0, *AR1, R0
	stf	R0, *AR1

	ldi	@_quarterqr, AR1	; x0=quarterqr
	ldf	*AR1, R0
	ldf	R0, R4

	ldf	R4, R0	; p11pred+=x0
	ldi	@_p11pred, AR1
	addf3	R0, *AR1, R0
	stf	R0, *AR1

	ldf	2, R0	; x0*=2
	mpyf3	R0, R4, R4

	ldi	@_p12est, AR1	; p12pred=p12est+p22est
	ldf	*AR1, R0
	ldi	@_p22est, AR1
	ldf	*AR1, R1
	addf3	R1, R0, R0
	ldi	@_p12pred, AR1
	stf	R0, *AR1

	ldf	R4, R0	; p12pred+=x0
	ldi	@_p12pred, AR1
	addf3	R0, *AR1, R0
	stf	R0, *AR1

	ldf	2, R0	; x0*=2
	mpyf3	R0, R4, R4

	ldi	@_p22est, AR1	; p22pred=p22est+x0
	ldf	*AR1, R0
	ldf	R4, R1
	addf3	R1, R0, R0
	ldi	@_p22pred, AR1
	stf	R0, *AR1

	ldi	@_finvsrda, AR1	; finvsrda(0)=1
	ldf	1, R0
	stf	R0, *AR1

	ldi	@_p11pred, AR1	; finvsrda(0)+=p11pred
	ldf	*AR1, R0
	ldi	@_finvsrda, AR1
	addf3	R0, *AR1, R0
	stf	R0, *AR1

	push	ar0	; gosub finv
	ldi	@_finvsrda, ar0
	call	finv
	pop	ar0

	ldi	@_finvsrda, AR1	; x0=finvsrda(1)
	ldi	1, IR0
	ldf	*+AR1(IR0), R0
	ldf	R0, R4

	ldi	@_p11pred, AR1	; k1=p11pred*x0
	ldf	*AR1, R0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	ldi	@_k1, AR1
	stf	R0, *AR1

	ldi	@_p12pred, AR1	; k2=p12pred*x0
	ldf	*AR1, R0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	ldi	@_k2, AR1
	stf	R0, *AR1

	idle	; idle

	ldi	@_aiciosrda, AR1	; error=aiciosrda(1)-x0
	ldi	1, IR0
	ldi	*+AR1(IR0), R0
	ldf	R4, R1
	float	R0, R0
	subf3	R1, R0, R0
	ldi	@_error, AR1
	stf	R0, *AR1

	ldi	@_k1, AR1	; x1+=k1*error
	ldf	*AR1, R0
	ldi	@_error, AR1
	ldf	*AR1, R1
	mpyf3	R1, R0, R0
	addf3	R0, R5, R0
	ldf	R0, R5

	ldi	@_k2, AR1	; x2+=k2*error
	ldf	*AR1, R0
	ldi	@_error, AR1
	ldf	*AR1, R1
	mpyf3	R1, R0, R0
	addf3	R0, R6, R0
	ldf	R0, R6

	ldi	@_p12pred, AR1	; x3=p12pred
	ldf	*AR1, R0
	ldf	R0, R7

	ldf	R7, R0	; x3*=x3*x0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	mpyf3	R0, R7, R0
	ldf	R0, R7

	ldi	@_p22pred, AR1	; p22est=p22pred-x3
	ldf	*AR1, R0
	ldf	R7, R1
	subf3	R1, R0, R0
	ldi	@_p22est, AR1
	stf	R0, *AR1

	ldi	@_p12pred, AR1	; p12est=p12pred*x0
	ldf	*AR1, R0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	ldi	@_p12est, AR1
	stf	R0, *AR1

	ldi	@_p11pred, AR1	; p11est=p11pred*x0
	ldf	*AR1, R0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	ldi	@_p11est, AR1
	stf	R0, *AR1

	br	mainloop	; goto mainloop


; this program uses the xint0 interruption
	.start "xint0sect", 0x809FC5
	.sect  "xint0sect"
	br xint0

	.text
xint0	; :xint0
	ldf	R4, R0	; aiciosrda(0)=x0
	fix	R0, R0
	ldi	@_aiciosrda, AR1
	sti	R0, *AR1

	push	ar0	; gosub aicio
	ldi	@_aiciosrda, ar0
	call	aicio
	pop	ar0

	reti	; reti

finv	; :finv
	ldf     *+ar0(0),r0
	cmpf    0.0,r0
	beq	finv3
	ldf     r0,r1
	pushf   r1
	pop     r1
	xor     @finvmask,r1
	push    r1
	popf    r1
	ldi     5,rc
	rptb    finv2
	mpyf3   r1,r0,r2
	subrf   2.0,r2
finv2	; :finv2
	mpyf    r2,r1
	ldf     r1,r0
	stf     r0,*+ar0(1)
	rets	; return

finv3	; :finv3
	ldf	0.0, r0
	stf     r0,*+ar0(1)
	rets	; return

aicset	; :aicset
	ldi     ar0,ar2
	ldi     @_pbase,ar1
	ldi     *ar2++,r0
	sti     r0,*+ar1(28h)
	ldi     03c1h,r0
	sti     r0,*+ar1(20h)
	ldi     02h,iof
	rpts    99
	nop
	ldi     131h,r0
	sti     r0,*+ar1(42h)
	sti     r0,*+ar1(43h)
	ldi     @setsp,r0
	sti     r0,*+ar1(40h)
	ldi     0,r0
	sti     r0,*+ar1(48h)
	or      06h,iof
	ldi     1,rc
	rptb    aicset2
	call    twait
	ldi     03h,r0
	sti     r0,*+ar1(48h)
	call    twait
	ldi     *ar2,r0
	lsh     7,r0
	or      *ar2++,r0
	lsh     2,r0
	cmpi    1,rc
	bz      aicset2
	or      2,r0
aicset2	; :aicset2
	sti     r0,*+ar1(48h)
	ldi     *ar2,r0
	call    twait
	ldi     03h,r1
	sti     r1,*+ar1(48h)
	call    twait
	ldi     r0,r1
	andn    0x80,r0
	lsh     2,r0
	or      3,r0
	sti     r0,*+ar1(48h)
	tstb    0x80,r1
	callnz  aicset_i
	rets	; return

aicset_i	; :aicset_i
	ldi     0h,if
	or      10h,ie
	or      2000h,st
	rets	; return

twait	; :twait
	ldi     *+ar1(40h),r1
	and     02h,r1
	bz      twait
	rets	; return

aicio	; :aicio
	ldi     *+ar0(0),r6
	lsh     2,r6
	ldi     @_pbase,ar1
	sti     r6,*+ar1(48h)
	ldi     *+ar1(4ch),r6
	lsh     16,r6
	ash     -18,r6
	sti     r6,*+ar0(1)
	rets	; return


; end of the program section
	.end
