common.h 5.5 KB

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