common.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. //
  5. // This file is part of SDLPAL.
  6. //
  7. // SDLPAL is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. // Modified by Lou Yihua <louyihua@21cn.com> with Unicode support, 2015
  21. //
  22. #ifndef _COMMON_H
  23. #define _COMMON_H
  24. #define PAL_CLASSIC 1
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #include <wchar.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <limits.h>
  35. #include <stdarg.h>
  36. #include <assert.h>
  37. #include "SDL.h"
  38. #include "SDL_endian.h"
  39. #ifdef _SDL_stdinc_h
  40. #define malloc SDL_malloc
  41. #define calloc SDL_calloc
  42. #define free SDL_free
  43. #define realloc SDL_realloc
  44. #endif
  45. #if SDL_VERSION_ATLEAST(2,0,0)
  46. #define SDLK_KP1 SDLK_KP_1
  47. #define SDLK_KP2 SDLK_KP_2
  48. #define SDLK_KP3 SDLK_KP_3
  49. #define SDLK_KP4 SDLK_KP_4
  50. #define SDLK_KP5 SDLK_KP_5
  51. #define SDLK_KP6 SDLK_KP_6
  52. #define SDLK_KP7 SDLK_KP_7
  53. #define SDLK_KP8 SDLK_KP_8
  54. #define SDLK_KP9 SDLK_KP_9
  55. #define SDLK_KP0 SDLK_KP_0
  56. #define SDL_HWSURFACE 0
  57. #endif
  58. #ifndef max
  59. #define max(a, b) (((a) > (b)) ? (a) : (b))
  60. #endif
  61. #ifndef min
  62. #define min(a, b) (((a) < (b)) ? (a) : (b))
  63. #endif
  64. /* This is need when compiled with SDL 1.2 */
  65. #ifndef SDL_FORCE_INLINE
  66. #if defined(_MSC_VER)
  67. #define SDL_FORCE_INLINE __forceinline
  68. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  69. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  70. #else
  71. #define SDL_FORCE_INLINE static SDL_INLINE
  72. #endif
  73. #endif /* SDL_FORCE_INLINE not defined */
  74. #if defined(_MSC_VER)
  75. #define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  76. #else
  77. #define PAL_FORCE_INLINE SDL_FORCE_INLINE
  78. #endif
  79. #if defined (__SYMBIAN32__)
  80. #undef _WIN32
  81. #undef SDL_INIT_JOYSTICK
  82. #define SDL_INIT_JOYSTICK 0
  83. #define PAL_HAS_MOUSE 1
  84. #define PAL_PREFIX "e:/data/pal/"
  85. #define PAL_SAVE_PREFIX "e:/data/pal/"
  86. #elif defined (GEKKO)
  87. #define PAL_HAS_JOYSTICKS 1
  88. #define PAL_HAS_MOUSE 0
  89. #define PAL_PREFIX "SD:/apps/sdlpal/"
  90. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  91. #elif defined (PSP)
  92. #define PAL_HAS_JOYSTICKS 0
  93. #define PAL_PREFIX "ms0:/"
  94. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  95. #elif defined (__IOS__)
  96. #define PAL_PREFIX UTIL_IOS_BasePath()
  97. #define PAL_SAVE_PREFIX UTIL_IOS_SavePath()
  98. #define PAL_HAS_TOUCH 1
  99. #elif defined (__ANDROID__)
  100. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  101. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  102. #define PAL_HAS_TOUCH 1
  103. #elif defined (__WINPHONE__)
  104. #define PAL_PREFIX "Assets\\Data\\"
  105. #define PAL_SAVE_PREFIX "" // ???
  106. #define PAL_HAS_TOUCH 1
  107. #include <stdio.h>
  108. #ifdef __cplusplus
  109. #include <cstdio>
  110. #endif
  111. FILE *MY_fopen(const char *path, const char *mode);
  112. #define fopen MY_fopen
  113. #else
  114. # define PAL_HAS_JOYSTICKS 1
  115. # ifndef _WIN32_WCE
  116. # if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  117. # define PAL_ALLOW_KEYREPEAT 1
  118. # define PAL_HAS_SDLCD 1
  119. # endif
  120. # ifndef PAL_PREFIX
  121. # define PAL_PREFIX "./"
  122. # endif
  123. # ifndef PAL_SAVE_PREFIX
  124. # define PAL_SAVE_PREFIX "./"
  125. # endif
  126. # endif
  127. //# if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH)
  128. //# define PAL_HAS_MP3 1
  129. //# endif
  130. #endif
  131. #ifndef PAL_HAS_SDLCD
  132. #define PAL_HAS_SDLCD 0
  133. #endif
  134. #define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  135. #define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  136. #define PAL_HAS_MAME 1 /* Should not be enabled for now, until M.A.M.E goes open source licenses */
  137. #ifndef SDL_INIT_CDROM
  138. #define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  139. #endif
  140. #ifndef SDL_AUDIO_BITSIZE
  141. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  142. #endif
  143. #ifdef _WIN32
  144. #include <windows.h>
  145. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  146. #include <io.h>
  147. #endif
  148. #if defined(_MSC_VER) && _MSC_VER < 1900
  149. #define vsnprintf _vsnprintf
  150. #endif
  151. #ifdef _MSC_VER
  152. #pragma warning (disable:4244)
  153. #pragma warning (disable:4996)
  154. #endif
  155. #ifndef _LPCBYTE_DEFINED
  156. #define _LPCBYTE_DEFINED
  157. typedef const BYTE *LPCBYTE;
  158. #endif
  159. #ifndef __WINPHONE__
  160. #define PAL_HAS_NATIVEMIDI 1
  161. #endif
  162. #else
  163. #include <unistd.h>
  164. #ifndef FALSE
  165. #define FALSE 0
  166. #endif
  167. #ifndef TRUE
  168. #define TRUE 1
  169. #endif
  170. #define VOID void
  171. typedef char CHAR;
  172. typedef wchar_t WCHAR;
  173. typedef short SHORT;
  174. typedef long LONG;
  175. typedef unsigned long ULONG, *PULONG;
  176. typedef unsigned short USHORT, *PUSHORT;
  177. typedef unsigned char UCHAR, *PUCHAR;
  178. typedef unsigned short WORD, *LPWORD;
  179. typedef unsigned int DWORD, *LPDWORD;
  180. typedef int INT, *LPINT;
  181. #ifndef __OBJC__
  182. typedef int BOOL, *LPBOOL;
  183. #endif
  184. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  185. typedef unsigned char BYTE, *LPBYTE;
  186. typedef const BYTE *LPCBYTE;
  187. typedef float FLOAT, *LPFLOAT;
  188. typedef void *LPVOID;
  189. typedef const void *LPCVOID;
  190. typedef CHAR *LPSTR;
  191. typedef const CHAR *LPCSTR;
  192. typedef WCHAR *LPWSTR;
  193. typedef const WCHAR *LPCWSTR;
  194. #endif
  195. #ifndef PAL_HAS_NATIVEMIDI
  196. #define PAL_HAS_NATIVEMIDI 0
  197. #endif
  198. #if defined (__SYMBIAN32__)
  199. #define PAL_LARGE static
  200. #else
  201. #define PAL_LARGE /* */
  202. #endif
  203. #define __WIDETEXT(quote) L##quote
  204. #define WIDETEXT(quote) __WIDETEXT(quote)
  205. typedef enum tagCODEPAGE {
  206. CP_UNKNOWN = -1,
  207. CP_MIN = 0,
  208. CP_BIG5 = 0,
  209. CP_GBK = 1,
  210. CP_SHIFTJIS = 2,
  211. CP_MAX = 3
  212. } CODEPAGE;
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif