common.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. #ifndef ENABLE_REVISIED_BATTLE
  24. # define PAL_CLASSIC 1
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  31. #define _CRT_SECURE_NO_WARNINGS
  32. #endif
  33. #include <wchar.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <time.h>
  38. #include <limits.h>
  39. #include <stdarg.h>
  40. #include <assert.h>
  41. #include "SDL.h"
  42. #include "SDL_endian.h"
  43. #if SDL_VERSION_ATLEAST(2,0,0)
  44. #define SDLK_KP1 SDLK_KP_1
  45. #define SDLK_KP2 SDLK_KP_2
  46. #define SDLK_KP3 SDLK_KP_3
  47. #define SDLK_KP4 SDLK_KP_4
  48. #define SDLK_KP5 SDLK_KP_5
  49. #define SDLK_KP6 SDLK_KP_6
  50. #define SDLK_KP7 SDLK_KP_7
  51. #define SDLK_KP8 SDLK_KP_8
  52. #define SDLK_KP9 SDLK_KP_9
  53. #define SDLK_KP0 SDLK_KP_0
  54. #define SDL_HWSURFACE 0
  55. #endif
  56. #ifndef max
  57. #define max fmax
  58. #endif
  59. #ifndef min
  60. #define min fmin
  61. #endif
  62. /* This is need when compiled with SDL 1.2 */
  63. #ifndef SDL_FORCE_INLINE
  64. #if defined(_MSC_VER)
  65. #define SDL_FORCE_INLINE __forceinline
  66. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  67. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  68. #else
  69. #define SDL_FORCE_INLINE static SDL_INLINE
  70. #endif
  71. #endif /* SDL_FORCE_INLINE not defined */
  72. #if defined(_MSC_VER)
  73. #define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  74. #else
  75. #define PAL_FORCE_INLINE SDL_FORCE_INLINE
  76. #endif
  77. #if defined (__SYMBIAN32__)
  78. #undef _WIN32
  79. #undef SDL_INIT_JOYSTICK
  80. #define SDL_INIT_JOYSTICK 0
  81. #define PAL_HAS_MOUSE 1
  82. #define PAL_PREFIX "e:/data/pal/"
  83. #define PAL_SAVE_PREFIX "e:/data/pal/"
  84. # ifdef __S60_5X__
  85. # define PAL_DEFAULT_WINDOW_WIDTH 640
  86. # define PAL_DEFAULT_WINDOW_HEIGHT 360
  87. # else
  88. # define PAL_DEFAULT_WINDOW_WIDTH 320
  89. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  90. # endif
  91. # if SDL_VERSION_ATLEAST(2,0,0)
  92. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  93. # else
  94. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gConfig.fFullScreen ? SDL_FULLSCREEN : 0))
  95. # endif
  96. # define PAL_PLATFORM " Symbian S60 \x79FB\x690D (c) 2009, netwan."
  97. # define PAL_CREDIT "netwan"
  98. # define PAL_PORTYEAR "2009"
  99. #elif defined (GEKKO)
  100. #define PAL_HAS_JOYSTICKS 1
  101. #define PAL_HAS_MOUSE 0
  102. #define PAL_PREFIX "SD:/apps/sdlpal/"
  103. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  104. #define PAL_DEFAULT_WINDOW_WIDTH 640
  105. #define PAL_DEFAULT_WINDOW_HEIGHT 480
  106. # if SDL_VERSION_ATLEAST(2,0,0)
  107. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
  108. # else
  109. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | (gConfig.fFullScreen ? SDL_FULLSCREEN : 0))
  110. # endif
  111. # define PAL_PLATFORM "Nintendo WII"
  112. # define PAL_CREDIT "Rikku2000"
  113. # define PAL_PORTYEAR "2012"
  114. #elif defined (PSP)
  115. #define PAL_HAS_JOYSTICKS 0
  116. #define PAL_PREFIX "ms0:/"
  117. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  118. #define PAL_DEFAULT_WINDOW_WIDTH 320
  119. #define PAL_DEFAULT_WINDOW_HEIGHT 240
  120. # if SDL_VERSION_ATLEAST(2,0,0)
  121. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  122. # else
  123. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  124. # endif
  125. # define PAL_PLATFORM "Sony PSP"
  126. # define PAL_CREDIT "(Unknown)"
  127. # define PAL_PORTYEAR "2011"
  128. #elif defined(GPH) || defined(DINGOO)
  129. #define PAL_PREFIX "./"
  130. #define PAL_SAVE_PREFIX "./"
  131. # define PAL_DEFAULT_WINDOW_WIDTH 320
  132. # define PAL_DEFAULT_WINDOW_HEIGHT 240
  133. # if SDL_VERSION_ATLEAST(2,0,0)
  134. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  135. # else
  136. # define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_FULLSCREEN)
  137. # endif
  138. # if defined(GPH)
  139. # define PAL_PLATFORM "GPH Caanoo & Wiz"
  140. # else
  141. # define PAL_PLATFORM "DINGOO & Dingux"
  142. # endif
  143. # define PAL_CREDIT "Rikku2000"
  144. # define PAL_PORTYEAR "2011"
  145. #elif defined(NDS)
  146. #define PAL_PREFIX "./"
  147. #define PAL_SAVE_PREFIX "./"
  148. # define PAL_DEFAULT_WINDOW_WIDTH 293
  149. # define PAL_DEFAULT_WINDOW_HEIGHT 196
  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_SWSURFACE | SDL_FULLSCREEN)
  154. # endif
  155. # define PAL_PLATFORM "Nintendo DS"
  156. # define PAL_CREDIT "(Unknown)"
  157. # define PAL_PORTYEAR "2012"
  158. #elif defined (__N3DS__)
  159. #define PAL_PREFIX "sdmc:/3ds/sdlpal/"
  160. #define PAL_SAVE_PREFIX "sdmc:/3ds/sdlpal/"
  161. #define PAL_CONFIG_PREFIX "sdmc:/3ds/sdlpal/"
  162. #define PAL_SCREENSHOT_PREFIX "sdmc:/3ds/sdlpal/"
  163. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 2048
  164. #define PAL_HAS_JOYSTICKS 0
  165. #define PAL_HAS_MP3 0
  166. #define PAL_HAS_OGG 0
  167. #define PAL_HAS_TOUCH 0
  168. #define PAL_DEFAULT_WINDOW_WIDTH 320
  169. #define PAL_DEFAULT_WINDOW_HEIGHT 240
  170. #define PAL_VIDEO_INIT_FLAGS (SDL_SWSURFACE | SDL_TOPSCR | SDL_CONSOLEBOTTOM | SDL_FULLSCREEN)
  171. # define PAL_PLATFORM "Nintendo 3DS"
  172. # define PAL_CREDIT "ZephRay"
  173. # define PAL_PORTYEAR "2017"
  174. #elif defined (__IOS__)
  175. #define PAL_PREFIX UTIL_BasePath()
  176. #define PAL_SAVE_PREFIX UTIL_SavePath()
  177. #define PAL_HAS_TOUCH 1
  178. #define PAL_DEFAULT_WINDOW_WIDTH 320
  179. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  180. # if SDL_VERSION_ATLEAST(2,0,0)
  181. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  182. # else
  183. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  184. # endif
  185. # define PAL_PLATFORM "Apple iOS"
  186. # define PAL_CREDIT "(Unknown)"
  187. # define PAL_PORTYEAR "2015"
  188. #elif defined (__ANDROID__)
  189. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  190. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  191. #define PAL_HAS_TOUCH 1
  192. #define PAL_DEFAULT_WINDOW_WIDTH 320
  193. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  194. # if SDL_VERSION_ATLEAST(2,0,0)
  195. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  196. # else
  197. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  198. # endif
  199. # define PAL_PLATFORM "Android"
  200. # define PAL_CREDIT "Rikku2000"
  201. # define PAL_PORTYEAR "2013"
  202. #elif defined(__WINRT__)
  203. #define PAL_PREFIX UTIL_BasePath()
  204. #define PAL_SAVE_PREFIX UTIL_SavePath()
  205. #define PAL_CONFIG_PREFIX UTIL_ConfigPath()
  206. #define PAL_SCREENSHOT_PREFIX UTIL_ScreenShotPath()
  207. #define PAL_HAS_TOUCH 1
  208. #define PAL_AUDIO_DEFAULT_BUFFER_SIZE 4096
  209. #define PAL_DEFAULT_WINDOW_WIDTH 320
  210. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  211. # if SDL_VERSION_ATLEAST(2,0,0)
  212. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  213. # else
  214. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gConfig.fFullScreen ? SDL_FULLSCREEN : 0))
  215. # endif
  216. # define PAL_PLATFORM "Windows Runtime"
  217. # define PAL_CREDIT "(Unknown)"
  218. # define PAL_PORTYEAR "2015"
  219. #elif defined (__EMSCRIPTEN__)
  220. #include <emscripten.h>
  221. #define SDL_Delay emscripten_sleep
  222. #define PAL_PREFIX "data/"
  223. #define PAL_SAVE_PREFIX "data/"
  224. #define PAL_HAS_TOUCH 0
  225. #define PAL_DEFAULT_WINDOW_WIDTH 320
  226. #define PAL_DEFAULT_WINDOW_HEIGHT 200
  227. # if SDL_VERSION_ATLEAST(2,0,0)
  228. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN)
  229. # else
  230. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_FULLSCREEN)
  231. # endif
  232. # define PAL_PLATFORM "Emscripten"
  233. # define PAL_CREDIT "palxex"
  234. # define PAL_PORTYEAR "2016"
  235. #else
  236. # ifndef PAL_HAS_JOYSTICKS
  237. # define PAL_HAS_JOYSTICKS 1
  238. # endif
  239. #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  240. # define PAL_ALLOW_KEYREPEAT 1
  241. # define PAL_HAS_SDLCD 1
  242. #endif
  243. # define PAL_PREFIX "./"
  244. # define PAL_SAVE_PREFIX "./"
  245. # define PAL_DEFAULT_WINDOW_WIDTH 640
  246. # define PAL_DEFAULT_WINDOW_HEIGHT 400
  247. # define PAL_DEFAULT_FULLSCREEN_HEIGHT 480
  248. # if SDL_VERSION_ATLEAST(2,0,0)
  249. # define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | (gConfig.fFullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0))
  250. # else
  251. # define PAL_VIDEO_INIT_FLAGS (SDL_HWSURFACE | SDL_RESIZABLE | (gConfig.fFullScreen ? SDL_FULLSCREEN : 0))
  252. # endif
  253. # define PAL_PLATFORM NULL
  254. # define PAL_CREDIT NULL
  255. # define PAL_PORTYEAR NULL
  256. #endif
  257. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  258. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  259. #endif
  260. /* Default for 1024 samples */
  261. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  262. # define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  263. #endif
  264. #ifndef PAL_HAS_SDLCD
  265. # define PAL_HAS_SDLCD 0
  266. #endif
  267. #ifndef PAL_HAS_MP3
  268. # define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  269. #endif
  270. #ifndef PAL_HAS_OGG
  271. # define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  272. #endif
  273. #ifndef SDL_INIT_CDROM
  274. # define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  275. #endif
  276. #ifndef SDL_AUDIO_BITSIZE
  277. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  278. #endif
  279. #ifndef PAL_CONFIG_PREFIX
  280. # define PAL_CONFIG_PREFIX PAL_PREFIX
  281. #endif
  282. #ifndef PAL_SCREENSHOT_PREFIX
  283. # define PAL_SCREENSHOT_PREFIX PAL_SAVE_PREFIX
  284. #endif
  285. #ifdef _WIN32
  286. #include <windows.h>
  287. #include <io.h>
  288. #if defined(_MSC_VER)
  289. # if _MSC_VER < 1900
  290. # define vsnprintf _vsnprintf
  291. # define snprintf _snprintf
  292. # endif
  293. # define strdup _strdup
  294. # pragma warning (disable:4244)
  295. #endif
  296. #ifndef _LPCBYTE_DEFINED
  297. # define _LPCBYTE_DEFINED
  298. typedef const BYTE *LPCBYTE;
  299. #endif
  300. #ifndef __WINRT__
  301. # define PAL_HAS_NATIVEMIDI 1
  302. #endif
  303. #else
  304. #include <unistd.h>
  305. #include <dirent.h>
  306. #ifndef FALSE
  307. #define FALSE 0
  308. #endif
  309. #ifndef TRUE
  310. #define TRUE 1
  311. #endif
  312. #define VOID void
  313. typedef char CHAR;
  314. typedef wchar_t WCHAR;
  315. typedef short SHORT;
  316. typedef long LONG;
  317. typedef unsigned long ULONG, *PULONG;
  318. typedef unsigned short USHORT, *PUSHORT;
  319. typedef unsigned char UCHAR, *PUCHAR;
  320. typedef unsigned short WORD, *LPWORD;
  321. typedef unsigned int DWORD, *LPDWORD;
  322. typedef int INT, *LPINT;
  323. #ifndef __OBJC__
  324. typedef int BOOL, *LPBOOL;
  325. #endif
  326. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  327. typedef unsigned char BYTE, *LPBYTE;
  328. typedef const BYTE *LPCBYTE;
  329. typedef float FLOAT, *LPFLOAT;
  330. typedef void *LPVOID;
  331. typedef const void *LPCVOID;
  332. typedef CHAR *LPSTR;
  333. typedef const CHAR *LPCSTR;
  334. typedef WCHAR *LPWSTR;
  335. typedef const WCHAR *LPCWSTR;
  336. #endif
  337. #ifndef PAL_HAS_NATIVEMIDI
  338. #define PAL_HAS_NATIVEMIDI 0
  339. #endif
  340. #if defined (__SYMBIAN32__) || defined (__N3DS__)
  341. #define PAL_LARGE static
  342. #else
  343. #define PAL_LARGE /* */
  344. #endif
  345. #define __WIDETEXT(quote) L##quote
  346. #define WIDETEXT(quote) __WIDETEXT(quote)
  347. // For SDL 1.2 compatibility
  348. #ifndef SDL_TICKS_PASSED
  349. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  350. #endif
  351. typedef enum tagCODEPAGE {
  352. CP_MIN = 0,
  353. CP_BIG5 = 0,
  354. CP_GBK = 1,
  355. CP_SHIFTJIS = 2,
  356. CP_JISX0208 = 3,
  357. CP_MAX = CP_GBK + 1,
  358. CP_UTF_8 = CP_MAX + 1
  359. } CODEPAGE;
  360. #ifdef __cplusplus
  361. }
  362. #endif
  363. #endif