forked from ec-/Quake3e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq_platform.h
More file actions
309 lines (238 loc) · 6.45 KB
/
Copy pathq_platform.h
File metadata and controls
309 lines (238 loc) · 6.45 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
//
#ifndef __Q_PLATFORM_H
#define __Q_PLATFORM_H
#define QDECL
#define id386 0
#define idx64 0
#define arm32 0
#define arm64 0
// ============================== Win32 ====================================
#ifdef _WIN32
#undef QDECL
#define QDECL __cdecl
#define Q_NEWLINE "\r\n"
#if defined (_WIN32_WINNT)
#if _WIN32_WINNT < 0x0501
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#else
#define _WIN32_WINNT 0x0501
#endif
#if defined( _MSC_VER ) && _MSC_VER >= 1400 // MSVC++ 8.0 at least
#define OS_STRING "win_msvc"
#define ID_INLINE __inline
#elif defined __MINGW32__
#define OS_STRING "win_mingw"
#define ID_INLINE __attribute__((always_inline,flatten)) inline
#elif defined __MINGW64__
#define OS_STRING "win_mingw64"
#define ID_INLINE __attribute__((always_inline,flatten)) inline
#else
#error "Compiler not supported"
#endif
#define PATH_SEP '\\'
#define PATH_SEP_FOREIGN '/'
#define DLL_EXT ".dll"
#if defined( _M_IX86 )
#define ARCH_STRING "x86"
#define Q3_LITTLE_ENDIAN
#undef id386
#define id386 1
#ifndef __WORDSIZE
#define __WORDSIZE 32
#endif
#endif
#if defined( _M_AMD64 )
#define ARCH_STRING "x86_64"
#define Q3_LITTLE_ENDIAN
#undef idx64
#define idx64 1
//#define UNICODE
#ifndef __WORDSIZE
#define __WORDSIZE 64
#endif
#endif
#if defined( _M_ARM64 )
#define ARCH_STRING "arm64"
#define Q3_LITTLE_ENDIAN
#undef arm64
#define arm64 1
#ifndef __WORDSIZE
#define __WORDSIZE 64
#endif
#endif
#if defined( _M_ARM )
#define ARCH_STRING "arm32"
#define Q3_LITTLE_ENDIAN
#undef arm32
#define arm32 1
#endif
#else // !defined _WIN32
// common unix platforms parameters
#define Q_NEWLINE "\n"
#define PATH_SEP '/'
#define PATH_SEP_FOREIGN '\\'
#define DLL_EXT ".so"
#if defined (__i386__)
#define ARCH_STRING "i386"
#define Q3_LITTLE_ENDIAN
#undef id386
#define id386 1
#endif // __i386__
#if defined (__x86_64__) || defined (__amd64__)
#define ARCH_STRING "x86_64"
#define Q3_LITTLE_ENDIAN
#undef idx64
#define idx64 1
#endif // __x86_64__ || __amd64__
#if defined (__arm__)
#define ARCH_STRING "arm"
#define Q3_LITTLE_ENDIAN
#undef arm32
#define arm32 1
#endif // __arm__
#if defined (__aarch64__)
#define ARCH_STRING "aarch64"
#define Q3_LITTLE_ENDIAN
#undef arm64
#define arm64 1
#endif // __arm64__
#if defined (__PPC64__)
#if defined (__LITTLE_ENDIAN__) || defined (__LITTLE_ENDIAN)
#define ARCH_STRING "ppc64le"
#define Q3_LITTLE_ENDIAN
#else
#define ARCH_STRING "ppc64"
#define Q3_BIG_ENDIAN
#endif // !__LITTLE_ENDIAN__
#endif // __PPC64__
#endif // !_WIN32
// ============================== Linux ====================================
#ifdef __linux__
#include <endian.h>
#define OS_STRING "linux"
#define ID_INLINE __attribute__((always_inline,flatten)) inline
#endif // __linux___
// =============================== BSD =====================================
#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
#include <sys/types.h>
#include <machine/endian.h>
#if defined (__FreeBSD__)
#define OS_STRING "freebsd"
#elif defined (__NetBSD__)
#define OS_STRING "netbsd"
#elif defined (__OpenBSD__)
#define OS_STRING "openbsd"
#endif
#define ID_INLINE __attribute__((always_inline,flatten)) inline
#if BYTE_ORDER == BIG_ENDIAN
#define Q3_BIG_ENDIAN
#else
#define Q3_LITTLE_ENDIAN
#endif
#endif // __FreeBSD__ || __NetBSD__ || __OpenBSD__
// ================================ APPLE ===================================
#ifdef __APPLE__
#define OS_STRING "macos"
#define ID_INLINE __attribute__((always_inline,flatten)) inline
#undef DLL_EXT
#define DLL_EXT ".dylib"
#endif // __APPLE__
// ================================ Q3VM ===================================
#ifdef Q3_VM
#define OS_STRING "q3vm"
#define ID_INLINE
#define ARCH_STRING "bytecode"
#define Q3_LITTLE_ENDIAN
#undef DLL_EXT
#define DLL_EXT ".qvm"
#endif
// =========================================================================
//catch missing defines in above blocks
#if !defined( OS_STRING )
#error "Operating system not supported"
#endif
#if !defined( ARCH_STRING )
#error "Architecture not supported"
#endif
#ifndef ID_INLINE
#error "ID_INLINE not defined"
#endif
#ifndef PATH_SEP
#error "PATH_SEP not defined"
#endif
#ifndef PATH_SEP_FOREIGN
#error "PATH_SEP_FOREIGN not defined"
#endif
#ifndef DLL_EXT
#error "DLL_EXT not defined"
#endif
// Endianess
#if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN )
#error "Endianness defined as both big and little"
#elif defined( Q3_BIG_ENDIAN )
#define CopyLittleShort(dest, src) CopyShortSwap(dest, src)
#define CopyLittleLong(dest, src) CopyLongSwap(dest, src)
#define LittleShort(x) ShortSwap(x)
#define LittleLong(x) LongSwap(x)
#define LittleFloat(x) FloatSwap(&x)
#define BigShort
#define BigLong
#define BigFloat
#elif defined( Q3_LITTLE_ENDIAN )
#define CopyLittleShort(dest, src) Com_Memcpy(dest, src, 2)
#define CopyLittleLong(dest, src) Com_Memcpy(dest, src, 4)
#define LittleShort
#define LittleLong
#define LittleFloat
#define BigShort(x) ShortSwap(x)
#define BigLong(x) LongSwap(x)
#define BigFloat(x) FloatSwap(&x)
#else
#error "Endianness not defined"
#endif
// Platform string
#ifdef NDEBUG
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING
#else
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug"
#endif
#if idx64
#ifdef _MSC_VER
#define _MSC_SSE2
#else
#define _GCC_SSE2
#endif
#endif // idx64
#if defined(__VSX__)
#define _GCC_VSX
#endif // __VSX__
// Modifier for printing size_t values portably
#if (defined _WIN64)
#define PRIz "I64"
#elif (defined _WIN32)
#define PRIz "I32"
#elif (defined Q3_VM)
#define PRIz ""
#else
#define PRIz "z"
#endif
#endif // __Q_PLATFORM_H