home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Libraries / MacOS 68K / MathLib68K / MathLib68K Sources / SANE_glue.c < prev   
Encoding:
C/C++ Source or Header  |  1995-02-24  |  4.7 KB  |  250 lines  |  [TEXT/MMCC]

  1. /*
  2.  *    SANE Glue ....
  3.  */
  4.  
  5. #ifndef __SANE__
  6. #include <SANE.h>
  7. #endif
  8.  
  9. #ifndef __TRAPS__
  10. #include <Traps.h>
  11. #endif
  12.  
  13. /*******************************************************************************
  14. *                            Format Conversion Routines                        *
  15. *******************************************************************************/
  16.  
  17. asm void x96tox80(extended96 *x96,extended80 *x)
  18. {
  19.     move.l    4(sp),a0
  20.     move.l    8(sp),a1
  21.     move.w    (a0)+,(a1)+
  22.     addq.w    #2,a0
  23.     move.l    (a0)+,(a1)+
  24.     move.l    (a0),(a1)
  25.     rts
  26. }
  27.  
  28. asm void x80tox96(extended80 *x80,extended96 *x96)
  29. {
  30.     move.l    4(sp),a0
  31.     move.l    8(sp),a1
  32.     move.w    (a0)+,(a1)+
  33.     clr.w    (a1)+
  34.     move.l    (a0)+,(a1)+
  35.     move.l    (a0),(a1)
  36.     rts
  37. }
  38.  
  39. /*******************************************************************************
  40. *                            Remainder functions                               *
  41. *******************************************************************************/
  42.  
  43. asm void Remainder(extended80 *source,extended80 *dest,short *quot)
  44. {
  45.     move.l    4(sp),-(sp)
  46.     move.l    12(sp),-(sp)
  47.     move.w    #0x000C,-(sp)    /* FREMX */
  48.     op _FP68K
  49.     move.l    12(sp),a0
  50.     move.w    d0,(a0)
  51.     rts
  52. }
  53.  
  54. /*******************************************************************************
  55. *                              Relational operator                             *
  56. *******************************************************************************/
  57.  
  58. asm RelOp Relation(extended80 *source,extended80 *dest)
  59. {
  60.     move.l    4(sp),-(sp)
  61.     move.l    12(sp),-(sp)
  62.     move.w    #0x000A,-(sp)    /* FCPXX */
  63.     op _FP68K
  64.     bne.s    L0
  65.     moveq    #EqualTo,d0
  66.     rts
  67. L0:    bvc.s    L1
  68.     moveq    #Unordered,d0
  69.     rts
  70. L1:    bmi.s    L2
  71.     moveq    #GreaterThan,d0
  72.     rts
  73. L2:    moveq    #LessThan,d0
  74.     rts
  75. }
  76.  
  77. /*******************************************************************************
  78. *                              Environment Functions                           *
  79. *******************************************************************************/
  80.  
  81.  
  82. asm short SignNum(extended80 x)
  83. {
  84.     pea        zeroword
  85.     pea        8(sp)
  86.     move.w    #0x2008,-(sp)    /* FCMPIX */
  87.     op _FP68K
  88.     bne.s    L0
  89.     moveq    #0,d0
  90.     rts
  91. zeroword:
  92.     dc.w    0
  93. L0:    bmi.s    L1
  94.     moveq    #1,d0
  95.     rts
  96. L1:    moveq    #-1,d0
  97.     rts
  98. }
  99.  
  100. #if    __MC68881__
  101.  
  102. asm RoundDir GetRound(void)
  103. {
  104.     DC.W    0xF200,0xB000    //    FMOVE    FPCR,D0
  105.     ANDI.W    #0x0030,D0
  106.     ROR.B    #4,D0
  107.     MOVE.B    L0(D0.W),D0
  108.     RTS
  109. L0:    DC.W    0x0003,0x0201
  110. }
  111.  
  112. asm void SetRound(RoundDir r)
  113. {
  114.     MOVEQ    #0,D0
  115.     MOVE.W    4(sp),D0
  116.     ANDI.W    #0x0003,D0
  117.     DC.W    0xF201,0xB000    //    FMOVE    FPCR,D1
  118.     ANDI.B    #0xCF,D1
  119.     OR.B    L0(D0.W),D1
  120.     DC.W    0xF201,0x9000    //    FMOVE    D1,FPCR
  121.     RTS
  122. L0:    DC.W    0x0030,0x2010
  123. }
  124.  
  125. asm RoundPre GetPrecision(void)
  126. {
  127.     DC.W    0xF200,0xB000    //    FMOVE    FPCR,D0
  128.     ANDI.W    #0x00C0,D0
  129.     ROR.B    #6,D0
  130.     MOVE.B    L0(D0.W),D0
  131.     RTS
  132. L0:    DC.W    0x0002,0x0103
  133. }
  134.  
  135. asm void SetPrecision(RoundPre p)
  136. {
  137.     MOVEQ    #0,D0
  138.     MOVE.W    4(sp),D0
  139.     ANDI.W    #0x0003,D0
  140.     DC.W    0xF201,0xB000    //    FMOVE    FPCR,D1
  141.     ANDI.B    #0x3F,D1
  142.     OR.B    L0(D0.W),D1
  143.     DC.W    0xF201,0x9000    //    FMOVE    D1,FPCR
  144.     RTS
  145. L0:    DC.W    0x0080,0x80C0
  146. }
  147.  
  148. asm extended NaN(short n)
  149. {
  150.     move.w    4(sp),d0            //    n
  151.     bne.s    L0
  152.     moveq    #15,d0
  153. L0:    addi.w    #0x4000,d0
  154.     clr.l    -(sp)                //    push _nan(n) onto stack
  155.     clr.w    -(sp)
  156.     move.w    d0,-(sp)
  157.     move.l    #0x7FFF7FFF,-(sp)
  158.     dc.w    0xF21F,0x4800        //    FMOVE.X    (SP)+,FP0
  159.     rts
  160. }
  161.  
  162. /*
  163. static asm void SetGetHalt(void)
  164. {
  165.     dc.w    0x0C40,0x0000,0x6712,0x0C40,0x0001,0x673C,0x0C40,0x0002,
  166.     dc.w    0x674A,0x303C,0xFE16,0xA9C9,0xF280,0x0000,0x2208,0xF327,
  167.     dc.w    0xF200,0xA800,0x8041,0xF200,0x8800,0xF200,0xB000,0xC041,
  168.     dc.w    0x0280,0x0000,0xFF00,0x670C,0x7000,0x102F,0x0001,0x08B7,
  169.     dc.w    0x0003,0x0000,0xF35F,0x4E75,0x327C,0x00C0,0x20D9,0x20D9,
  170.     dc.w    0x20D9,0x20D9,0x20D9,0x20D9,0x20D9,0x4E75,0x327C,0x00C0,
  171.     dc.w    0x22D8,0x22D8,0x22D8,0x22D8,0x22D8,0x22D8,0x22D8,0x4E75,
  172.     dc.w    0x48E7,0x80C0,0x303C,0xA097,0xA346,0x2248,0x303C,0xA89F,
  173.     dc.w    0xA346,0xB3C8,0x6618,0x7070,0xA51E,0x6B1A,0x2248,0x41FA,
  174.     dc.w    0xFF70,0x7070,0xA02E,0x2049,0x303C,0xA097,0xA247,0x4CDF,
  175.     dc.w    0x0301,0xA097,0x4E75,0x303C,0xFE16,0xA9C9
  176. }
  177. */
  178.  
  179. asm void GetTrapVector(TrapVector *tv)
  180. {
  181.     lea        0x00c0,a0
  182.     move.l    4(sp),a1
  183.     moveq    #7-1,d0
  184. l0:    move.l    (a0)+,(a1)+
  185.     dbf        d0,l0
  186.     rts
  187. }
  188.  
  189. asm void SetTrapVector(TrapVector *tv)
  190. {
  191.     move.l    4(sp),a0
  192.     lea        0x00c0,a1
  193.     moveq    #7-1,d0
  194. l0:    move.l    (a0)+,(a1)+
  195.     dbf        d0,l0
  196.     rts
  197. }
  198.  
  199. #else
  200.  
  201. void SetRound(RoundDir r)
  202. {
  203.     Environment ev;
  204.     
  205.     GetEnvironment(&ev);
  206.     ev=(ev&0x9FFF)|((r&3)<<13);
  207.     SetEnvironment(&ev);
  208. }
  209.  
  210. RoundDir GetRound(void)
  211. {
  212.     Environment ev;
  213.     
  214.     GetEnvironment(&ev);
  215.     return((ev>>13)&3);
  216. }
  217.  
  218. void SetPrecision(RoundPre r)
  219. {
  220.     Environment ev;
  221.  
  222.     GetEnvironment(&ev);
  223.     ev=(ev&0xFF9F)|((r&3)<<5);
  224.     SetEnvironment(&ev);
  225. }
  226.  
  227. RoundPre GetPrecision(void)
  228. {
  229.     Environment ev;
  230.  
  231.     GetEnvironment(&ev);
  232.     return((ev>>5)&3);
  233. }
  234.  
  235. asm extended NaN(short n)
  236. {
  237.     move.w    8(sp),d0        /* n */
  238.     bne.s    L0
  239.     moveq    #15,d0
  240. L0:    addi.w    #0x4000,d0
  241.     move.l    4(sp),a0        /* address of return extended */
  242.     move.w    #0x7FFF,(a0)+
  243.     move.w    d0,(a0)+
  244.     clr.l    (a0)+
  245.     clr.w    (a0)+
  246.     rts
  247. }
  248.  
  249. #endif
  250.