home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 364b.lha / PCQ_v1.1 / Runtime / PCQ / Trig.asm < prev   
Encoding:
Assembly Source File  |  1990-04-08  |  10.3 KB  |  339 lines

  1. *
  2. *
  3. *
  4.  
  5.     XREF    _p%MathBase
  6.     XREF    _LVOSPCmp
  7.     XREF    _LVOSPFloor
  8.     XREF    _LVOSPDiv
  9.     XREF    _LVOSPMul
  10.     XREF    _LVOSPSub
  11.     XREF    _LVOSPNeg
  12.     XREF    _LVOSPAdd
  13.  
  14.         XDEF    _p%sin
  15. _p%sin
  16.         move.l  4(sp),d0          ;x to d0
  17.         move.l  _p%MathBase,a6
  18.         move.l  d7,-(sp)
  19.         move.l  d0,d7
  20.         move.l  #$C90FD943,d1     ;twopi
  21.         jsr    _LVOSPCmp(a6)        ;cmp
  22.         bge.s   sin_toobig
  23.         move.l  d7,d0
  24.         move.l  #$0,d1            ;d1 holds 0
  25.         jsr     _LVOSPCmp(a6)           ;cmp
  26.         bge.s   sin_around
  27. sin_toobig
  28.         move.l  d7,d0
  29.         move.l  #$C90FD943,d1     ;twopi
  30.         jsr     _LVOSPDiv(a6)           ;div
  31.         jsr     _LVOSPFloor(a6)           ;floor
  32.         move.l  #$C90FD943,d1     ;twopi
  33.         jsr     _LVOSPMul(a6)           ;mul
  34.         move.l  d7,d1
  35.         exg     d0,d1
  36.         jsr     _LVOSPSub(a6)           ;sub
  37.         move.l  d0,d7
  38. sin_around
  39.         move.l  d7,d0
  40.         move.l  #$C90FD941,d1     ;halfpi
  41.         jsr     _LVOSPCmp(a6)           ;cmp
  42.         bgt.s   sin_TwoQuad
  43.         bsr.s     GetSin
  44.         bra.s   sin_out
  45. sin_TwoQuad
  46.         move.l  d7,d0
  47.         move.l  #$C90FD942,d1     ;pi
  48.         jsr     _LVOSPCmp(a6)           ;cmp
  49.         bgt.s   sin_ThreeQuad
  50.         move.l  #$C90FD942,d0     ;pi
  51.         move.l  d7,d1
  52.         jsr     _LVOSPSub(a6)           ;sub
  53.         move.l  d0,d7
  54.         bsr.s   GetSin
  55.         bra.s   sin_out
  56. sin_ThreeQuad
  57.         move.l  d7,d0
  58.         move.l  #$96CBE343,d1     ;threehalvespi
  59.         jsr     _LVOSPCmp(a6)           ;cmp
  60.         bgt.s   sin_FourQuad
  61.         move.l  d7,d0
  62.         move.l  #$C90FD942,d1     ;twopi
  63.         jsr     _LVOSPSub(a6)           ;sub
  64.         move.l  d0,d7
  65.         bsr.s   GetSin
  66.         jsr     _LVOSPNeg(a6)           ;neg
  67.         bra.s   sin_out
  68. sin_FourQuad
  69.         move.l  #$C90FD943,d0     ;twopi
  70.         move.l  d7,d1
  71.         jsr     _LVOSPSub(a6)           ;sub
  72.         move.l  d0,d7
  73.         bsr.s   GetSin
  74.         jsr     _LVOSPNeg(a6)           ;neg
  75. sin_out     move.l  (sp)+,d7
  76.         rts
  77.  
  78.  
  79. GetSin                            ;a4x^4+a3x^3+a2x^2+a1x+a0
  80.         move.l  d7,d0             ;d7 holds x
  81.         move.l  #$E8626F3B,d1     ;a4
  82.         jsr     _LVOSPMul(a6)           ;mul
  83.         move.l  #$CFD12F3E,d1     ;a3
  84.         jsr     _LVOSPSub(a6)           ;sub   a3 is negative
  85.         move.l  d7,d1
  86.         jsr     _LVOSPMul(a6)           ;mul
  87.         move.l  #$A350863B,d1     ;a2
  88.         jsr     _LVOSPAdd(a6)           ;add
  89.         move.l  d7,d1
  90.         jsr     _LVOSPMul(a6)           ;mul
  91.         move.l  #$FEEF6E40,d1     ;a1
  92.         jsr     _LVOSPAdd(a6)           ;add
  93.         move.l  d7,d1
  94.         jsr     _LVOSPMul(a6)           ;mul
  95.         move.l  #$CB805734,d1     ;a0
  96.         jsr     _LVOSPAdd(a6)           ;add
  97.         rts
  98.  
  99.         XDEF    _p%cos
  100. _p%cos
  101.         move.l  4(sp),d0          ;x to d0
  102.         move.l  _p%MathBase,a6
  103.         move.l  d7,-(sp)
  104.         move.l  d0,d7
  105.         move.l  #$C90FD943,d1     ;twopi
  106.         jsr     _LVOSPCmp(a6)           ;cmp
  107.         bge.s   cos_toobig
  108.         move.l  d7,d0
  109.         move.l  #$0,d1            ;d1 holds 0
  110.         jsr     _LVOSPCmp(a6)           ;cmp
  111.         bge.s   cos_around
  112. cos_toobig
  113.         move.l  d7,d0
  114.         move.l  #$C90FD943,d1     ;twopi
  115.         jsr     _LVOSPDiv(a6)           ;div
  116.         jsr     _LVOSPFloor(a6)           ;floor
  117.         move.l  #$C90FD943,d1     ;twopi
  118.         jsr     _LVOSPMul(a6)           ;mul
  119.         move.l  d7,d1
  120.         exg     d0,d1
  121.         jsr     _LVOSPSub(a6)           ;sub
  122.         move.l  d0,d7
  123. cos_around
  124.         move.l  d7,d0
  125.         move.l  #$C90FD941,d1     ;halfpi
  126.         jsr     _LVOSPCmp(a6)           ;cmp
  127.         bgt.s   cos_TwoQuad
  128.         bsr.s   GetCos
  129.         bra.s   cos_out
  130. cos_TwoQuad
  131.         move.l  d7,d0
  132.         move.l  #$C90FD942,d1     ;pi
  133.         jsr     _LVOSPCmp(a6)           ;cmp
  134.         bgt.s   cos_ThreeQuad
  135.         move.l  #$C90FD942,d0     ;pi
  136.         move.l  d7,d1
  137.         jsr     _LVOSPSub(a6)           ;sub
  138.         move.l  d0,d7
  139.         bsr.s   GetCos
  140.         jsr     _LVOSPNeg(a6)           ;neg
  141.         bra.s   cos_out
  142. cos_ThreeQuad
  143.         move.l  d7,d0
  144.         move.l  #$96CBE343,d1     ;threehalvespi
  145.         jsr     _LVOSPCmp(a6)           ;cmp
  146.         bgt.s   cos_FourQuad
  147.         move.l  d7,d0
  148.         move.l  #$C90FD942,d1     ;pi
  149.         jsr     _LVOSPSub(a6)           ;sub
  150.         move.l  d0,d7
  151.         bsr.s   GetCos
  152.         jsr     _LVOSPNeg(a6)           ;neg
  153.         bra.s   cos_out
  154. cos_FourQuad
  155.         move.l  #$C90FD943,d0     ;twopi
  156.         move.l  d7,d1
  157.         jsr     _LVOSPSub(a6)           ;sub
  158.         move.l  d0,d7
  159.         bsr.s   GetCos
  160. cos_out     move.l  (sp)+,d7
  161.         rts
  162.  
  163.  
  164. GetCos                            ;a4x^4+a3x^3+a2x^2+a1x+a0
  165.         move.l  d7,d0             ;d7 holds x
  166.         move.l  #$F570BF3B,d1     ;a4
  167.         jsr     _LVOSPMul(a6)           ;mul
  168.         move.l  #$A1650A3B,d1     ;a3
  169.         jsr     _LVOSPAdd(a6)           ;add
  170.         move.l  d7,d1
  171.         jsr     _LVOSPMul(a6)           ;mul
  172.         move.l  #$82E90140,d1     ;a2
  173.         jsr     _LVOSPSub(a6)           ;sub   a2 is negative
  174.         move.l  d7,d1
  175.         jsr     _LVOSPMul(a6)           ;mul
  176.         move.l  #$8E477E38,d1     ;a1
  177.         jsr     _LVOSPAdd(a6)           ;add
  178.         move.l  d7,d1
  179.         jsr     _LVOSPMul(a6)           ;mul
  180.         move.l  #$FFFB5540,d1     ;a0
  181.         jsr     _LVOSPAdd(a6)           ;add
  182.         rts
  183.  
  184.         XDEF    _p%tan
  185. _p%tan
  186.         move.l  4(sp),d0          ;x to d0
  187.         move.l  _p%MathBase,a6
  188.         movem.l  d6-d7,-(sp)
  189.         move.l  d0,d7
  190.         move.l  #$C90FD943,d1     ;twopi
  191.         jsr     _LVOSPCmp(a6)           ;cmp
  192.         bge.s   tan_toobig
  193.         move.l  d7,d0
  194.         move.l  #$0,d1            ;d1 holds 0
  195.         jsr     _LVOSPCmp(a6)           ;cmp
  196.         bge.s   tan_around
  197. tan_toobig
  198.         move.l  d7,d0
  199.         move.l  #$C90FD943,d1     ;twopi
  200.         jsr     _LVOSPDiv(a6)           ;div
  201.         jsr     _LVOSPFloor(a6)           ;floor
  202.         move.l  #$C90FD943,d1     ;twopi
  203.         jsr     _LVOSPMul(a6)           ;mul
  204.         move.l  d7,d1
  205.         exg     d0,d1
  206.         jsr     _LVOSPSub(a6)           ;sub
  207.         move.l  d0,d7
  208. tan_around
  209.         move.l  d7,d0
  210.         move.l  #$C90FD941,d1     ;halfpi
  211.         jsr     _LVOSPCmp(a6)           ;cmp
  212.         bgt.s   tan_TwoQuad
  213.         bsr.s     GetTan
  214.         bra.s   tan_out
  215. tan_TwoQuad
  216.         move.l  d7,d0
  217.         move.l  #$C90FD942,d1     ;pi
  218.         jsr     _LVOSPCmp(a6)           ;cmp
  219.         bgt.s   tan_ThreeQuad
  220.         move.l  #$C90FD942,d0     ;pi
  221.         move.l  d7,d1
  222.         jsr     _LVOSPSub(a6)           ;sub
  223.         move.l  d0,d7
  224.         bsr.s   GetTan
  225.         jsr     _LVOSPNeg(a6)           ;neg
  226.         bra.s   tan_out
  227. tan_ThreeQuad
  228.         move.l  d7,d0
  229.         move.l  #$96CBE343,d1     ;threehalvespi
  230.         jsr     _LVOSPCmp(a6)           ;cmp
  231.         bgt.s   tan_FourQuad
  232.         move.l  d7,d0
  233.         move.l  #$C90FD942,d1     ;pi
  234.         jsr     _LVOSPSub(a6)           ;sub
  235.         move.l  d0,d7
  236.         bsr.s   GetTan
  237.         bra.s   tan_out
  238. tan_FourQuad
  239.         move.l  #$C90FD943,d0     ;twopi
  240.         move.l  d7,d1
  241.         jsr     _LVOSPSub(a6)           ;sub
  242.         move.l  d0,d7
  243.         bsr.s   GetTan
  244.         jsr     _LVOSPNeg(a6)           ;neg
  245. tan_out     movem.l  (sp)+,d6-d7
  246.         rts
  247.  
  248. GetTan
  249.         move.l  d7,d0
  250.         move.l  #$C90FD940,d1     ;fourthpi
  251.         jsr     _LVOSPCmp(a6)           ;cmp
  252.         sgt     d6                ;d6 is flag for angle>fourthpi
  253.         ble.s   tan_small
  254.         move.l  #$C90FD941,d0     ;halfpi
  255.         move.l  d7,d1
  256.         jsr     _LVOSPSub(a6)           ;sub
  257.         move.l  d0,d7
  258.  
  259. tan_small                         ;a4x^4+a3x^3+a2x^2+a1x+a0
  260.         move.l  d7,d0             ;d7 holds x
  261.         move.l  #$FE621B3F,d1     ;a4
  262.         jsr     _LVOSPMul(a6)           ;mul
  263.         move.l  #$DD40913D,d1     ;a3
  264.         jsr     _LVOSPSub(a6)           ;sub   a3 is negative
  265.         move.l  d7,d1
  266.         jsr     _LVOSPMul(a6)           ;mul
  267.         move.l  #$96E19C3E,d1     ;a2
  268.         jsr     _LVOSPAdd(a6)           ;add
  269.         move.l  d7,d1
  270.         jsr     _LVOSPMul(a6)           ;mul
  271.         move.l  #$FB844840,d1     ;a1
  272.         jsr     _LVOSPAdd(a6)           ;add
  273.         move.l  d7,d1
  274.         jsr     _LVOSPMul(a6)           ;mul
  275.         move.l  #$E60CA535,d1     ;a0
  276.         jsr     _LVOSPAdd(a6)           ;add
  277.         tst.s   d6
  278.         beq.s   tan_small_out
  279.         move.l  d0,d1
  280.         move.l  #$80000041,d0
  281.         jsr     _LVOSPDiv(a6)           ;div       take reciprocal of tangent
  282. tan_small_out
  283.         rts
  284.  
  285.         XDEF    _p%atn
  286. _p%atn
  287.         move.l  4(sp),d0          ;x to d0
  288.         move.l  _p%MathBase,a6
  289.         movem.l  d5-d7,-(sp)
  290.         move.l  d0,d7
  291.         move.l  #$0,d1            ;d1 holds 0
  292.         jsr     _LVOSPCmp(a6)           ;cmp
  293.         sle     d6                ;set flag for negative angle
  294.         bge.s   atn_posang
  295.         move.l  d7,d0
  296.         jsr     _LVOSPNeg(a6)           ;neg
  297.         move.l  d0,d7
  298. atn_posang
  299.         move.l  d7,d0
  300.         move.l  #$80000041,d1           ; one
  301.         jsr     _LVOSPCmp(a6)           ;cmp
  302.         sge     d5                ;d5 flags angle > fourthpi
  303.         blt.s   GetAtn
  304.         move.l  d7,d1
  305.         move.l  #$80000041,d0
  306.         jsr     _LVOSPDiv(a6)           ;take reciprocal
  307.         move.l  d0,d7
  308. GetAtn                            ;a4x^4+a3x^3+a2x^2+a1x+a0
  309.         move.l  d7,d0             ;d7 holds x
  310.         move.l  #$8D9AED3E,d1     ;a4
  311.         jsr     _LVOSPMul(a6)           ;mul
  312.         move.l  #$AC901A3F,d1     ;a3
  313.         jsr     _LVOSPSub(a6)           ;sub   a3 is negative
  314.         move.l  d7,d1
  315.         jsr     _LVOSPMul(a6)           ;mul
  316.         move.l  #$A4FC033B,d1     ;a2
  317.         jsr     _LVOSPSub(a6)           ;sub    a2 is negative
  318.         move.l  d7,d1
  319.         jsr     _LVOSPMul(a6)           ;mul
  320.         move.l  #$8098CB41,d1     ;a1
  321.         jsr     _LVOSPAdd(a6)           ;add
  322.         move.l  d7,d1
  323.         jsr     _LVOSPMul(a6)           ;mul
  324.         move.l  #$C93A4B34,d1     ;a0
  325.         jsr     _LVOSPSub(a6)           ;sub    a0 is negative
  326.         tst.b   d5
  327.         beq.s   atn_pos
  328.         move.l  d0,d1
  329.         move.l  #$C90FD941,d0
  330.         jsr     _LVOSPSub(a6)           ;sub
  331.  
  332. atn_pos tst.b    d6
  333.         beq.s   atn_out
  334.         jsr     _LVOSPNeg(a6)           ;neg angle
  335. atn_out movem.l  (sp)+,d5-d7
  336.         rts
  337.  
  338.         END
  339.