common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. // Modified by Lou Yihua <louyihua@21cn.com> with unicode support, 2015.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #ifndef _COMMON_H
  22. #define _COMMON_H
  23. #ifndef ENABLE_REVISIED_BATTLE
  24. # define PAL_CLASSIC 1
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  31. #define _CRT_SECURE_NO_WARNINGS
  32. #endif
  33. #include <wchar.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <time.h>
  38. #include <limits.h>
  39. #include <stdarg.h>
  40. #include <assert.h>
  41. #include "SDL.h"
  42. #include "SDL_endian.h"
  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. #ifndef max
  57. #define max fmax
  58. #endif
  59. #ifndef min
  60. #define min fmin
  61. #endif
  62. /* This is need when compiled with SDL 1.2 */
  63. #ifndef SDL_FORCE_INLINE
  64. #if defined(_MSC_VER)
  65. #define SDL_FORCE_INLINE __forceinline
  66. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  67. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  68. #else
  69. #define SDL_FORCE_INLINE static SDL_INLINE
  70. #endif
  71. #endif /* SDL_FORCE_INLINE not defined */
  72. #if defined(_MSC_VER)
  73. #define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  74. #else
  75. #define PAL_FORCE_INLINE SDL_FORCE_INLINE
  76. #endif
  77. /* When porting SDLPAL to a new platform, please make a separate directory and put a file
  78. named 'pal_config.h' that contains marco definitions & header includes into the directory.
  79. The example of this file can be found in directories of existing portings.
  80. */
  81. #include "pal_config.h"
  82. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  83. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  84. #endif
  85. /* Default for 1024 samples */
  86. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  87. # define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  88. #endif
  89. #ifndef PAL_HAS_SDLCD
  90. # define PAL_HAS_SDLCD 0
  91. #endif
  92. #ifndef PAL_HAS_MP3
  93. # define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  94. #endif
  95. #ifndef PAL_HAS_OGG
  96. # define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  97. #endif
  98. #ifndef SDL_INIT_CDROM
  99. # define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  100. #endif
  101. #ifndef SDL_AUDIO_BITSIZE
  102. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  103. #endif
  104. #ifndef PAL_CONFIG_PREFIX
  105. # define PAL_CONFIG_PREFIX PAL_PREFIX
  106. #endif
  107. #ifndef PAL_SCREENSHOT_PREFIX
  108. # define PAL_SCREENSHOT_PREFIX PAL_SAVE_PREFIX
  109. #endif
  110. #ifdef _WIN32
  111. #include <windows.h>
  112. #include <io.h>
  113. #if defined(_MSC_VER)
  114. # if _MSC_VER < 1900
  115. # define vsnprintf _vsnprintf
  116. # define snprintf _snprintf
  117. # endif
  118. # define strdup _strdup
  119. # pragma warning (disable:4244)
  120. #endif
  121. #ifndef _LPCBYTE_DEFINED
  122. # define _LPCBYTE_DEFINED
  123. typedef const BYTE *LPCBYTE;
  124. #endif
  125. #ifndef __WINRT__
  126. # define PAL_HAS_NATIVEMIDI 1
  127. #endif
  128. #else
  129. #include <unistd.h>
  130. #include <dirent.h>
  131. #ifndef FALSE
  132. #define FALSE 0
  133. #endif
  134. #ifndef TRUE
  135. #define TRUE 1
  136. #endif
  137. #define VOID void
  138. typedef char CHAR;
  139. typedef wchar_t WCHAR;
  140. typedef short SHORT;
  141. typedef long LONG;
  142. typedef unsigned long ULONG, *PULONG;
  143. typedef unsigned short USHORT, *PUSHORT;
  144. typedef unsigned char UCHAR, *PUCHAR;
  145. typedef unsigned short WORD, *LPWORD;
  146. typedef unsigned int DWORD, *LPDWORD;
  147. typedef int INT, *LPINT;
  148. #ifndef __OBJC__
  149. typedef int BOOL, *LPBOOL;
  150. #endif
  151. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  152. typedef unsigned char BYTE, *LPBYTE;
  153. typedef const BYTE *LPCBYTE;
  154. typedef float FLOAT, *LPFLOAT;
  155. typedef void *LPVOID;
  156. typedef const void *LPCVOID;
  157. typedef CHAR *LPSTR;
  158. typedef const CHAR *LPCSTR;
  159. typedef WCHAR *LPWSTR;
  160. typedef const WCHAR *LPCWSTR;
  161. #endif
  162. #ifndef PAL_HAS_NATIVEMIDI
  163. # define PAL_HAS_NATIVEMIDI 0
  164. #endif
  165. #ifndef PAL_LARGE
  166. # define PAL_LARGE
  167. #endif
  168. #ifndef PAL_SCALE_SCREEN
  169. # define PAL_SCALE_SCREEN TRUE
  170. #endif
  171. #define __WIDETEXT(quote) L##quote
  172. #define WIDETEXT(quote) __WIDETEXT(quote)
  173. // For SDL 1.2 compatibility
  174. #ifndef SDL_TICKS_PASSED
  175. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  176. #endif
  177. typedef enum tagCODEPAGE {
  178. CP_MIN = 0,
  179. CP_BIG5 = 0,
  180. CP_GBK = 1,
  181. CP_SHIFTJIS = 2,
  182. CP_JISX0208 = 3,
  183. CP_MAX = CP_GBK + 1,
  184. CP_UTF_8 = CP_MAX + 1
  185. } CODEPAGE;
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif