home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / 3DENGINE.ZIP / Fixpoint.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-21  |  1.0 KB  |  69 lines

  1.  
  2. // FIXPOINT.ASM
  3. //
  4. // Copyright (c) 1993
  5. // Kevin Gliner
  6. //
  7. // Adapted by Christopher Lampton for
  8. // GARDENS OF IMAGINATION (Waite Group Press, 1994)
  9. #pragma inline
  10.  
  11. inline void fixmul(long arg1, long arg2)
  12. {
  13.      asm {
  14.         push    bp
  15.         mov    bp,sp
  16.         mov    eax,arg1
  17.         imul    arg2
  18. //                          shr        eax,16          ;to put result in eax instead, do
  19.                                                 ;a shrd edx,eax,16
  20.         shrd eax,edx,16
  21.         pop    bp
  22.         ret
  23.     }
  24. }
  25.  
  26. inline void fixmuldiv(long arg1, long arg2, long arg3)
  27. {
  28.      asm {
  29.         push    bp
  30.         mov    bp,sp
  31.         mov    eax, arg1
  32.         imul    arg2
  33.         idiv    arg3               ;eax now holds result
  34.         shld edx,eax,16
  35.         pop    bp
  36.         ret
  37.      }
  38. }
  39.  
  40. inline void fixdiv(long numer, long denom)
  41. {
  42.     asm {
  43.         push bp
  44.         mov  bp,sp
  45.         mov  eax, numer
  46.         mov  edx,eax
  47.         sar  edx,16
  48.         shl  eax,16
  49.         idiv denom            ;eax now holds result
  50.         shld edx,eax,16
  51.         pop  bp
  52.         ret
  53.     }
  54. }
  55.  
  56. inline void fix(int arg1)
  57. {
  58.     asm {
  59.         push bp
  60.         mov  bp,sp
  61.         mov  ax, arg1
  62.         sal  eax,16
  63.         mov  edx, eax
  64.         shr  edx, 16
  65.         pop  bp
  66.         ret
  67.     }
  68. }
  69.