Subversion Repositories spk

Rev

Rev 273 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
114 cycrow 1
#ifndef CONVERSION_INCLUDED
2
#define CONVERSION_INCLUDED
3
 
4
/*
5
 
6
	conversion from:
7
		int to double 
8
		int (modulo 100000) to int (modulo 0xFFFF)
9
	double to int rounding is done "to nearest" - hence the assembler and not simple static cast
10
 
11
*/
12
 
13
namespace conversion
14
{
15
 
16
__declspec(naked)
17
static 
18
int __stdcall vertex_bob2bod(int i)
19
{
20
	// bod = i / 0.65535
21
	static double MULTIPLIER = 0.65536; // == 65535 / 100000
22
	__asm {
23
		fld MULTIPLIER
24
		fidivr dword ptr [esp + 4]
25
		fistp dword ptr [esp + 4]
26
		mov eax, dword ptr [esp + 4]
27
		ret 4
28
	}
29
}
30
 
31
/*inline 
32
int __stdcall vertex_bob2bod(int i)
33
{
34
	static double MULTIPLIER = 0.65535; // == 65535 / 100000 
35
	return (int)(i / MULTIPLIER);
36
}*/
37
 
38
 
39
__declspec(naked)
40
inline 
41
int __stdcall vertex_bod2bob(int i)
42
{
43
	// bob = i * 0.65535
44
	static double MULTIPLIER = 0.65536; // == 65535 / 100000
45
	__asm {
46
		fld MULTIPLIER
47
		fimul dword ptr [esp + 4]
48
		fistp dword ptr [esp + 4]
49
		mov eax, dword ptr [esp + 4]
50
		ret 4
51
	}
52
}
53
 
54
__declspec(naked)
55
inline 
56
int __stdcall double2int(double d)
57
{
58
	static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535
59
 
60
	// int = right / multiplier 
61
	__asm{
62
		fld qword ptr [esp + 4]
63
		fdiv MULTIPLIER
64
		fistp dword ptr [esp + 4]
65
		mov eax, dword ptr [esp + 4]
66
		ret 8
67
	}
68
}
69
/*
70
inline 
71
int __stdcall double2int(double d)
72
{
73
	static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535
74
 
75
	return (int)(d / MULTIPLIER);
76
 
77
}*/
78
 
79
} // namespace conversion
80
 
81
#endif // !defined(CONVERSION_INCLUDED)