common.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #ifndef _COMMON_H
  21. #define _COMMON_H
  22. //#define PAL_WIN95 1 // not valid for now
  23. //#define PAL_CLASSIC 1
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <limits.h>
  33. #include <stdarg.h>
  34. #include <assert.h>
  35. #include "SDL.h"
  36. #include "SDL_endian.h"
  37. #ifdef _SDL_stdinc_h
  38. #define malloc SDL_malloc
  39. #define calloc SDL_calloc
  40. #define free SDL_free
  41. #define realloc SDL_realloc
  42. #endif
  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. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  57. #define SWAP16(X) (X)
  58. #define SWAP32(X) (X)
  59. #else
  60. #define SWAP16(X) SDL_Swap16(X)
  61. #define SWAP32(X) SDL_Swap32(X)
  62. #endif
  63. #ifndef max
  64. #define max(a, b) (((a) > (b)) ? (a) : (b))
  65. #endif
  66. #ifndef min
  67. #define min(a, b) (((a) < (b)) ? (a) : (b))
  68. #endif
  69. #if defined (__SYMBIAN32__)
  70. #undef _WIN32
  71. #undef SDL_INIT_JOYSTICK
  72. #define SDL_INIT_JOYSTICK 0
  73. #define PAL_HAS_MOUSE 1
  74. #define PAL_PREFIX "e:/data/pal/"
  75. #define PAL_SAVE_PREFIX "e:/data/pal/"
  76. #elif defined (GEKKO)
  77. #define PAL_HAS_JOYSTICKS 1
  78. #define PAL_HAS_MOUSE 0
  79. #define PAL_PREFIX "SD:/apps/sdlpal/"
  80. #define PAL_SAVE_PREFIX "SD:/apps/sdlpal/"
  81. #elif defined (PSP)
  82. #define PAL_HAS_JOYSTICKS 0
  83. #define PAL_PREFIX "ms0:/"
  84. #define PAL_SAVE_PREFIX "ms0:/PSP/SAVEDATA/SDLPAL/"
  85. #elif defined (__IOS__)
  86. #define PAL_PREFIX "../Documents/"
  87. #define PAL_SAVE_PREFIX "../Documents/"
  88. #define PAL_HAS_TOUCH 1
  89. #elif defined (__ANDROID__)
  90. #define PAL_PREFIX "/mnt/sdcard/sdlpal/"
  91. #define PAL_SAVE_PREFIX "/mnt/sdcard/sdlpal/"
  92. #define PAL_HAS_TOUCH 1
  93. #elif defined (__WINPHONE__)
  94. #define PAL_PREFIX "Assets\\Data\\"
  95. #define PAL_SAVE_PREFIX "" // ???
  96. #define PAL_HAS_TOUCH 1
  97. #include <stdio.h>
  98. #ifdef __cplusplus
  99. #include <cstdio>
  100. #endif
  101. FILE *MY_fopen(const char *path, const char *mode);
  102. #define fopen MY_fopen
  103. void WinPhone_OnBackKeyPress();
  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:4018)
  133. #pragma warning (disable:4028)
  134. #pragma warning (disable:4244)
  135. #pragma warning (disable:4305)
  136. #pragma warning (disable:4761)
  137. #pragma warning (disable:4996)
  138. #endif
  139. #ifndef _LPCBYTE_DEFINED
  140. #define _LPCBYTE_DEFINED
  141. typedef const BYTE *LPCBYTE;
  142. #endif
  143. #ifndef __WINPHONE__
  144. #define PAL_HAS_NATIVEMIDI 1
  145. #endif
  146. #else
  147. #include <unistd.h>
  148. #define CONST const
  149. #ifndef FALSE
  150. #define FALSE 0
  151. #endif
  152. #ifndef TRUE
  153. #define TRUE 1
  154. #endif
  155. #define VOID void
  156. typedef char CHAR;
  157. typedef short SHORT;
  158. typedef long LONG;
  159. typedef unsigned long ULONG, *PULONG;
  160. typedef unsigned short USHORT, *PUSHORT;
  161. typedef unsigned char UCHAR, *PUCHAR;
  162. typedef unsigned short WORD, *LPWORD;
  163. typedef unsigned int DWORD, *LPDWORD;
  164. typedef int INT, *LPINT, BOOL, *LPBOOL;
  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. #endif
  174. #if defined (__SYMBIAN32__)
  175. #define PAL_LARGE static
  176. #else
  177. #define PAL_LARGE /* */
  178. #endif
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif