home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / fix / fix.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  5KB  |  161 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/fix/rcs/fix.h $
  15.  * $Revision: 1.13 $
  16.  * $Author: matt $
  17.  * $Date: 1994/12/06 13:52:34 $
  18.  *
  19.  * FIX.H - prototypes and macros for fixed-point functions
  20.  *
  21.  * Copyright (c) 1993  Matt Toschlog & Mike Kulas
  22.  *
  23.  * $Log: fix.h $
  24.  * Revision 1.13  1994/12/06  13:52:34  matt
  25.  * Added f2ir(), which is fix-to-int with rounding
  26.  * 
  27.  * Revision 1.12  1994/05/18  21:45:16  matt
  28.  * Added comments
  29.  * 
  30.  * Revision 1.11  1994/01/19  23:12:02  matt
  31.  * Made fix_atan2() left-handed, like our coordinate system
  32.  * 
  33.  * Revision 1.10  1993/10/20  01:09:00  matt
  34.  * Add fix_asin(), improved fix_atan2()
  35.  * 
  36.  * Revision 1.9  1993/10/19  23:53:46  matt
  37.  * Added fix_atan2()
  38.  * 
  39.  * Revision 1.8  1993/10/19  22:22:40  matt
  40.  * Added fix_acos()
  41.  * 
  42.  * Revision 1.7  1993/09/17  11:37:01  mike
  43.  * Add capitalized versions of "some handy constants", eg:
  44.  * #define F1_0 f1_0
  45.  * 
  46.  * Revision 1.6  1993/08/24  13:00:48  matt
  47.  * Adopted new standard, and made assembly-callable routines not trash any regs
  48.  * 
  49.  * Revision 1.5  1993/08/12  13:12:45  matt
  50.  * Changed fixmul() to use SHRD instead of shl,shr,or
  51.  * 
  52.  * Revision 1.4  1993/08/04  19:57:18  matt
  53.  * Added parens in fix/float conversion macros
  54.  * 
  55.  * Revision 1.3  1993/08/04  11:41:45  matt
  56.  * Fixed bogus constants
  57.  * 
  58.  * Revision 1.2  1993/08/04  09:30:11  matt
  59.  * Added more constants
  60.  * 
  61.  * Revision 1.1  1993/08/03  17:45:53  matt
  62.  * Initial revision
  63.  * 
  64.  *
  65.  */
  66.  
  67. #ifndef _FIX_H
  68. #define _FIX_H
  69.  
  70. #include "types.h"
  71.  
  72. typedef long fix;                //16 bits int, 16 bits frac
  73. typedef short fixang;        //angles
  74.  
  75. //Convert an int to a fix
  76. #define i2f(i) ((i)<<16)
  77.  
  78. //Get the int part of a fix
  79. #define f2i(f) ((f)>>16)
  80.  
  81. //Get the int part of a fix, with rounding
  82. #define f2ir(f) (((f)+f0_5)>>16)
  83.  
  84. //Convert fix to float and float to fix
  85. #define f2fl(f) (((float) (f)) / 65536.0)
  86. #define fl2f(f) ((fix) ((f) * 65536))
  87.  
  88. //Some handy constants
  89. #define f0_0    0
  90. #define f1_0    0x10000
  91. #define f2_0    0x20000
  92. #define f3_0    0x30000
  93. #define f10_0    0xa0000
  94.  
  95. #define f0_5 0x8000
  96. #define f0_1 0x199a
  97.  
  98. #define F0_0    f0_0
  99. #define F1_0    f1_0
  100. #define F2_0    f2_0
  101. #define F3_0    f3_0
  102. #define F10_0    f10_0
  103.  
  104. #define F0_5     f0_5
  105. #define F0_1     f0_1
  106.  
  107. fix fixmul(fix a,fix b);
  108. #pragma aux fixmul parm [eax] [edx] = \
  109.     "imul    edx"                \
  110.     "shrd    eax,edx,16";
  111.  
  112.  
  113. fix fixdiv(fix a,fix b);
  114. #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
  115.     "mov    edx,eax"    \
  116.     "sar    edx,16"    \
  117.     "shl    eax,16"    \
  118.     "idiv    ebx";
  119.  
  120. fix fixmuldiv(fix a,fix b,fix c);
  121. #pragma aux fixmuldiv parm [eax] [edx] [ebx] modify exact [eax edx] = \
  122.     "imul    edx"    \
  123.     "idiv    ebx";
  124.  
  125. //computes the square root of a long, returning a short
  126. ushort long_sqrt(long a);
  127.  
  128. //computes the square root of a quad, returning a long
  129. ulong quad_sqrt(long low,long high);
  130.  
  131. //computes the square root of a fix, returning a fix
  132. fix fix_sqrt(fix a);
  133.  
  134. //compute sine and cosine of an angle, filling in the variables
  135. //either of the pointers can be NULL
  136. void fix_sincos(fix a,fix *s,fix *c);        //with interpolation
  137. void fix_fastsincos(fix a,fix *s,fix *c);    //no interpolation
  138.  
  139. //compute inverse sine & cosine
  140. fixang fix_asin(fix v); 
  141. fixang fix_acos(fix v); 
  142.  
  143. //given cos & sin of an angle, return that angle.
  144. //parms need not be normalized, that is, the ratio of the parms cos/sin must
  145. //equal the ratio of the actual cos & sin for the result angle, but the parms 
  146. //need not be the actual cos & sin.  
  147. //NOTE: this is different from the standard C atan2, since it is left-handed.
  148. fixang fix_atan2(fix cos,fix sin); 
  149.  
  150. #pragma aux fix_fastsincos parm [eax] [esi] [edi] modify exact [eax ebx];
  151. #pragma aux fix_sincos parm [eax] [esi] [edi] modify exact [eax ebx];
  152.  
  153. #pragma aux fix_acos "*" parm [eax] value [ax] modify exact [eax];
  154. #pragma aux fix_atan2 "*" parm [eax] [ebx] value [ax] modify exact [eax ebx];
  155.  
  156. #pragma aux long_sqrt "*" parm [eax] value [ax] modify [];
  157. #pragma aux fix_sqrt "*" parm [eax] value [eax] modify [];
  158. #pragma aux quad_sqrt "*" parm [eax] [edx] value [eax] modify [];
  159.  
  160. #endif
  161.