]> icculus.org git repositories - btb/d2x.git/blob - unused/lib/fix.h
This commit was manufactured by cvs2svn to create tag 'd2x-0_1_3'.
[btb/d2x.git] / unused / lib / fix.h
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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifndef _FIX_H
15 #define _FIX_H
16
17 #include "pstypes.h"
18
19 typedef long fix;                               //16 bits int, 16 bits frac
20 typedef short fixang;           //angles
21
22 typedef struct quad {
23         ulong low;
24         long high;
25 } quad;
26
27 //Convert an int to a fix
28 #define i2f(i) ((i)<<16)
29
30 //Get the int part of a fix
31 #define f2i(f) ((f)>>16)
32
33 //Get the int part of a fix, with rounding
34 #define f2ir(f) (((f)+f0_5)>>16)
35
36 //Convert fix to float and float to fix
37 #define f2fl(f) (((float) (f)) / 65536.0)
38 #define fl2f(f) ((fix) ((f) * 65536))
39
40 //Some handy constants
41 #define f0_0    0
42 #define f1_0    0x10000
43 #define f2_0    0x20000
44 #define f3_0    0x30000
45 #define f10_0   0xa0000
46
47 #define f0_5 0x8000
48 #define f0_1 0x199a
49
50 #define F0_0    f0_0
51 #define F1_0    f1_0
52 #define F2_0    f2_0
53 #define F3_0    f3_0
54 #define F10_0   f10_0
55
56 #define F0_5    f0_5
57 #define F0_1    f0_1
58
59 fix fixmul(fix a,fix b);
60 #pragma aux fixmul parm [eax] [edx] = \
61         "imul   edx"                            \
62         "shrd   eax,edx,16";
63
64
65 fix fixdiv(fix a,fix b);
66 #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
67         "mov    edx,eax"        \
68         "sar    edx,16" \
69         "shl    eax,16" \
70         "idiv   ebx";
71
72 fix fixmuldiv(fix a,fix b,fix c);
73 #pragma aux fixmuldiv parm [eax] [edx] [ebx] modify exact [eax edx] = \
74         "imul   edx"    \
75         "idiv   ebx";
76
77 #pragma aux fixmulaccum parm [esi] [eax] [edx] modify exact [eax edx] = \
78         "imul   edx"                    \
79         "add  [esi],eax"        \
80         "adc    4[esi],edx";
81
82 #pragma aux fixquadadjust parm [esi] modify exact [eax edx] = \
83         "mov  eax,[esi]"                \
84         "mov  edx,4[esi]"               \
85         "shrd   eax,edx,16";
86
87 #pragma aux fixquadnegate parm [eax] modify exact [ebx] = \
88         "mov    ebx,[eax]"              \
89         "neg    ebx"                            \
90         "mov    [eax],ebx"              \
91         "mov    ebx,4[eax]"             \
92         "not    ebx"                            \
93         "sbb    ebx,-1"                 \
94         "mov    4[eax],ebx";
95
96 #pragma aux fixdivquadlong parm [eax] [edx] [ebx] modify exact [eax edx] = \
97         "idiv   ebx";
98
99 //computes the square root of a long, returning a short
100 ushort long_sqrt(long a);
101
102 //computes the square root of a quad, returning a long
103 ulong quad_sqrt(long low,long high);
104
105 //computes the square root of a fix, returning a fix
106 fix fix_sqrt(fix a);
107
108 //multiply two fixes, and add 64-bit product to a quad
109 void fixmulaccum(quad *q,fix a,fix b);
110
111 //extract a fix from a quad product
112 fix fixquadadjust(quad *q);
113
114 //divide a quad by a long
115 long fixdivquadlong(ulong qlow,long qhigh,long d);
116
117 //negate a quad
118 void fixquadnegate(quad *q);
119
120 //compute sine and cosine of an angle, filling in the variables
121 //either of the pointers can be NULL
122 void fix_sincos(fix a,fix *s,fix *c);           //with interpolation
123 void fix_fastsincos(fix a,fix *s,fix *c);       //no interpolation
124
125 //compute inverse sine & cosine
126 fixang fix_asin(fix v); 
127 fixang fix_acos(fix v); 
128
129 //given cos & sin of an angle, return that angle.
130 //parms need not be normalized, that is, the ratio of the parms cos/sin must
131 //equal the ratio of the actual cos & sin for the result angle, but the parms 
132 //need not be the actual cos & sin.  
133 //NOTE: this is different from the standard C atan2, since it is left-handed.
134 fixang fix_atan2(fix cos,fix sin); 
135
136 #pragma aux fix_fastsincos parm [eax] [esi] [edi] modify exact [eax ebx];
137 #pragma aux fix_sincos parm [eax] [esi] [edi] modify exact [eax ebx];
138
139 #pragma aux fix_asin "*" parm [eax] value [ax] modify exact [eax];
140 #pragma aux fix_acos "*" parm [eax] value [ax] modify exact [eax];
141 #pragma aux fix_atan2 "*" parm [eax] [ebx] value [ax] modify exact [eax ebx];
142
143 #pragma aux long_sqrt "*" parm [eax] value [ax] modify [];
144 #pragma aux fix_sqrt "*" parm [eax] value [eax] modify [];
145 #pragma aux quad_sqrt "*" parm [eax] [edx] value [eax] modify [];
146
147 #endif