common.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <time.h>
  33. #include <limits.h>
  34. #include <stdarg.h>
  35. #include <assert.h>
  36. #include "SDL.h"
  37. #include "SDL_endian.h"
  38. #ifdef _SDL_stdinc_h
  39. #define malloc SDL_malloc
  40. #define calloc SDL_calloc
  41. #define free SDL_free
  42. #define realloc SDL_realloc
  43. #endif
  44. #if SDL_VERSION_ATLEAST(2,0,0)
  45. #define SDLK_KP1 SDLK_KP_1
  46. #define SDLK_KP2 SDLK_KP_2
  47. #define SDLK_KP3 SDLK_KP_3
  48. #define SDLK_KP4 SDLK_KP_4
  49. #define SDLK_KP5 SDLK_KP_5
  50. #define SDLK_KP6 SDLK_KP_6
  51. #define SDLK_KP7 SDLK_KP_7
  52. #define SDLK_KP8 SDLK_KP_8
  53. #define SDLK_KP9 SDLK_KP_9
  54. #define SDLK_KP0 SDLK_KP_0
  55. #define SDL_HWSURFACE 0
  56. #endif
  57. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  58. #define SWAP16(X) (X)
  59. #define SWAP32(X) (X)
  60. #else
  61. #define SWAP16(X) SDL_Swap16(X)
  62. #define SWAP32(X) SDL_Swap32(X)
  63. #endif
  64. #ifndef max
  65. #define max(a, b) (((a) > (b)) ? (a) : (b))
  66. #endif
  67. #ifndef min
  68. #define min(a, b) (((a) < (b)) ? (a) : (b))
  69. #endif
  70. #if defined (__SYMBIAN32__)
  71. #undef _WIN32
  72. #undef SDL_INIT_JOYSTICK
  73. #define SDL_INIT_JOYSTICK 0
  74. #define PAL_HAS_MOUSE 1
  75. #define PAL_PREFIX "e:/data/pal/"
  76. #define PAL_SAVE_PREFIX "e:/data/pal/"
  77. #elif defined (GEKKO)
  78. #define PAL_HAS_JOYSTICKS 1
  79. #define PAL_HAS_MOUSE 0
  80. #define PAL_PREFIX "SD:/apps/sdlpal/"
  81. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  82. #elif defined (PSP)
  83. #define PAL_HAS_JOYSTICKS 0
  84. #define PAL_PREFIX "ms0:/"
  85. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  86. #elif defined (__IOS__)
  87. #define PAL_PREFIX UTIL_IOS_BasePath()
  88. #define PAL_SAVE_PREFIX UTIL_IOS_SavePath()
  89. #define PAL_HAS_TOUCH 1
  90. #elif defined (__ANDROID__)
  91. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  92. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  93. #define PAL_HAS_TOUCH 1
  94. #elif defined (__WINPHONE__)
  95. #define PAL_PREFIX "Assets\\Data\\"
  96. #define PAL_SAVE_PREFIX "" // ???
  97. #define PAL_HAS_TOUCH 1
  98. #include <stdio.h>
  99. #ifdef __cplusplus
  100. #include <cstdio>
  101. #endif
  102. FILE *MY_fopen(const char *path, const char *mode);
  103. #define fopen MY_fopen
  104. #else
  105. #define PAL_HAS_JOYSTICKS 1
  106. #ifndef _WIN32_WCE
  107. #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
  108. #define PAL_ALLOW_KEYREPEAT 1
  109. #define PAL_HAS_CD 1
  110. #endif
  111. #if !defined (CYGWIN) && !defined (DINGOO) && !defined (GPH) && !defined (GEKKO) && !defined (__WINPHONE__)
  112. #define PAL_HAS_MP3 1
  113. #endif
  114. #endif
  115. #ifndef PAL_PREFIX
  116. #define PAL_PREFIX "./"
  117. #endif
  118. #ifndef PAL_SAVE_PREFIX
  119. #define PAL_SAVE_PREFIX "./"
  120. #endif
  121. #endif
  122. #ifndef SDL_INIT_CDROM
  123. #define SDL_INIT_CDROM 0
  124. #endif
  125. #ifdef _WIN32
  126. #include <windows.h>
  127. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  128. #include <io.h>
  129. #endif
  130. #define vsnprintf _vsnprintf
  131. #ifdef _MSC_VER
  132. #pragma warning (disable:4244)
  133. #pragma warning (disable:4996)
  134. #endif
  135. #ifndef _LPCBYTE_DEFINED
  136. #define _LPCBYTE_DEFINED
  137. typedef const BYTE *LPCBYTE;
  138. #endif
  139. #ifndef __WINPHONE__
  140. #define PAL_HAS_NATIVEMIDI 1
  141. #endif
  142. #else
  143. #include <unistd.h>
  144. #include <wchar.h>
  145. #ifndef FALSE
  146. #define FALSE 0
  147. #endif
  148. #ifndef TRUE
  149. #define TRUE 1
  150. #endif
  151. #define VOID void
  152. typedef char CHAR;
  153. typedef wchar_t WCHAR;
  154. typedef short SHORT;
  155. typedef long LONG;
  156. typedef unsigned long ULONG, *PULONG;
  157. typedef unsigned short USHORT, *PUSHORT;
  158. typedef unsigned char UCHAR, *PUCHAR;
  159. typedef unsigned short WORD, *LPWORD;
  160. typedef unsigned int DWORD, *LPDWORD;
  161. typedef int INT, *LPINT;
  162. #ifndef __OBJC__
  163. typedef int BOOL, *LPBOOL;
  164. #endif
  165. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  166. typedef unsigned char BYTE, *LPBYTE;
  167. typedef const BYTE *LPCBYTE;
  168. typedef float FLOAT, *LPFLOAT;
  169. typedef void *LPVOID;
  170. typedef const void *LPCVOID;
  171. typedef CHAR *LPSTR;
  172. typedef const CHAR *LPCSTR;
  173. typedef WCHAR *LPWSTR;
  174. typedef const WCHAR *LPCWSTR;
  175. #endif
  176. #if defined (__SYMBIAN32__)
  177. #define PAL_LARGE static
  178. #else
  179. #define PAL_LARGE /* */
  180. #endif
  181. #define __WIDETEXT(quote) L##quote
  182. #define WIDETEXT(quote) __WIDETEXT(quote)
  183. typedef enum tagCODEPAGE {
  184. CP_UNKNOWN = -1,
  185. CP_MIN = 0,
  186. CP_BIG5 = 0,
  187. CP_GBK = 1,
  188. CP_SHIFTJIS = 2,
  189. CP_MAX = 3
  190. } CODEPAGE;
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif