?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xsin
  2.  define included_xsin
  3.  include "../common/pushpop.asm"
  4.  include "constantsx.asm"
  5.  include "xmul.asm"
  6.  include "xadd.asm"
  7.  include "xrsub.asm"
  8.  include "xmod1.asm"
  9.  include "xcos.asm"
  10.  
  11. sin_x=xOP1+60
  12. sin_y=xOP1+70
  13. temp=xOP1+80
  14.  
  15. xsin:
  16. ;sine(-pi/4<=x<pi/4)
  17. ;y=x*x
  18. ;a1=2^-3 * 11184804/2^23
  19. ;a2=2^-7 * 8946604/2^23
  20. ;a3=2^-13 * 13408017/2^23
  21. ;x(1-y(a1-y(a2-y*a3)))
  22. ;
  23.   call pushpop
  24.   push bc
  25. ;Need to apply range reduction
  26. ; We want the input on [-pi/4,pi/4]
  27. ; First multiply by 1/(2pi)
  28.   ld de,xconst_2pi_inv
  29.   ld bc,sin_x
  30.   call xmul
  31.  
  32. ;Now add .25
  33.   ld h,b
  34.   ld l,c
  35.   ld de,xconst_p25
  36.   call xadd
  37.  
  38. ;Now grab the xmod1
  39.   call xmod1
  40.  
  41. ;Let's convert this to a cosine problem
  42.   ld de,xconst_p5
  43.   call xrsub
  44.   jp xcos_stepin
  45.  
  46. xsin_subroutine:
  47. ;Multiply by 2pi
  48.   ld de,xconst_2pi
  49.   ld b,h
  50.   ld c,l
  51.   call xmul
  52.  
  53.   ld d,h
  54.   ld e,l
  55.   ld bc,sin_y
  56.   call xmul
  57.   ld h,b
  58.   ld l,c
  59.   ld de,xsin_p7
  60.   ld bc,temp
  61.   call xmul
  62.   ld hl,xsin_p6
  63.   ld d,b
  64.   ld e,c
  65.   call xadd
  66.   ld hl,sin_y
  67.   call xmul
  68.   ld hl,xsin_p5
  69.   call xadd
  70.   ld hl,sin_y
  71.   call xmul
  72.  
  73.   ld hl,xsin_p4
  74.   call xadd
  75.   ld hl,sin_y
  76.   call xmul
  77.  
  78.   ld hl,xsin_p3
  79.   call xadd
  80.   ld hl,sin_y
  81.   call xmul
  82.  
  83.   ld hl,xsin_p2
  84.   call xadd
  85.   ld hl,sin_y
  86.   call xmul
  87.  
  88.   ld hl,xsin_p1
  89.   call xadd
  90.   ld hl,sin_y
  91.   call xmul
  92.  
  93.  
  94.   ld hl,xsin_p0
  95.   call xadd
  96.   ld hl,sin_x
  97.   pop bc
  98.   jp xmul
  99.  
  100. xsin_p0:
  101.  db $00,$00,$00,$00,$00,$00,$00,$80,$00,$40    ;0.9999999999999999999981204044115315796
  102. xsin_p1:
  103.  db $8E,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$FD,$BF    ;-0.1666666666666666662812878964544520249
  104. xsin_p2:
  105.  db $96,$4C,$88,$88,$88,$88,$88,$88,$F9,$3F    ;.00833333333333332033458286248185347141
  106. xsin_p3:
  107.  db $37,$DF,$3F,$0C,$D0,$00,$0D,$D0,$F3,$BF    ;-.0001984126984125310632612418861238238148
  108. xsin_p4:
  109.  db $12,$C0,$D4,$84,$29,$1D,$EF,$B8,$ED,$3F    ;.000002755731921339040823259154579822644652
  110. xsin_p5:
  111.  db $B9,$1F,$70,$0F,$32,$29,$32,$D7,$E6,$BF    ;-.00000002505210473832886631551463640646870413
  112. xsin_p6:
  113.  db $80,$CC,$9B,$F1,$F1,$3A,$90,$B0,$DF,$3F    ;.0000000001605834763092742825428205943594730752
  114. xsin_p7:
  115.  db $D3,$82,$8D,$7D,$A3,$4B,$4C,$D5,$D7,$BF    ;-.000000000000757786825836494841305422527105351555
  116.  
  117. ;#undefine sin_x
  118. ;#undefine sin_y
  119. ;#undefine temp
  120.  endif
  121.