common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. // Modified by Lou Yihua <louyihua@21cn.com> with unicode support, 2015.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #ifndef _COMMON_H
  22. #define _COMMON_H
  23. #define PAL_CLASSIC 1
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  29. #define _CRT_SECURE_NO_WARNINGS
  30. #endif
  31. #include <wchar.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include <limits.h>
  37. #include <stdarg.h>
  38. #include <assert.h>
  39. #include "SDL.h"
  40. #include "SDL_endian.h"
  41. #ifdef _SDL_stdinc_h
  42. #define malloc SDL_malloc
  43. #define calloc SDL_calloc
  44. #define free SDL_free
  45. #define realloc SDL_realloc
  46. #endif
  47. #if SDL_VERSION_ATLEAST(2,0,0)
  48. #define SDLK_KP1 SDLK_KP_1
  49. #define SDLK_KP2 SDLK_KP_2
  50. #define SDLK_KP3 SDLK_KP_3
  51. #define SDLK_KP4 SDLK_KP_4
  52. #define SDLK_KP5 SDLK_KP_5
  53. #define SDLK_KP6 SDLK_KP_6
  54. #define SDLK_KP7 SDLK_KP_7
  55. #define SDLK_KP8 SDLK_KP_8
  56. #define SDLK_KP9 SDLK_KP_9
  57. #define SDLK_KP0 SDLK_KP_0
  58. #define SDL_HWSURFACE 0
  59. #endif
  60. #ifndef max
  61. #define max(a, b) (((a) > (b)) ? (a) : (b))
  62. #endif
  63. #ifndef min
  64. #define min(a, b) (((a) < (b)) ? (a) : (b))
  65. #endif
  66. /* This is need when compiled with SDL 1.2 */
  67. #ifndef SDL_FORCE_INLINE
  68. #if defined(_MSC_VER)
  69. #define SDL_FORCE_INLINE __forceinline
  70. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  71. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  72. #else
  73. #define SDL_FORCE_INLINE static SDL_INLINE
  74. #endif
  75. #endif /* SDL_FORCE_INLINE not defined */
  76. #if defined(_MSC_VER)
  77. #define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  78. #else
  79. #define PAL_FORCE_INLINE SDL_FORCE_INLINE
  80. #endif
  81. #if defined (__SYMBIAN32__)
  82. #undef _WIN32
  83. #undef SDL_INIT_JOYSTICK
  84. #define SDL_INIT_JOYSTICK 0
  85. #define PAL_HAS_MOUSE 1
  86. #define PAL_PREFIX "e:/data/pal/"
  87. #define PAL_SAVE_PREFIX "e:/data/pal/"
  88. # ifdef __S60_5X__
  89. # define PAL_DEFAULT_WINDOW_WIDTH 640
  90. # define PAL_DEFAULT_WINDOW_HEIGHT 360
  91. # else
  92. # define PAL_DEFAULT_WINDOW_WIDTH 320
  93. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  94. # endif
  95. # if SDL_VERSION_ATLEAST(2,0,0)
  96. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  97. # else
  98. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  99. # endif
  100. # define PAL_PLATFORM " Symbian S60 \x79FB\x690D (c) 2009, netwan."
  101. # define PAL_CREDIT "netwan"
  102. # define PAL_PORTYEAR "2009"
  103. #elif defined (GEKKO)
  104. #define PAL_HAS_JOYSTICKS 1
  105. #define PAL_HAS_MOUSE 0
  106. #define PAL_PREFIX "SD:/apps/sdlpal/"
  107. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  108. #define PAL_DEFAULT_WINDOW_WIDTH 640
  109. #define PAL_DEFAULT_WINDOW_HEIGHT 480
  110. # if SDL_VERSION_ATLEAST(2,0,0)
  111. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  112. # else
  113. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  114. # endif
  115. # define PAL_PLATFORM "Nintendo WII"
  116. # define PAL_CREDIT "Rikku2000"
  117. # define PAL_PORTYEAR "2012"
  118. #elif defined (PSP)
  119. #define PAL_HAS_JOYSTICKS 0
  120. #define PAL_PREFIX "ms0:/"
  121. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  122. #define PAL_DEFAULT_WINDOW_WIDTH 320
  123. #define PAL_DEFAULT_WINDOW_HEIGHT 240
  124. # if SDL_VERSION_ATLEAST(2,0,0)
  125. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  126. # else
  127. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  128. # endif
  129. # define PAL_PLATFORM "Sony PSP"
  130. # define PAL_CREDIT "(Unknown)"
  131. # define PAL_PORTYEAR "2011"
  132. #elif defined(GPH) || defined(DINGOO)
  133. #define PAL_PREFIX "./"
  134. #define PAL_SAVE_PREFIX "./"
  135. # define PAL_DEFAULT_WINDOW_WIDTH 320
  136. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  137. # if SDL_VERSION_ATLEAST(2,0,0)
  138. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  139. # else
  140. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  141. # endif
  142. # if defined(GPH)
  143. # define PAL_PLATFORM "GPH Caanoo & Wiz"
  144. # else
  145. # define PAL_PLATFORM "DINGOO & Dingux"
  146. # endif
  147. # define PAL_CREDIT "Rikku2000"
  148. # define PAL_PORTYEAR "2011"
  149. #elif defined(NDS)
  150. #define PAL_PREFIX "./"
  151. #define PAL_SAVE_PREFIX "./"
  152. # define PAL_DEFAULT_WINDOW_WIDTH 293
  153. # define PAL_DEFAULT_WINDOW_HEIGHT 196
  154. # if SDL_VERSION_ATLEAST(2,0,0)
  155. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  156. # else
  157. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  158. # endif
  159. # define PAL_PLATFORM "Nintendo DS"
  160. # define PAL_CREDIT "(Unknown)"
  161. # define PAL_PORTYEAR "2012"
  162. #elif defined (__IOS__)
  163. #define PAL_PREFIX UTIL_BasePath()
  164. #define PAL_SAVE_PREFIX UTIL_SavePath()
  165. #define PAL_HAS_TOUCH 1
  166. #define PAL_DEFAULT_WINDOW_WIDTH 320
  167. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  168. # if SDL_VERSION_ATLEAST(2,0,0)
  169. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  170. # else
  171. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  172. # endif
  173. # define PAL_PLATFORM "Apple iOS"
  174. # define PAL_CREDIT "(Unknown)"
  175. # define PAL_PORTYEAR "2015"
  176. #elif defined (__ANDROID__)
  177. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  178. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  179. #define PAL_HAS_TOUCH 1
  180. #define PAL_DEFAULT_WINDOW_WIDTH 320
  181. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  182. # if SDL_VERSION_ATLEAST(2,0,0)
  183. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  184. # else
  185. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  186. # endif
  187. # define PAL_PLATFORM "Android"
  188. # define PAL_CREDIT "Rikku2000"
  189. # define PAL_PORTYEAR "2013"
  190. #elif defined (__WINPHONE__)
  191. #define PAL_PREFIX UTIL_BasePath()
  192. #define PAL_SAVE_PREFIX UTIL_SavePath()
  193. #define PAL_HAS_TOUCH 1
  194. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 4096
  195. #define PAL_DEFAULT_WINDOW_WIDTH 320
  196. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  197. # if SDL_VERSION_ATLEAST(2,0,0)
  198. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  199. # else
  200. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  201. # endif
  202. # define PAL_PLATFORM "Windows Phone"
  203. # define PAL_CREDIT "(Unknown)"
  204. # define PAL_PORTYEAR "2015"
  205. #else
  206. #define PAL_HAS_JOYSTICKS 1
  207. #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  208. # define PAL_ALLOW_KEYREPEAT 1
  209. # define PAL_HAS_SDLCD 1
  210. #endif
  211. #define PAL_PREFIX "./"
  212. #define PAL_SAVE_PREFIX "./"
  213. #define PAL_DEFAULT_WINDOW_WIDTH 640
  214. #define PAL_DEFAULT_WINDOW_HEIGHT 400
  215. #define PAL_DEFAULT_FULLSCREEN_HEIGHT 480
  216. # if SDL_VERSION_ATLEAST(2,0,0)
  217. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  218. # else
  219. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
  220. # endif
  221. # define PAL_PLATFORM NULL
  222. # define PAL_CREDIT NULL
  223. # define PAL_PORTYEAR NULL
  224. #endif
  225. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  226. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  227. #endif
  228. /* Default for 1024 samples */
  229. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  230. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  231. #endif
  232. #ifndef PAL_HAS_SDLCD
  233. #define PAL_HAS_SDLCD 0
  234. #endif
  235. #define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  236. #define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  237. #define PAL_HAS_MAME 1 /* Should not be enabled for now, until M.A.M.E goes open source licenses */
  238. #ifndef SDL_INIT_CDROM
  239. #define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  240. #endif
  241. #ifndef SDL_AUDIO_BITSIZE
  242. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  243. #endif
  244. #ifdef _WIN32
  245. #include <windows.h>
  246. #if !defined(__BORLANDC__)
  247. #include <io.h>
  248. #endif
  249. #if defined(_MSC_VER)
  250. # if _MSC_VER < 1900
  251. # define vsnprintf _vsnprintf
  252. # define snprintf _snprintf
  253. # endif
  254. # define strdup _strdup
  255. # pragma warning (disable:4244)
  256. #endif
  257. #ifndef _LPCBYTE_DEFINED
  258. #define _LPCBYTE_DEFINED
  259. typedef const BYTE *LPCBYTE;
  260. #endif
  261. #ifndef __WINPHONE__
  262. #define PAL_HAS_NATIVEMIDI 1
  263. #endif
  264. #else
  265. #include <unistd.h>
  266. #include <dirent.h>
  267. #ifndef FALSE
  268. #define FALSE 0
  269. #endif
  270. #ifndef TRUE
  271. #define TRUE 1
  272. #endif
  273. #define VOID void
  274. typedef char CHAR;
  275. typedef wchar_t WCHAR;
  276. typedef short SHORT;
  277. typedef long LONG;
  278. typedef unsigned long ULONG, *PULONG;
  279. typedef unsigned short USHORT, *PUSHORT;
  280. typedef unsigned char UCHAR, *PUCHAR;
  281. typedef unsigned short WORD, *LPWORD;
  282. typedef unsigned int DWORD, *LPDWORD;
  283. typedef int INT, *LPINT;
  284. #ifndef __OBJC__
  285. typedef int BOOL, *LPBOOL;
  286. #endif
  287. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  288. typedef unsigned char BYTE, *LPBYTE;
  289. typedef const BYTE *LPCBYTE;
  290. typedef float FLOAT, *LPFLOAT;
  291. typedef void *LPVOID;
  292. typedef const void *LPCVOID;
  293. typedef CHAR *LPSTR;
  294. typedef const CHAR *LPCSTR;
  295. typedef WCHAR *LPWSTR;
  296. typedef const WCHAR *LPCWSTR;
  297. #endif
  298. #ifndef PAL_HAS_NATIVEMIDI
  299. #define PAL_HAS_NATIVEMIDI 0
  300. #endif
  301. #if defined (__SYMBIAN32__)
  302. #define PAL_LARGE static
  303. #else
  304. #define PAL_LARGE /* */
  305. #endif
  306. #define __WIDETEXT(quote) L##quote
  307. #define WIDETEXT(quote) __WIDETEXT(quote)
  308. // For SDL 1.2 compatibility
  309. #ifndef SDL_TICKS_PASSED
  310. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  311. #endif
  312. #define PAL_DelayUntil(t) \
  313. PAL_ProcessEvent(); \
  314. while (!SDL_TICKS_PASSED(SDL_GetTicks(), (t))) \
  315. { \
  316. PAL_ProcessEvent(); \
  317. SDL_Delay(1); \
  318. }
  319. typedef enum tagCODEPAGE {
  320. CP_UNKNOWN = -1,
  321. CP_MIN = 0,
  322. CP_BIG5 = 0,
  323. CP_GBK = 1,
  324. //CP_SHIFTJIS = 2,
  325. CP_MAX = CP_GBK + 1,
  326. CP_UTF_8 = CP_MAX + 1
  327. } CODEPAGE;
  328. #ifdef __cplusplus
  329. }
  330. #endif
  331. #endif