summaryrefslogtreecommitdiff
path: root/src/common/platform.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/platform.h')
-rw-r--r--src/common/platform.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/common/platform.h b/src/common/platform.h
new file mode 100644
index 000000000..84c6b6365
--- /dev/null
+++ b/src/common/platform.h
@@ -0,0 +1,142 @@
1/**
2 * Copyright (C) 2005-2012 Gekko Emulator
3 *
4 * @file platform.h
5 * @author ShizZy <shizzy247@gmail.com>
6 * @date 2012-02-11
7 * @brief Platform detection macros for portable compilation
8 *
9 * @section LICENSE
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details at
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * Official project repository can be found at:
22 * http://code.google.com/p/gekko-gc-emu/
23 */
24
25#ifndef COMMON_PLATFORM_H_
26#define COMMON_PLATFORM_H_
27
28#include "common_types.h"
29
30////////////////////////////////////////////////////////////////////////////////////////////////////
31// Platform definitions
32
33/// Enumeration for defining the supported platforms
34#define PLATFORM_NULL 0
35#define PLATFORM_WINDOWS 1
36#define PLATFORM_MACOSX 2
37#define PLATFORM_LINUX 3
38#define PLATFORM_ANDROID 4
39#define PLATFORM_IOS 5
40
41////////////////////////////////////////////////////////////////////////////////////////////////////
42// Platform detection
43
44#ifndef EMU_PLATFORM
45
46#if defined( __WIN32__ ) || defined( _WIN32 )
47#define EMU_PLATFORM PLATFORM_WINDOWS
48
49#elif defined( __APPLE__ ) || defined( __APPLE_CC__ )
50#define EMU_PLATFORM PLATFORM_MAXOSX
51
52#elif defined(__linux__)
53#define EMU_PLATFORM PLATFORM_LINUX
54
55#else // Assume linux otherwise
56#define EMU_PLATFORM PLATFORM_LINUX
57
58#endif
59
60#endif
61
62#if defined(__x86_64__) || defined(_M_X64) || defined(__alpha__) || defined(__ia64__)
63#define EMU_ARCHITECTURE_X64
64#else
65#define EMU_ARCHITECTURE_X86
66#endif
67
68////////////////////////////////////////////////////////////////////////////////////////////////////
69// Compiler-Specific Definitions
70
71#if EMU_PLATFORM == PLATFORM_WINDOWS
72
73#include <time.h>
74
75#define NOMINMAX
76#define EMU_FASTCALL __fastcall
77
78inline struct tm* localtime_r(const time_t *clock, struct tm *result) {
79 if (localtime_s(result, clock) == 0)
80 return result;
81 return NULL;
82}
83
84#else
85
86#define EMU_FASTCALL __attribute__((fastcall))
87#define __stdcall
88#define __cdecl
89
90#define LONG long
91#define BOOL bool
92#define DWORD u32
93
94#endif
95
96#if EMU_PLATFORM != PLATFORM_WINDOWS
97
98// TODO: Hacks..
99#include <limits.h>
100#define MAX_PATH PATH_MAX
101
102#include <strings.h>
103#define stricmp(str1, str2) strcasecmp(str1, str2)
104#define _stricmp(str1, str2) strcasecmp(str1, str2)
105#define _snprintf snprintf
106#define _getcwd getcwd
107#define _tzset tzset
108
109typedef void EXCEPTION_POINTERS;
110
111inline u32 _rotl(u32 x, int shift) {
112 shift &= 31;
113 if (0 == shift) {
114 return x;
115 }
116 return (x << shift) | (x >> (32 - shift));
117}
118
119inline u64 _rotl64(u64 x, u32 shift){
120 u32 n = shift % 64;
121 return (x << n) | (x >> (64 - n));
122}
123
124inline u32 _rotr(u32 x, int shift) {
125 shift &= 31;
126 if (0 == shift) {
127 return x;
128 }
129 return (x >> shift) | (x << (32 - shift));
130}
131
132inline u64 _rotr64(u64 x, u32 shift){
133 u32 n = shift % 64;
134 return (x >> n) | (x << (64 - n));
135}
136
137#endif
138
139#define GCC_VERSION_AVAILABLE(major, minor) (defined(__GNUC__) && (__GNUC__ > (major) || \
140 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
141
142#endif // COMMON_PLATFORM_H_