Skip to content

Commit afddd9c

Browse files
committed
Adde stuff for Linux in Common
1 parent 11278f1 commit afddd9c

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

src/Common/PlatformLinux.inl

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#include <stdio.h>
2+
#include <cstring>
3+
#include <stdlib.h> // for malloc
4+
#include <unistd.h> // for rmdir
5+
#include <sys/fcntl.h>
6+
#include <sys/stat.h>
7+
#include <sys/types.h>
8+
#include <sys/param.h>
9+
#include <errno.h>
10+
#include <stdarg.h>
11+
#include <ctype.h>
12+
#include <limits.h> // for PAGESIZE...
13+
#include <math.h>
14+
#include <algorithm> // for min max
15+
16+
#include <string>
17+
#include <alloca.h>
18+
#include <pthread.h>
19+
#include <fcntl.h>
20+
#include <sys/mman.h> // for mmap / munmap
21+
#include <dirent.h>
22+
#include <utime.h>
23+
24+
#include <SDL2/SDL.h>
25+
#define CONFIG_USE_SDL
26+
27+
#define _LINUX // for GameSpy
28+
29+
#if !defined(__INTEL_COMPILER)
30+
#define _alloca alloca
31+
#endif
32+
33+
#define _MAX_PATH PATH_MAX + 1
34+
#define MAX_PATH PATH_MAX + 1
35+
36+
#define WINAPI
37+
38+
#define _copysign copysign
39+
40+
#define _cdecl //__attribute__((cdecl))
41+
#define _stdcall //__attribute__((stdcall))
42+
#define _fastcall //__attribute__((fastcall))
43+
44+
#define __cdecl
45+
#define __stdcall
46+
#define __fastcall
47+
//#define __declspec
48+
#define __forceinline FORCE_INLINE
49+
#define __pragma
50+
#define __declspec(x)
51+
#define CALLBACK
52+
53+
/*
54+
static inline long InterlockedExchange(volatile long *val, long new_val)
55+
{
56+
long old_val;
57+
do {
58+
old_val = *val;
59+
} while (__sync_val_compare_and_swap (val, old_val, new_val) != old_val);
60+
return old_val;
61+
}
62+
*/
63+
//TODO: Implement more platform independend atomic operations: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/Common/Atomic_GCC.h
64+
inline void InterlockedExchange(volatile unsigned int& target, unsigned int value)
65+
{
66+
__sync_add_and_fetch(&target, value);
67+
}
68+
69+
inline pthread_t GetCurrentThreadId()
70+
{
71+
return pthread_self();
72+
}
73+
74+
inline void Sleep(int ms)
75+
{
76+
SDL_Delay(ms);
77+
}
78+
79+
inline void _splitpath (
80+
const char *path, // Path Input
81+
char *drive, // Drive : Output
82+
char *dir, // Directory : Output
83+
char *fname, // Filename : Output
84+
char *ext // Extension : Output
85+
){}
86+
87+
inline unsigned long GetLastError()
88+
{
89+
return 0;
90+
}
91+
92+
#define xr_unlink unlink
93+
94+
typedef int BOOL;
95+
typedef char* LPSTR;
96+
typedef char* PSTR;
97+
typedef char* LPTSTR;
98+
typedef const char* LPCSTR;
99+
typedef const char* LPCTSTR;
100+
typedef unsigned char BYTE;
101+
typedef unsigned char* LPBYTE;
102+
typedef unsigned int UINT;
103+
typedef int INT;
104+
typedef long LONG;
105+
106+
typedef unsigned short WORD;
107+
typedef unsigned short* LPWORD;
108+
typedef unsigned long DWORD;
109+
typedef unsigned long* LPDWORD;
110+
typedef const void *LPCVOID;
111+
112+
#define WAVE_FORMAT_PCM 0x0001
113+
114+
typedef struct {
115+
WORD wFormatTag;
116+
WORD nChannels;
117+
DWORD nSamplesPerSec;
118+
DWORD nAvgBytesPerSec;
119+
WORD nBlockAlign;
120+
WORD wBitsPerSample;
121+
WORD cbSize;
122+
} WAVEFORMATEX;
123+
124+
typedef struct _EXCEPTION_POINTERS {
125+
} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
126+
127+
#ifdef XR_X64
128+
typedef int64_t INT_PTR;
129+
typedef uint16_t UINT_PTR;
130+
typedef int64_t LONG_PTR;
131+
#else
132+
typedef int INT_PTR;
133+
typedef unsigned int UINT_PTR;
134+
typedef long LONG_PTR;
135+
#endif // XR_X64
136+
137+
typedef void *HANDLE;
138+
typedef void *HMODULE;
139+
typedef void *LPVOID;
140+
typedef UINT_PTR WPARAM;
141+
typedef LONG_PTR LPARAM;
142+
typedef long HRESULT;
143+
typedef long LRESULT;
144+
typedef long _W64;
145+
//typedef void *HWND;
146+
typedef SDL_Window *HWND;
147+
typedef void *HDC;
148+
//typedef void *HGLRC;
149+
typedef SDL_GLContext HGLRC;
150+
typedef float FLOAT;
151+
typedef unsigned char UINT8;
152+
153+
typedef struct _RECT {
154+
long left;
155+
long top;
156+
long right;
157+
long bottom;
158+
} RECT, *PRECT;
159+
160+
typedef struct tagPOINT {
161+
long x;
162+
long y;
163+
} POINT, *PPOINT, *LPPOINT;
164+
165+
#define WM_USER 0x0400
166+
167+
#define TRUE 1
168+
#define FALSE 0
169+
#define NONE 0
170+
#define CONST const
171+
172+
typedef dirent DirEntryType;
173+
174+
#define _O_WRONLY O_WRONLY
175+
#define _O_RDONLY O_RDONLY
176+
#define _O_TRUNC O_TRUNC
177+
#define _O_CREAT O_CREAT
178+
#define _S_IWRITE S_IWRITE
179+
#define _S_IREAD S_IREAD
180+
#define _O_BINARY 0
181+
#define O_BINARY 0
182+
#define O_SEQUENTIAL 0
183+
#define SH_DENYWR 0
184+
185+
#define _stricmp stricmp
186+
#define strcmpi stricmp
187+
#define stricmp strcasecmp
188+
#define strncpy_s(dest, size, source, num) strncpy(dest, source, num)
189+
#define strcpy_s(dest, num, source) strcpy(dest, source)
190+
#define _vsnprintf vsnprintf
191+
#define _alloca alloca
192+
#define _snprintf snprintf
193+
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) sprintf(buffer, stringbuffer, ##__VA_ARGS__)
194+
#define GetProcAddress(handle, name) dlsym(handle, name)
195+
#define _chdir chdir
196+
#define _strnicmp strnicmp
197+
#define strnicmp strncasecmp
198+
#define _getcwd getcwd
199+
#define _snwprintf swprintf
200+
#define swprintf_s swprintf
201+
#define wcsicmp _wcsicmp
202+
#define _wcsicmp wcscmp
203+
#define _tempnam tempnam
204+
#define _unlink unlink
205+
#define _access access
206+
#define _open open
207+
#define _close close
208+
#define _sopen open
209+
#define _sopen_s(handle, filename, ...) open(filename, O_RDONLY)
210+
#define _fdopen fdopen
211+
#define _rmdir rmdir
212+
#define _write write
213+
#define _strupr strupr
214+
#define _read read
215+
#define _set_new_handler std::set_new_handler
216+
#define _finite isfinite
217+
#define _mkdir(dir) mkdir(dir, S_IRWXU)
218+
#define _wtoi(arg) wcstol(arg, NULL, 10)
219+
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
220+
#undef min
221+
#undef max
222+
#define __max(a, b) std::max(a, b)
223+
#define __min(a, b) std::min(a, b)
224+
225+
#define ZeroMemory(p, sz) memset((p), 0, (sz))
226+
#define CopyMemory(d, s, n) memcpy(d, s, n)
227+
228+
#define RGB(r,g,b) ( ((DWORD)(BYTE)r)|((DWORD)((BYTE)g)<<8)|((DWORD)((BYTE)b)<<16) )
229+
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
230+
#define FAILED(hr) (((HRESULT)(hr)) < 0)
231+
#define S_OK 0x00000000
232+
#define S_FALSE 0x10000000
233+
#define E_FAIL 0x80004005
234+
235+
#define STUBBED(txt) do { \
236+
static bool already_seen = false; \
237+
if (!already_seen) { \
238+
already_seen = true; \
239+
fprintf(stderr, "STUBBED: %s in %s, line %d.\n", txt, __FILE__, __LINE__); \
240+
} \
241+
} while (0)

src/Common/PlatformWindows.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define DOSWIN32
2727
#define _WIN32_DCOM
2828

29+
#define STUBBED(txt) do {} while (0)
30+
2931
#pragma warning(push)
3032
#pragma warning(disable : 4005) // macro redefinition
3133
#include <windows.h>

0 commit comments

Comments
 (0)