common.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  30. #define _CRT_SECURE_NO_WARNINGS
  31. #endif
  32. #include <wchar.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <time.h>
  37. #include <limits.h>
  38. #include <stdarg.h>
  39. #include <assert.h>
  40. #include "SDL.h"
  41. #include "SDL_endian.h"
  42. #ifdef _SDL_stdinc_h
  43. #define malloc SDL_malloc
  44. #define calloc SDL_calloc
  45. #define free SDL_free
  46. #define realloc SDL_realloc
  47. #endif
  48. #if SDL_VERSION_ATLEAST(2,0,0)
  49. #define SDLK_KP1 SDLK_KP_1
  50. #define SDLK_KP2 SDLK_KP_2
  51. #define SDLK_KP3 SDLK_KP_3
  52. #define SDLK_KP4 SDLK_KP_4
  53. #define SDLK_KP5 SDLK_KP_5
  54. #define SDLK_KP6 SDLK_KP_6
  55. #define SDLK_KP7 SDLK_KP_7
  56. #define SDLK_KP8 SDLK_KP_8
  57. #define SDLK_KP9 SDLK_KP_9
  58. #define SDLK_KP0 SDLK_KP_0
  59. #define SDL_HWSURFACE 0
  60. #endif
  61. #ifndef max
  62. #define max(a, b) (((a) > (b)) ? (a) : (b))
  63. #endif
  64. #ifndef min
  65. #define min(a, b) (((a) < (b)) ? (a) : (b))
  66. #endif
  67. /* This is need when compiled with SDL 1.2 */
  68. #ifndef SDL_FORCE_INLINE
  69. #if defined(_MSC_VER)
  70. #define SDL_FORCE_INLINE __forceinline
  71. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  72. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  73. #else
  74. #define SDL_FORCE_INLINE static SDL_INLINE
  75. #endif
  76. #endif /* SDL_FORCE_INLINE not defined */
  77. #if defined(_MSC_VER)
  78. #define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  79. #else
  80. #define PAL_FORCE_INLINE SDL_FORCE_INLINE
  81. #endif
  82. #if defined (__SYMBIAN32__)
  83. #undef _WIN32
  84. #undef SDL_INIT_JOYSTICK
  85. #define SDL_INIT_JOYSTICK 0
  86. #define PAL_HAS_MOUSE 1
  87. #define PAL_PREFIX "e:/data/pal/"
  88. #define PAL_SAVE_PREFIX "e:/data/pal/"
  89. # ifdef __S60_5X__
  90. # define PAL_DEFAULT_WINDOW_WIDTH 640
  91. # define PAL_DEFAULT_WINDOW_HEIGHT 360
  92. # else
  93. # define PAL_DEFAULT_WINDOW_WIDTH 320
  94. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  95. # endif
  96. # if SDL_VERSION_ATLEAST(2,0,0)
  97. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  98. # else
  99. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  100. # endif
  101. #elif defined (GEKKO)
  102. #define PAL_HAS_JOYSTICKS 1
  103. #define PAL_HAS_MOUSE 0
  104. #define PAL_PREFIX "SD:/apps/sdlpal/"
  105. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  106. #define PAL_DEFAULT_WINDOW_WIDTH 640
  107. #define PAL_DEFAULT_WINDOW_HEIGHT 480
  108. # if SDL_VERSION_ATLEAST(2,0,0)
  109. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  110. # else
  111. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  112. # endif
  113. #elif defined (PSP)
  114. #define PAL_HAS_JOYSTICKS 0
  115. #define PAL_PREFIX "ms0:/"
  116. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  117. #define PAL_DEFAULT_WINDOW_WIDTH 320
  118. #define PAL_DEFAULT_WINDOW_HEIGHT 240
  119. # if SDL_VERSION_ATLEAST(2,0,0)
  120. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  121. # else
  122. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  123. # endif
  124. #elif defined(GPH) || defined(DINGOO)
  125. #define PAL_PREFIX "./"
  126. #define PAL_SAVE_PREFIX "./"
  127. # define PAL_DEFAULT_WINDOW_WIDTH 320
  128. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  129. # if SDL_VERSION_ATLEAST(2,0,0)
  130. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  131. # else
  132. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  133. # endif
  134. #elif defined(NDS)
  135. #define PAL_PREFIX "./"
  136. #define PAL_SAVE_PREFIX "./"
  137. # define PAL_DEFAULT_WINDOW_WIDTH 293
  138. # define PAL_DEFAULT_WINDOW_HEIGHT 196
  139. # if SDL_VERSION_ATLEAST(2,0,0)
  140. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  141. # else
  142. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  143. # endif
  144. #elif defined (__IOS__)
  145. #define PAL_PREFIX UTIL_BasePath()
  146. #define PAL_SAVE_PREFIX UTIL_SavePath()
  147. #define PAL_HAS_TOUCH 1
  148. #define PAL_DEFAULT_WINDOW_WIDTH 320
  149. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  150. # if SDL_VERSION_ATLEAST(2,0,0)
  151. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  152. # else
  153. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  154. # endif
  155. #elif defined (__ANDROID__)
  156. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  157. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  158. #define PAL_HAS_TOUCH 1
  159. #define PAL_DEFAULT_WINDOW_WIDTH 320
  160. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  161. # if SDL_VERSION_ATLEAST(2,0,0)
  162. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  163. # else
  164. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  165. # endif
  166. #elif defined (__WINPHONE__)
  167. #define PAL_PREFIX UTIL_BasePath()
  168. #define PAL_SAVE_PREFIX UTIL_SavePath()
  169. #define PAL_HAS_TOUCH 1
  170. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 4096
  171. #define PAL_DEFAULT_WINDOW_WIDTH 320
  172. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  173. # if SDL_VERSION_ATLEAST(2,0,0)
  174. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  175. # else
  176. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  177. # endif
  178. #else
  179. #define PAL_HAS_JOYSTICKS 1
  180. #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  181. # define PAL_ALLOW_KEYREPEAT 1
  182. # define PAL_HAS_SDLCD 1
  183. #endif
  184. #define PAL_PREFIX "./"
  185. #define PAL_SAVE_PREFIX "./"
  186. #define PAL_DEFAULT_WINDOW_WIDTH 640
  187. #define PAL_DEFAULT_WINDOW_HEIGHT 400
  188. #define PAL_DEFAULT_FULLSCREEN_HEIGHT 480
  189. # if SDL_VERSION_ATLEAST(2,0,0)
  190. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  191. # else
  192. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  193. # endif
  194. #endif
  195. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  196. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  197. #endif
  198. /* Default for 1024 samples */
  199. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  200. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  201. #endif
  202. #ifndef PAL_HAS_SDLCD
  203. #define PAL_HAS_SDLCD 0
  204. #endif
  205. #define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  206. #define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  207. #define PAL_HAS_MAME 1 /* Should not be enabled for now, until M.A.M.E goes open source licenses */
  208. #ifndef SDL_INIT_CDROM
  209. #define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  210. #endif
  211. #ifndef SDL_AUDIO_BITSIZE
  212. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  213. #endif
  214. #ifdef _WIN32
  215. #include <windows.h>
  216. #if !defined(__BORLANDC__)
  217. #include <io.h>
  218. #endif
  219. #if defined(_MSC_VER)
  220. # if _MSC_VER < 1900
  221. # define vsnprintf _vsnprintf
  222. # endif
  223. # pragma warning (disable:4244)
  224. #endif
  225. #ifndef _LPCBYTE_DEFINED
  226. #define _LPCBYTE_DEFINED
  227. typedef const BYTE *LPCBYTE;
  228. #endif
  229. #ifndef __WINPHONE__
  230. #define PAL_HAS_NATIVEMIDI 1
  231. #endif
  232. #else
  233. #include <unistd.h>
  234. #include <dirent.h>
  235. #ifndef FALSE
  236. #define FALSE 0
  237. #endif
  238. #ifndef TRUE
  239. #define TRUE 1
  240. #endif
  241. #define VOID void
  242. typedef char CHAR;
  243. typedef wchar_t WCHAR;
  244. typedef short SHORT;
  245. typedef long LONG;
  246. typedef unsigned long ULONG, *PULONG;
  247. typedef unsigned short USHORT, *PUSHORT;
  248. typedef unsigned char UCHAR, *PUCHAR;
  249. typedef unsigned short WORD, *LPWORD;
  250. typedef unsigned int DWORD, *LPDWORD;
  251. typedef int INT, *LPINT;
  252. #ifndef __OBJC__
  253. typedef int BOOL, *LPBOOL;
  254. #endif
  255. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  256. typedef unsigned char BYTE, *LPBYTE;
  257. typedef const BYTE *LPCBYTE;
  258. typedef float FLOAT, *LPFLOAT;
  259. typedef void *LPVOID;
  260. typedef const void *LPCVOID;
  261. typedef CHAR *LPSTR;
  262. typedef const CHAR *LPCSTR;
  263. typedef WCHAR *LPWSTR;
  264. typedef const WCHAR *LPCWSTR;
  265. #endif
  266. #ifndef PAL_HAS_NATIVEMIDI
  267. #define PAL_HAS_NATIVEMIDI 0
  268. #endif
  269. #if defined (__SYMBIAN32__)
  270. #define PAL_LARGE static
  271. #else
  272. #define PAL_LARGE /* */
  273. #endif
  274. #define __WIDETEXT(quote) L##quote
  275. #define WIDETEXT(quote) __WIDETEXT(quote)
  276. // For SDL 1.2 compatibility
  277. #ifndef SDL_TICKS_PASSED
  278. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  279. #endif
  280. #define PAL_DelayUntil(t) \
  281. PAL_ProcessEvent(); \
  282. while (!SDL_TICKS_PASSED(SDL_GetTicks(), (t))) \
  283. { \
  284. PAL_ProcessEvent(); \
  285. SDL_Delay(1); \
  286. }
  287. typedef enum tagCODEPAGE {
  288. CP_UNKNOWN = -1,
  289. CP_MIN = 0,
  290. CP_BIG5 = 0,
  291. CP_GBK = 1,
  292. CP_SHIFTJIS = 2,
  293. CP_MAX = 3,
  294. CP_UTF_8 = CP_MAX + 1
  295. } CODEPAGE;
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif