
pctl  equ $fffd
bcr equ $fffe ; BCR Register
ogdbr equ $fffc ; OnCE GDB Register
ecsr equ $ffeb ; EMI Control/Status Register
edrr0 equ $ffea ; EMI Data Read Register
ebar0 equ $ffe8 ; EMI Base Address Register 0
eor0 equ $ffe9 ; EMI Offset Register
edrf equ 13 ; EMI EDRR Full flag
hrne equ 17 ; SHI FIFO Not Empty flag
hrx equ $fff3 ; SHI HRX FIFO
hcsr equ $fff1 ; SHI Control/Status Register
hi2c equ 1 ; SHI IIC Enable Control Bit
ma equ 0 ; OMR Mode A
mb equ 1 ; OMR Mode B
mc equ 4 ; OMR Mode C
gpior equ $fff7 ; GPIO Control/Data Register
gdd3 equ 9 ; direction bit for GPIO3
gd3 equ 1 ; data bit for GPIO3
rcs equ $ffe1  ;SAI receiver control / status register
tcs equ $ffe4  ;SAI transmitter conntrol /status register
brc equ $ffe0  ;baud rate control register
rx0 equ $ffe2  ;SAI receive data register
rx1 equ $ffe3  ;SAI receive data register
tx0 equ $ffe5  ;SAI transmit data register
tx1 equ $ffe6  ;SAI transmit data register
tx2 equ $ffe7  ;SAI transmit data register
ipr equ $ffff  ;interrupt priority register
rldf equ 14
rrdf equ 15

buf_delta_i equ  $50
buf_delta_f equ  $51
buf_sin_x_i equ  $52
buf_sin_x_f equ  $53
buf_cos_x_i equ  $54
buf_cos_x_f equ  $55


;start equ $60                    ;program starting address
sinep equ $100                   ;sine table starting address
cosinep equ $139
mask equ $0ff                     ;base address plus N minus one
delta equ 1.05                    ;delta = 2.5




N equ 8


  org p:$0
  jmp start1




start1:


    movep #$260023,x:pctl    ; uaktywnij PLL i ustaw 50MHz
    movep #$000201,x:rcs     ;uaktywnij SAI

    movep #$000203,x:tcs     ;uaktywnij SAI




 move #(delta-@cvi(delta)),b0 ;store fraction part in b0
 asl b #sinep,r6                ;eliminate sign bit, initialize r1
 move b0,y:buf_delta_f                     ;unsigned fractional Delta in y0

 move #>@cvi(delta),b0
 move b0,y:buf_delta_i        ;integer part of Delta in y0


 clr a  #0,n6                    ;initialize a and n1
 move #mask,m7
 move m7,m6 ;set up mask value
 move #0,n7                     ;initialize n2
 move #sinep+1,r7              ;initialize r2 with the value r1+ 1


 clr a  #0,n2                    ;initialize a and n1
 move #mask,m3
 move m3,m2 ;set up mask value                                     petla:
 move #0,n3                     ;initialize n2                         nop
 move #cosinep+1,r3              ;initialize r2 with the value r1+ 1     jset #rldf,x:rcs,odbierz_lewy
 move #cosinep,r2

 move a1,y:buf_sin_x_i
 move a0,y:buf_sin_x_f
 move a1,y:buf_cos_x_i
 move a0,y:buf_cos_x_f



petla:



    nop
    jset #rldf,x:rcs,odbierz_lewy


    nop
    jset #rrdf,x:rcs,odbierz_prawy

    nop
    jmp petla



odbierz_lewy:

    move x:rx0,x0


    ; clr a
 move y:buf_sin_x_i,a1
 move y:buf_sin_x_f,a0
     clr b
 move a0,b1   ;fraction part of ptr in b1, b0= 0 (1)
 lsr b   y:(r6+n6),x0           ;b1= signed fr. Delta, x0= sine (2)
 move b1,x:tx1
 move b,x1 y:(r7+n7),b             ;sign. fract. in x1, sine in b1 (2)
 sub x0,b                      ;subtr sines to obtain slope (1)
 move b,x0   y:(r6+n6),b       ;slope value to x0, sine in b1 (2)
 macr x0,x1,b                  ;sample approximation = m* x+ b (1)
 move y:buf_delta_i,y1
 move y:buf_delta_f,y0
 add y,a                    ;
 move b,x:tx0               ;update calculation, output sample (1)
 move m7,x1                     ;set up mask value in x1 (1)
 and x1,a                       ;mask a1 = modulo arithmetic (1)

 move a1,n6                     ;update offset register n1 (1)
 move a1,n7                     ;update offset register n2 (1)                                 ;return from the subroutine (1)
 move a1,y:buf_sin_x_i
 move a0,y:buf_sin_x_f









    jmp petla


odbierz_prawy:

    move x:rx0,x0

     clr a
 move y:buf_cos_x_i,a1
 move y:buf_cos_x_f,a0
     clr b
 move a0,b1   ;fraction part of ptr in b1, b0= 0 (1)
  lsr b   y:(r2+n2),x0           ;b1= signed fr. Delta, x0= sine (2)
 move b1,x:tx1
 move b,x1 y:(r3+n3),b             ;sign. fract. in x1, sine in b1 (2)
 sub x0,b                      ;subtr sines to obtain slope (1)
 move b,x0   y:(r2+n2),b       ;slope value to x0, sine in b1 (2)
 macr x0,x1,b                  ;sample approximation = m* x+ b (1)
 move y:buf_delta_i,y1
 move y:buf_delta_f,y0
 add y,a                    ;
 move b,x:tx0               ;update calculation, output sample (1)
 move m3,x1                     ;set up mask value in x1 (1)
 and x1,a                       ;mask a1 = modulo arithmetic (1)

 move a1,n2                     ;update offset register n1 (1)
 move a1,n3                     ;update offset register n2 (1)                                 ;return from the subroutine (1)
 move a1,y:buf_cos_x_i
 move a0,y:buf_cos_x_f











   jmp petla



