home *** CD-ROM | disk | FTP | other *** search
/ Software Collection (I) / TOOLS.iso / b05 / 6.img / PSCRIPT / TRIG.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-03-11  |  3.8 KB  |  150 lines

  1. ;/**[f******************************************************************
  2. ; * trig.a -
  3. ; *
  4. ; * Copyright (C) 1988 Aldus Corporation.  All rights reserved.
  5. ; * Copyright (C) 1989-1992  Microsoft Corporation.
  6. ; * Company confidential.
  7. ; *
  8. ; **f]*****************************************************************/
  9.  
  10. ; peterwo - 12-17-91  bug fix and simplify this using a little trig.
  11.  
  12. ; basically, we have a table of sines spanning angles from 0 to 90 degs.
  13. ; our task is to convert any sin or cos of any angle to
  14. ; a sin of an angle from 0 to 90 degs.
  15.  
  16. ; how to do this:
  17. ; cos(phi) = sin(phi + 90)      //  (a) convert cosines to sines
  18.  
  19. ; sin(phi) = - sin(-phi)        //  (b) convert negative angles to positive
  20.  
  21. ; sin(phi) = sin(phi % 360)     //  (c) convert angle to range (0 < phi < 360)
  22.  
  23. ; if (180 < phi < 360)
  24. ;    sin(phi) = - sin(phi - 180)  //  (d) convert angle to range
  25. ;                                 //        (0 < phi < 180)
  26.  
  27. ; if (90 < phi < 180)
  28. ;    sin(phi) = sin(180 - phi)  //  (e) convert angle to range (0 < phi < 90)
  29.  
  30.  
  31.  
  32.  
  33.  
  34.         .xlist
  35.         include cmacros.inc
  36.         .list
  37.  
  38.  
  39.         ExternFP Scale
  40.  
  41.  
  42.  
  43. createSeg _TRIG,nres,byte,public,CODE
  44. sBegin  nres
  45. assumes cs,nres
  46. assumes ds,nothing
  47.  
  48.  
  49.         include vecttext.h              ; C and MASM inc file
  50.         include vttable.h               ; C and MASM inc file
  51.  
  52.  
  53. cProc   RCos,<FAR,PUBLIC>
  54.  
  55.         parmw   R
  56.         parmw   Angle
  57.  
  58. cBegin
  59.  
  60.         mov     ax,Angle
  61.         add     ax, 900                 ; rule (a)
  62.         jmp     short ComputeSin
  63. cEnd    <nogen>
  64.  
  65.  
  66. cProc   RSin,<FAR,PUBLIC>
  67.  
  68.         parmw   R
  69.         parmw   Angle
  70.  
  71. cBegin
  72.  
  73.         mov     ax,Angle
  74. ComputeSin:
  75. ; separate sign from Angle
  76.         cwd                             ; save sign
  77.         xor     ax,dx                   ; take absolute value
  78.         sub     ax,dx                   ;
  79.  
  80.         mov     bx,dx                   ; save sign
  81.         xor     dx,dx                   ; clear out high word
  82.         mov     cx,3600                 ; divide by period of sin/cos
  83.         div     cx                      ; get modulo in dx
  84.         mov     ax,dx                   ; ax now contains a postive angle
  85.                                         ; between 0 and 360 degrees
  86.         cmp     ax,1800
  87.         jle     LessThan180
  88.         sub     ax,1800                 ; rule (d)
  89.         xor     bx,0FFFFh               ; reverse sign
  90.  
  91. LessThan180:
  92.         cmp     ax,900
  93.         jle     LessThan90
  94.         sub     ax,1800                 ; rule (e)
  95.         neg     ax
  96.  
  97. LessThan90:                             ; ax is now between 0 and 90 degrees
  98.         mov     dx,bx                   ; RTable expects the sign in dx
  99.  
  100.  
  101. ;       RTable - ...
  102. ;
  103. ;       Compute (R * vttable[index]) / (10000)
  104. ;
  105. ;       Currently:
  106. ;               dx = negate flag  0 or FFFF
  107. ;               ax = index
  108.  
  109.  
  110.  
  111.         push    dx                      ;Save negation flag
  112.  
  113.         ifdef   INTERPOLATEDANGLES      ;If interpolation
  114.  
  115.         push    di                      ;Interpolation
  116.         cwd                             ;Compute Index/10
  117.         mov     cx,10
  118.         div     cx
  119.         mov     bx,ax
  120.         shl     bx,1
  121.         mov     di,vttable[bx]          ;Get base value
  122.         mov     ax,vttable+2[bx]
  123.         sub     ax,di
  124.         cCall   Scale,<dx,ax,cx>
  125.         add     ax,di
  126.         mov     cx,10000
  127.         cCall   Scale,<R,ax,cx>
  128.         pop     di
  129.  
  130.         else
  131.  
  132.         mov     bx,ax
  133.         shl     bx,1                    ;Make it a word index
  134.         mov     cx,10000
  135.         cCall   Scale,<R,vttable[bx],cx>
  136.  
  137.         endif
  138.  
  139.  
  140.         pop     dx                      ;Negate result if needed
  141.         xor     ax,dx
  142.         sub     ax,dx
  143.  
  144.  
  145.  
  146. cEnd    RSin
  147.  
  148. sEnd    nres
  149. end
  150.