File: gsPlatform.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (88 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include "gsPlatform.h"


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Include standard network lib
#if defined(_WIN32) && !defined(_XBOX)
	#if defined(GSI_WINSOCK2)
		#pragma comment(lib, "ws2_32")
	#else
		#pragma comment(lib, "wsock32")
	#endif
	#pragma comment(lib, "advapi32")
#endif


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Floating point specific byte reversal functions
// stores the result in a 4-byte character array
unsigned char * gsiFloatSwap(unsigned char buf[4], float f)
{
	unsigned char *dst = (unsigned char *)buf;
	unsigned char *src = (unsigned char *)&f;

	dst[0] = src[3];
	dst[1] = src[2];
	dst[2] = src[1];
	dst[3] = src[0];

	return buf;
}

// unswap using char pointers
float gsiFloatUnswap(unsigned char buf[4]) 
{
	float f;
	unsigned char *src = (unsigned char *)buf;
	unsigned char *dst = (unsigned char *)&f;

	dst[0] = src[3];
	dst[1] = src[2];
	dst[2] = src[1];
	dst[3] = src[0];

	return f;
}

gsi_u16 gsiByteOrderSwap16(gsi_u16 _in)
{
	gsi_u16 t;
	const char *in = (char *)&_in;
	char *out = (char *)&t;
	out[0] = in[1];
	out[1] = in[0];
	return t;
}

gsi_u32 gsiByteOrderSwap32(gsi_u32 _in)
{
	gsi_u32 t;
	const char *in = (char *)&_in;
	char *out = (char *)&t;
	out[0] = in[3];
	out[1] = in[2];
	out[2] = in[1];
	out[3] = in[0];
	return t;
}

gsi_u64 gsiByteOrderSwap64(gsi_u64 _in)
{
	gsi_u64 t;
	const char *in = (char *)&_in;
	char *out = (char *)&t;
	out[0] = in[7];
	out[1] = in[6];
	out[2] = in[5];
	out[3] = in[4];
	out[4] = in[3];
	out[5] = in[2];
	out[6] = in[1];
	out[7] = in[0];
	return t;
}