1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef __NUM_TYPE_HPP_
|
---|
10 | #define __NUM_TYPE_HPP_
|
---|
11 |
|
---|
12 | #include "arch.hh"
|
---|
13 |
|
---|
14 | /*
|
---|
15 | Use i4_float instead of float so we can
|
---|
16 | substitute fixed point later on
|
---|
17 | */
|
---|
18 |
|
---|
19 | typedef float i4_float;
|
---|
20 | typedef float i4_angle; // stored in radians
|
---|
21 |
|
---|
22 | inline i4_float i4_fabs(const i4_float &x)
|
---|
23 | {
|
---|
24 | if (x<0)
|
---|
25 | return -x;
|
---|
26 | else return x;
|
---|
27 | }
|
---|
28 |
|
---|
29 | #ifdef WIN32
|
---|
30 | inline sw32 i4_f_to_i(i4_float f)
|
---|
31 | {
|
---|
32 | w16 i4_f_to_i_control_word_1;
|
---|
33 | w16 i4_f_to_i_control_word_2;
|
---|
34 | sw32 res;
|
---|
35 | __asm
|
---|
36 | {
|
---|
37 | fld f
|
---|
38 |
|
---|
39 | wait
|
---|
40 | fnstcw i4_f_to_i_control_word_1
|
---|
41 | wait
|
---|
42 |
|
---|
43 | mov ax,i4_f_to_i_control_word_1
|
---|
44 | or ah,0xC
|
---|
45 | mov word ptr i4_f_to_i_control_word_2,ax
|
---|
46 | fldcw i4_f_to_i_control_word_2
|
---|
47 | fistp res
|
---|
48 | fldcw i4_f_to_i_control_word_1
|
---|
49 | }
|
---|
50 | return res;
|
---|
51 | }
|
---|
52 |
|
---|
53 | inline sw32 i4_s_to_i(double f)
|
---|
54 | {
|
---|
55 | w16 i4_f_to_i_control_word_1;
|
---|
56 | w16 i4_f_to_i_control_word_2;
|
---|
57 | sw32 res;
|
---|
58 | __asm
|
---|
59 | {
|
---|
60 | fld qword ptr [f]
|
---|
61 |
|
---|
62 | fnstcw i4_f_to_i_control_word_1
|
---|
63 |
|
---|
64 | mov ax,i4_f_to_i_control_word_1
|
---|
65 | or ah,0xC
|
---|
66 | mov word ptr i4_f_to_i_control_word_2,ax
|
---|
67 | fldcw i4_f_to_i_control_word_2
|
---|
68 | fistp res
|
---|
69 | fldcw i4_f_to_i_control_word_1
|
---|
70 | }
|
---|
71 | return res;
|
---|
72 | }
|
---|
73 |
|
---|
74 | #else
|
---|
75 |
|
---|
76 | #define i4_f_to_i(a) (sw32)(a)
|
---|
77 | #define i4_d_to_i(a) (sw32)(a)
|
---|
78 |
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | inline i4_float i4_interpolate(i4_float from, i4_float to, i4_float frac)
|
---|
82 | {
|
---|
83 | return (to - from)*frac + from;
|
---|
84 | }
|
---|
85 |
|
---|
86 | #endif
|
---|