common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #define PAL_UNICODE 1
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  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. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  59. #define SWAP16(X) (X)
  60. #define SWAP32(X) (X)
  61. #else
  62. #define SWAP16(X) SDL_Swap16(X)
  63. #define SWAP32(X) SDL_Swap32(X)
  64. #endif
  65. #ifndef max
  66. #define max(a, b) (((a) > (b)) ? (a) : (b))
  67. #endif
  68. #ifndef min
  69. #define min(a, b) (((a) < (b)) ? (a) : (b))
  70. #endif
  71. #if defined (__SYMBIAN32__)
  72. #undef _WIN32
  73. #undef SDL_INIT_JOYSTICK
  74. #define SDL_INIT_JOYSTICK 0
  75. #define PAL_HAS_MOUSE 1
  76. #define PAL_PREFIX "e:/data/pal/"
  77. #define PAL_SAVE_PREFIX "e:/data/pal/"
  78. #elif defined (GEKKO)
  79. #define PAL_HAS_JOYSTICKS 1
  80. #define PAL_HAS_MOUSE 0
  81. #define PAL_PREFIX "SD:/apps/sdlpal/"
  82. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  83. #elif defined (PSP)
  84. #define PAL_HAS_JOYSTICKS 0
  85. #define PAL_PREFIX "ms0:/"
  86. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  87. #elif defined (__IOS__)
  88. #define PAL_PREFIX UTIL_IOS_BasePath()
  89. #define PAL_SAVE_PREFIX UTIL_IOS_SavePath()
  90. #define PAL_HAS_TOUCH 1
  91. #elif defined (__ANDROID__)
  92. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  93. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  94. #define PAL_HAS_TOUCH 1
  95. #elif defined (__WINPHONE__)
  96. #define PAL_PREFIX "Assets\\Data\\"
  97. #define PAL_SAVE_PREFIX "" // ???
  98. #define PAL_HAS_TOUCH 1
  99. #include <stdio.h>
  100. #ifdef __cplusplus
  101. #include <cstdio>
  102. #endif
  103. FILE *MY_fopen(const char *path, const char *mode);
  104. #define fopen MY_fopen
  105. #else
  106. #define PAL_HAS_JOYSTICKS 1
  107. #ifndef _WIN32_WCE
  108. #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  109. #define PAL_ALLOW_KEYREPEAT 1
  110. #define PAL_HAS_CD 1
  111. #endif
  112. #if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH) && !defined (GEKKO) && !defined (__WINPHONE__)
  113. #define PAL_HAS_MP3 1
  114. #endif
  115. #endif
  116. #ifndef PAL_PREFIX
  117. #define PAL_PREFIX "./"
  118. #endif
  119. #ifndef PAL_SAVE_PREFIX
  120. #define PAL_SAVE_PREFIX "./"
  121. #endif
  122. #endif
  123. #ifndef SDL_INIT_CDROM
  124. #define SDL_INIT_CDROM 0
  125. #endif
  126. #ifdef _WIN32
  127. #include <windows.h>
  128. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  129. #include <io.h>
  130. #endif
  131. #define vsnprintf _vsnprintf
  132. #ifdef _MSC_VER
  133. #pragma warning (disable:4244)
  134. #pragma warning (disable:4996)
  135. #endif
  136. #ifndef _LPCBYTE_DEFINED
  137. #define _LPCBYTE_DEFINED
  138. typedef const BYTE *LPCBYTE;
  139. #endif
  140. #ifndef __WINPHONE__
  141. #define PAL_HAS_NATIVEMIDI 1
  142. #endif
  143. #else
  144. #include <unistd.h>
  145. #include <wchar.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. #if defined (__SYMBIAN32__)
  178. #define PAL_LARGE static
  179. #else
  180. #define PAL_LARGE /* */
  181. #endif
  182. #define __WIDETEXT(quote) L##quote
  183. #define WIDETEXT(quote) __WIDETEXT(quote)
  184. typedef enum tagCODEPAGE {
  185. CP_UNKNOWN = -1,
  186. CP_MIN = 0,
  187. CP_BIG5 = 0,
  188. CP_GBK = 1,
  189. CP_SHIFTJIS = 2,
  190. CP_MAX = 3
  191. } CODEPAGE;
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif