FIX.H 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #ifndef _FIX_H
  67. #define _FIX_H
  68. #include "types.h"
  69. typedef long fix; //16 bits int, 16 bits frac
  70. typedef short fixang; //angles
  71. //Convert an int to a fix
  72. #define i2f(i) ((i)<<16)
  73. //Get the int part of a fix
  74. #define f2i(f) ((f)>>16)
  75. //Get the int part of a fix, with rounding
  76. #define f2ir(f) (((f)+f0_5)>>16)
  77. //Convert fix to float and float to fix
  78. #define f2fl(f) (((float) (f)) / 65536.0)
  79. #define fl2f(f) ((fix) ((f) * 65536))
  80. //Some handy constants
  81. #define f0_0 0
  82. #define f1_0 0x10000
  83. #define f2_0 0x20000
  84. #define f3_0 0x30000
  85. #define f10_0 0xa0000
  86. #define f0_5 0x8000
  87. #define f0_1 0x199a
  88. #define F0_0 f0_0
  89. #define F1_0 f1_0
  90. #define F2_0 f2_0
  91. #define F3_0 f3_0
  92. #define F10_0 f10_0
  93. #define F0_5 f0_5
  94. #define F0_1 f0_1
  95. fix fixmul(fix a,fix b);
  96. #pragma aux fixmul parm [eax] [edx] = \
  97. "imul edx" \
  98. "shrd eax,edx,16";
  99. fix fixdiv(fix a,fix b);
  100. #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
  101. "mov edx,eax" \
  102. "sar edx,16" \
  103. "shl eax,16" \
  104. "idiv ebx";
  105. fix fixmuldiv(fix a,fix b,fix c);
  106. #pragma aux fixmuldiv parm [eax] [edx] [ebx] modify exact [eax edx] = \
  107. "imul edx" \
  108. "idiv ebx";
  109. //computes the square root of a long, returning a short
  110. ushort long_sqrt(long a);
  111. //computes the square root of a quad, returning a long
  112. ulong quad_sqrt(long low,long high);
  113. //computes the square root of a fix, returning a fix
  114. fix fix_sqrt(fix a);
  115. //compute sine and cosine of an angle, filling in the variables
  116. //either of the pointers can be NULL
  117. void fix_sincos(fix a,fix *s,fix *c); //with interpolation
  118. void fix_fastsincos(fix a,fix *s,fix *c); //no interpolation
  119. //compute inverse sine & cosine
  120. fixang fix_asin(fix v);
  121. fixang fix_acos(fix v);
  122. //given cos & sin of an angle, return that angle.
  123. //parms need not be normalized, that is, the ratio of the parms cos/sin must
  124. //equal the ratio of the actual cos & sin for the result angle, but the parms
  125. //need not be the actual cos & sin.
  126. //NOTE: this is different from the standard C atan2, since it is left-handed.
  127. fixang fix_atan2(fix cos,fix sin);
  128. #pragma aux fix_fastsincos parm [eax] [esi] [edi] modify exact [eax ebx];
  129. #pragma aux fix_sincos parm [eax] [esi] [edi] modify exact [eax ebx];
  130. #pragma aux fix_acos "*" parm [eax] value [ax] modify exact [eax];
  131. #pragma aux fix_atan2 "*" parm [eax] [ebx] value [ax] modify exact [eax ebx];
  132. #pragma aux long_sqrt "*" parm [eax] value [ax] modify [];
  133. #pragma aux fix_sqrt "*" parm [eax] value [eax] modify [];
  134. #pragma aux quad_sqrt "*" parm [eax] [edx] value [eax] modify [];
  135. #endif