common.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #if defined (__SYMBIAN32__)
  65. #undef _WIN32
  66. #undef SDL_INIT_JOYSTICK
  67. #define SDL_INIT_JOYSTICK 0
  68. #define PAL_HAS_MOUSE 1
  69. #define PAL_PREFIX "e:/data/pal/"
  70. #define PAL_SAVE_PREFIX "e:/data/pal/"
  71. #elif defined (GEKKO)
  72. #define PAL_HAS_JOYSTICKS 1
  73. #define PAL_HAS_MOUSE 0
  74. #define PAL_PREFIX "SD:/apps/sdlpal/"
  75. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  76. #elif defined (PSP)
  77. #define PAL_HAS_JOYSTICKS 0
  78. #define PAL_PREFIX "ms0:/"
  79. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  80. #elif defined (__IOS__)
  81. #define PAL_PREFIX UTIL_IOS_BasePath()
  82. #define PAL_SAVE_PREFIX UTIL_IOS_SavePath()
  83. #define PAL_HAS_TOUCH 1
  84. #elif defined (__ANDROID__)
  85. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  86. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  87. #define PAL_HAS_TOUCH 1
  88. #elif defined (__WINPHONE__)
  89. #define PAL_PREFIX "Assets\\Data\\"
  90. #define PAL_SAVE_PREFIX "" // ???
  91. #define PAL_HAS_TOUCH 1
  92. #include <stdio.h>
  93. #ifdef __cplusplus
  94. #include <cstdio>
  95. #endif
  96. FILE *MY_fopen(const char *path, const char *mode);
  97. #define fopen MY_fopen
  98. #else
  99. # define PAL_HAS_JOYSTICKS 1
  100. # ifndef _WIN32_WCE
  101. # if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  102. # define PAL_ALLOW_KEYREPEAT 1
  103. # define PAL_HAS_SDLCD 1
  104. # endif
  105. # ifndef PAL_PREFIX
  106. # define PAL_PREFIX "./"
  107. # endif
  108. # ifndef PAL_SAVE_PREFIX
  109. # define PAL_SAVE_PREFIX "./"
  110. # endif
  111. # endif
  112. //# if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH)
  113. //# define PAL_HAS_MP3 1
  114. //# endif
  115. #endif
  116. #ifndef PAL_HAS_SDLCD
  117. #define PAL_HAS_SDLCD 0
  118. #endif
  119. #define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  120. #define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  121. #define PAL_HAS_MAME 1 /* Should not be enabled for now, until M.A.M.E goes open source licenses */
  122. #ifndef SDL_INIT_CDROM
  123. #define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  124. #endif
  125. #ifdef _WIN32
  126. #include <windows.h>
  127. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  128. #include <io.h>
  129. #endif
  130. #if defined(_MSC_VER) && _MSC_VER < 1900
  131. #define vsnprintf _vsnprintf
  132. #endif
  133. #ifdef _MSC_VER
  134. #pragma warning (disable:4244)
  135. #pragma warning (disable:4996)
  136. #endif
  137. #ifndef _LPCBYTE_DEFINED
  138. #define _LPCBYTE_DEFINED
  139. typedef const BYTE *LPCBYTE;
  140. #endif
  141. #ifndef __WINPHONE__
  142. #define PAL_HAS_NATIVEMIDI 1
  143. #endif
  144. #else
  145. #include <unistd.h>
  146. #ifndef FALSE
  147. #define FALSE 0
  148. #endif
  149. #ifndef TRUE
  150. #define TRUE 1
  151. #endif
  152. #define VOID void
  153. typedef char CHAR;
  154. typedef wchar_t WCHAR;
  155. typedef short SHORT;
  156. typedef long LONG;
  157. typedef unsigned long ULONG, *PULONG;
  158. typedef unsigned short USHORT, *PUSHORT;
  159. typedef unsigned char UCHAR, *PUCHAR;
  160. typedef unsigned short WORD, *LPWORD;
  161. typedef unsigned int DWORD, *LPDWORD;
  162. typedef int INT, *LPINT;
  163. #ifndef __OBJC__
  164. typedef int BOOL, *LPBOOL;
  165. #endif
  166. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  167. typedef unsigned char BYTE, *LPBYTE;
  168. typedef const BYTE *LPCBYTE;
  169. typedef float FLOAT, *LPFLOAT;
  170. typedef void *LPVOID;
  171. typedef const void *LPCVOID;
  172. typedef CHAR *LPSTR;
  173. typedef const CHAR *LPCSTR;
  174. typedef WCHAR *LPWSTR;
  175. typedef const WCHAR *LPCWSTR;
  176. #endif
  177. #ifndef PAL_HAS_NATIVEMIDI
  178. #define PAL_HAS_NATIVEMIDI 0
  179. #endif
  180. #if defined (__SYMBIAN32__)
  181. #define PAL_LARGE static
  182. #else
  183. #define PAL_LARGE /* */
  184. #endif
  185. #define __WIDETEXT(quote) L##quote
  186. #define WIDETEXT(quote) __WIDETEXT(quote)
  187. typedef enum tagCODEPAGE {
  188. CP_UNKNOWN = -1,
  189. CP_MIN = 0,
  190. CP_BIG5 = 0,
  191. CP_GBK = 1,
  192. CP_SHIFTJIS = 2,
  193. CP_MAX = 3
  194. } CODEPAGE;
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #endif