Skip to content

Commit

Permalink
Adde stuff for Linux in Common
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-t committed Mar 13, 2017
1 parent 11278f1 commit afddd9c
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
241 changes: 241 additions & 0 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
#include <stdio.h>
#include <cstring>
#include <stdlib.h> // for malloc
#include <unistd.h> // for rmdir
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
#include <limits.h> // for PAGESIZE...
#include <math.h>
#include <algorithm> // for min max

#include <string>
#include <alloca.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/mman.h> // for mmap / munmap
#include <dirent.h>
#include <utime.h>

#include <SDL2/SDL.h>
#define CONFIG_USE_SDL

#define _LINUX // for GameSpy

#if !defined(__INTEL_COMPILER)
#define _alloca alloca
#endif

#define _MAX_PATH PATH_MAX + 1
#define MAX_PATH PATH_MAX + 1

#define WINAPI

#define _copysign copysign

#define _cdecl //__attribute__((cdecl))
#define _stdcall //__attribute__((stdcall))
#define _fastcall //__attribute__((fastcall))

#define __cdecl
#define __stdcall
#define __fastcall
//#define __declspec
#define __forceinline FORCE_INLINE
#define __pragma
#define __declspec(x)
#define CALLBACK

/*
static inline long InterlockedExchange(volatile long *val, long new_val)
{
long old_val;
do {
old_val = *val;
} while (__sync_val_compare_and_swap (val, old_val, new_val) != old_val);
return old_val;
}
*/
//TODO: Implement more platform independend atomic operations: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/Common/Atomic_GCC.h
inline void InterlockedExchange(volatile unsigned int& target, unsigned int value)
{
__sync_add_and_fetch(&target, value);
}

inline pthread_t GetCurrentThreadId()
{
return pthread_self();
}

inline void Sleep(int ms)
{
SDL_Delay(ms);
}

inline void _splitpath (
const char *path, // Path Input
char *drive, // Drive : Output
char *dir, // Directory : Output
char *fname, // Filename : Output
char *ext // Extension : Output
){}

inline unsigned long GetLastError()
{
return 0;
}

#define xr_unlink unlink

typedef int BOOL;
typedef char* LPSTR;
typedef char* PSTR;
typedef char* LPTSTR;
typedef const char* LPCSTR;
typedef const char* LPCTSTR;
typedef unsigned char BYTE;
typedef unsigned char* LPBYTE;
typedef unsigned int UINT;
typedef int INT;
typedef long LONG;

typedef unsigned short WORD;
typedef unsigned short* LPWORD;
typedef unsigned long DWORD;
typedef unsigned long* LPDWORD;
typedef const void *LPCVOID;

#define WAVE_FORMAT_PCM 0x0001

typedef struct {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX;

typedef struct _EXCEPTION_POINTERS {
} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;

#ifdef XR_X64
typedef int64_t INT_PTR;
typedef uint16_t UINT_PTR;
typedef int64_t LONG_PTR;
#else
typedef int INT_PTR;
typedef unsigned int UINT_PTR;
typedef long LONG_PTR;
#endif // XR_X64

typedef void *HANDLE;
typedef void *HMODULE;
typedef void *LPVOID;
typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef long HRESULT;
typedef long LRESULT;
typedef long _W64;
//typedef void *HWND;
typedef SDL_Window *HWND;
typedef void *HDC;
//typedef void *HGLRC;
typedef SDL_GLContext HGLRC;
typedef float FLOAT;
typedef unsigned char UINT8;

typedef struct _RECT {
long left;
long top;
long right;
long bottom;
} RECT, *PRECT;

typedef struct tagPOINT {
long x;
long y;
} POINT, *PPOINT, *LPPOINT;

#define WM_USER 0x0400

#define TRUE 1
#define FALSE 0
#define NONE 0
#define CONST const

typedef dirent DirEntryType;

#define _O_WRONLY O_WRONLY
#define _O_RDONLY O_RDONLY
#define _O_TRUNC O_TRUNC
#define _O_CREAT O_CREAT
#define _S_IWRITE S_IWRITE
#define _S_IREAD S_IREAD
#define _O_BINARY 0
#define O_BINARY 0
#define O_SEQUENTIAL 0
#define SH_DENYWR 0

#define _stricmp stricmp
#define strcmpi stricmp
#define stricmp strcasecmp
#define strncpy_s(dest, size, source, num) strncpy(dest, source, num)
#define strcpy_s(dest, num, source) strcpy(dest, source)
#define _vsnprintf vsnprintf
#define _alloca alloca
#define _snprintf snprintf
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) sprintf(buffer, stringbuffer, ##__VA_ARGS__)
#define GetProcAddress(handle, name) dlsym(handle, name)
#define _chdir chdir
#define _strnicmp strnicmp
#define strnicmp strncasecmp
#define _getcwd getcwd
#define _snwprintf swprintf
#define swprintf_s swprintf
#define wcsicmp _wcsicmp
#define _wcsicmp wcscmp
#define _tempnam tempnam
#define _unlink unlink
#define _access access
#define _open open
#define _close close
#define _sopen open
#define _sopen_s(handle, filename, ...) open(filename, O_RDONLY)
#define _fdopen fdopen
#define _rmdir rmdir
#define _write write
#define _strupr strupr
#define _read read
#define _set_new_handler std::set_new_handler
#define _finite isfinite
#define _mkdir(dir) mkdir(dir, S_IRWXU)
#define _wtoi(arg) wcstol(arg, NULL, 10)
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
#undef min
#undef max
#define __max(a, b) std::max(a, b)
#define __min(a, b) std::min(a, b)

#define ZeroMemory(p, sz) memset((p), 0, (sz))
#define CopyMemory(d, s, n) memcpy(d, s, n)

#define RGB(r,g,b) ( ((DWORD)(BYTE)r)|((DWORD)((BYTE)g)<<8)|((DWORD)((BYTE)b)<<16) )
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#define FAILED(hr) (((HRESULT)(hr)) < 0)
#define S_OK 0x00000000
#define S_FALSE 0x10000000
#define E_FAIL 0x80004005

#define STUBBED(txt) do { \
static bool already_seen = false; \
if (!already_seen) { \
already_seen = true; \
fprintf(stderr, "STUBBED: %s in %s, line %d.\n", txt, __FILE__, __LINE__); \
} \
} while (0)
2 changes: 2 additions & 0 deletions src/Common/PlatformWindows.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define DOSWIN32
#define _WIN32_DCOM

#define STUBBED(txt) do {} while (0)

#pragma warning(push)
#pragma warning(disable : 4005) // macro redefinition
#include <windows.h>
Expand Down

0 comments on commit afddd9c

Please sign in to comment.