1 | /*****************************************************************************\ |
2 | Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. |
3 | This file is licensed under the Snes9x License. |
4 | For further information, consult the LICENSE file in the root directory. |
5 | \*****************************************************************************/ |
6 | |
7 | #ifndef _PORT_H_ |
8 | #define _PORT_H_ |
9 | |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | #include <stdarg.h> |
13 | #include <limits.h> |
14 | #ifndef __LIBRETRO__ |
15 | #include <memory.h> |
16 | #endif |
17 | #include <time.h> |
18 | #include <string.h> |
19 | #ifdef HAVE_STRINGS_H |
20 | #include <strings.h> |
21 | #endif |
22 | #include <sys/types.h> |
23 | |
24 | #ifdef __WIN32__ |
25 | #define NOMINMAX 1 |
26 | #include <windows.h> |
27 | #endif |
28 | |
29 | #ifdef __WIN32__ |
30 | //#define RIGHTSHIFT_IS_SAR |
31 | #define RIGHTSHIFT_int8_IS_SAR |
32 | #define RIGHTSHIFT_int16_IS_SAR |
33 | #define RIGHTSHIFT_int32_IS_SAR |
34 | #ifndef __LIBRETRO__ |
35 | #define SNES_JOY_READ_CALLBACKS |
36 | #endif //__LIBRETRO__ |
37 | #endif |
38 | |
39 | #ifdef __MACOSX__ |
40 | #define PIXEL_FORMAT RGB555 |
41 | #endif |
42 | |
43 | #ifndef PIXEL_FORMAT |
44 | #define PIXEL_FORMAT RGB565 |
45 | #endif |
46 | |
47 | #if defined(__GNUC__) |
48 | #define alwaysinline inline __attribute__((always_inline)) |
49 | #elif defined(_MSC_VER) |
50 | #define alwaysinline __forceinline |
51 | #else |
52 | #define alwaysinline inline |
53 | #endif |
54 | |
55 | #ifndef snes9x_types_defined |
56 | #define snes9x_types_defined |
57 | typedef unsigned char bool8; |
58 | #ifdef HAVE_STDINT_H |
59 | #include <stdint.h> |
60 | typedef intptr_t pint; |
61 | typedef int8_t int8; |
62 | typedef uint8_t uint8; |
63 | typedef int16_t int16; |
64 | typedef uint16_t uint16; |
65 | typedef int32_t int32; |
66 | typedef uint32_t uint32; |
67 | typedef int64_t int64; |
68 | typedef uint64_t uint64; |
69 | #else // HAVE_STDINT_H |
70 | #ifdef __WIN32__ |
71 | typedef intptr_t pint; |
72 | typedef signed char int8; |
73 | typedef unsigned char uint8; |
74 | typedef signed short int16; |
75 | typedef unsigned short uint16; |
76 | typedef signed int int32; |
77 | typedef unsigned int uint32; |
78 | typedef signed __int64 int64; |
79 | typedef unsigned __int64 uint64; |
80 | typedef int8 int8_t; |
81 | typedef uint8 uint8_t; |
82 | typedef int16 int16_t; |
83 | typedef uint16 uint16_t; |
84 | typedef int32 int32_t; |
85 | typedef uint32 uint32_t; |
86 | typedef int64 int64_t; |
87 | typedef uint64 uint64_t; |
88 | typedef int socklen_t; |
89 | #else // __WIN32__ |
90 | typedef signed char int8; |
91 | typedef unsigned char uint8; |
92 | typedef signed short int16; |
93 | typedef unsigned short uint16; |
94 | typedef signed int int32; |
95 | typedef unsigned int uint32; |
96 | #ifdef __GNUC__ |
97 | // long long is not part of ISO C++ |
98 | __extension__ |
99 | #endif |
100 | typedef long long int64; |
101 | typedef unsigned long long uint64; |
102 | #ifdef PTR_NOT_INT |
103 | typedef size_t pint; |
104 | #else // __PTR_NOT_INT |
105 | typedef size_t pint; |
106 | #endif // __PTR_NOT_INT |
107 | #endif // __WIN32__ |
108 | #endif // HAVE_STDINT_H |
109 | #endif // snes9x_types_defined |
110 | |
111 | #ifndef TRUE |
112 | #define TRUE 1 |
113 | #endif |
114 | #ifndef FALSE |
115 | #define FALSE 0 |
116 | #endif |
117 | |
118 | #define START_EXTERN_C extern "C" { |
119 | #define END_EXTERN_C } |
120 | |
121 | #ifndef __WIN32__ |
122 | #ifndef PATH_MAX |
123 | #define PATH_MAX 1024 |
124 | #endif |
125 | #define _MAX_DRIVE 1 |
126 | #define _MAX_DIR PATH_MAX |
127 | #define _MAX_FNAME PATH_MAX |
128 | #define _MAX_EXT PATH_MAX |
129 | #define _MAX_PATH PATH_MAX |
130 | #else |
131 | #ifndef PATH_MAX |
132 | #define PATH_MAX _MAX_PATH |
133 | #endif |
134 | #endif |
135 | |
136 | #ifndef __WIN32__ |
137 | void _splitpath (const char *, char *, char *, char *, char *); |
138 | void _makepath (char *, const char *, const char *, const char *, const char *); |
139 | #define S9xDisplayString DisplayStringFromBottom |
140 | #else // __WIN32__ |
141 | #define snprintf _snprintf |
142 | #define strcasecmp stricmp |
143 | #define strncasecmp strnicmp |
144 | #ifndef __LIBRETRO__ |
145 | void WinDisplayStringFromBottom(const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap); |
146 | #define S9xDisplayString WinDisplayStringFromBottom |
147 | void SetInfoDlgColor(unsigned char, unsigned char, unsigned char); |
148 | #define SET_UI_COLOR(r,g,b) SetInfoDlgColor(r,g,b) |
149 | #else // __LIBRETRO__ |
150 | #define S9xDisplayString DisplayStringFromBottom |
151 | #endif // __LIBRETRO__ |
152 | #endif // __WIN32__ |
153 | |
154 | inline void sstrncpy(char *dst, const char *src, size_t size) |
155 | { |
156 | strncpy(dst, src, size - 1); |
157 | dst[size - 1] = '\0'; |
158 | } |
159 | |
160 | #if defined(__DJGPP) || defined(__WIN32__) |
161 | #define SLASH_STR "\\" |
162 | #define SLASH_CHAR '\\' |
163 | #else |
164 | #define SLASH_STR "/" |
165 | #define SLASH_CHAR '/' |
166 | #endif |
167 | |
168 | #ifndef SIG_PF |
169 | #define SIG_PF void (*) (int) |
170 | #endif |
171 | |
172 | #ifdef __linux |
173 | #define TITLE "Snes9x: Linux" |
174 | #define SYS_CONFIG_FILE "/etc/snes9x/snes9x.conf" |
175 | #endif |
176 | |
177 | #ifndef TITLE |
178 | #define TITLE "Snes9x" |
179 | #endif |
180 | |
181 | #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__x86_64__) || defined(__alpha__) || defined(__MIPSEL__) || defined(_M_IX86) || defined(_M_X64) || defined(_XBOX1) || defined(__arm__) || defined(ANDROID) || defined(__aarch64__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__) |
182 | #define LSB_FIRST |
183 | #define FAST_LSB_WORD_ACCESS |
184 | #else |
185 | #define MSB_FIRST |
186 | #endif |
187 | |
188 | #ifdef FAST_LSB_WORD_ACCESS |
189 | #define READ_WORD(s) (*(uint16 *) (s)) |
190 | #define READ_3WORD(s) (*(uint32 *) (s) & 0x00ffffff) |
191 | #define READ_DWORD(s) (*(uint32 *) (s)) |
192 | #define WRITE_WORD(s, d) *(uint16 *) (s) = (d) |
193 | #define WRITE_3WORD(s, d) *(uint16 *) (s) = (uint16) (d), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16) |
194 | #define WRITE_DWORD(s, d) *(uint32 *) (s) = (d) |
195 | #else |
196 | #define READ_WORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8)) |
197 | #define READ_3WORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8) | (*((uint8 *) (s) + 2) << 16)) |
198 | #define READ_DWORD(s) (*(uint8 *) (s) | (*((uint8 *) (s) + 1) << 8) | (*((uint8 *) (s) + 2) << 16) | (*((uint8 *) (s) + 3) << 24)) |
199 | #define WRITE_WORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8) |
200 | #define WRITE_3WORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16) |
201 | #define WRITE_DWORD(s, d) *(uint8 *) (s) = (uint8) (d), *((uint8 *) (s) + 1) = (uint8) ((d) >> 8), *((uint8 *) (s) + 2) = (uint8) ((d) >> 16), *((uint8 *) (s) + 3) = (uint8) ((d) >> 24) |
202 | #endif |
203 | |
204 | #define SWAP_WORD(s) (s) = (((s) & 0xff) << 8) | (((s) & 0xff00) >> 8) |
205 | #define SWAP_DWORD(s) (s) = (((s) & 0xff) << 24) | (((s) & 0xff00) << 8) | (((s) & 0xff0000) >> 8) | (((s) & 0xff000000) >> 24) |
206 | |
207 | #include "pixform.h" |
208 | |
209 | #endif |
210 | |