aboutsummaryrefslogtreecommitdiff
path: root/src/libparsec/include/gd_host.h
blob: 96115bda05095c5eb8ea494fc13706029ea6a229 (plain)
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
/*
 * PARSEC HEADER: gd_host.h
 */

#ifndef _GD_HOST_H_
#define _GD_HOST_H_


// ----------------------------------------------------------------------------
// HOST BYTE ORDER/WORD SIZE RELATED MACROS                                   -
// ----------------------------------------------------------------------------


// endianness conversion functions --------------------------------------------
//
#define FORCESWAP_16(s)		( ((word)(s) >> 8) | ((word)(s) << 8) )
#define FORCESWAP_32(l)		( ( ((dword)(l)             ) << 24 ) |	\
							  ( ((dword)(l)             ) >> 24 ) |	\
							  ( ((dword)(l) & 0x0000ff00) << 8 )  |	\
							  ( ((dword)(l) & 0x00ff0000) >> 8 ) )

#ifdef SYSTEM_BIG_ENDIAN

	// little endian to host (and vice versa)
	#define SWAP_16(s)		FORCESWAP_16(s)
	#define SWAP_32(l)		FORCESWAP_32(l)

	// big endian to host (and vice versa)
	#define SWAP_16_BIG(s)	(s)
	#define SWAP_32_BIG(l)	(l)

#else

	// little endian to host (and vice versa)
	#define SWAP_16(s)		(s)
	#define SWAP_32(l)		(l)

	// big endian to host (and vice versa)
	#define SWAP_16_BIG(s)	FORCESWAP_16(s)
	#define SWAP_32_BIG(l)	FORCESWAP_32(l)

#endif // SYSTEM_BIG_ENDIAN


// conversion from seg:ofs address to linear address (DOS32 only) -------------
//
#define MK_LINEAR(seg,ofs)			((void*)((seg<<4)+ofs))


// lo and hi byte and word functions (intentionally not named like in win32) --
//
#ifndef LO_BYTE
	#define LO_BYTE(w)				((byte)(w))
#endif

#ifndef HI_BYTE
	#define HI_BYTE(w)				((byte)((w)>>8))
#endif

#ifndef LO_WORD
	#define LO_WORD(l)				((word)(l))
#endif

#ifndef HI_WORD
	#define HI_WORD(l)				((word)((l)>>16))
#endif

#ifndef MAKE_WORD
	#define MAKE_WORD(l,h)			(((byte)(l))|(((word)(byte)(h))<<8))
#endif

#ifndef MAKE_DWORD
	#define MAKE_DWORD(l,h)			(((word)(l))|(((dword)(word)(h))<<16))
#endif


#endif // _GD_HOST_H_