common.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  27. #define _CRT_SECURE_NO_WARNINGS
  28. #endif
  29. #include <wchar.h>
  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 <stdint.h>
  38. #include "SDL.h"
  39. #include "SDL_endian.h"
  40. #define __WIDETEXT(quote) L##quote
  41. #define WIDETEXT(quote) __WIDETEXT(quote)
  42. #if !defined(fmax) || !defined(fmin)
  43. # include <math.h>
  44. #endif
  45. #ifndef max
  46. # define max fmax
  47. #endif
  48. #ifndef min
  49. # define min fmin
  50. #endif
  51. // For SDL 1.2 compatibility
  52. #ifndef SDL_TICKS_PASSED
  53. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  54. #endif
  55. #ifndef SDL_INIT_CDROM
  56. # define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  57. #endif
  58. #ifndef SDL_AUDIO_BITSIZE
  59. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  60. #endif
  61. /* This is need when compiled with SDL 1.2 */
  62. #ifndef SDL_FORCE_INLINE
  63. #if defined(_MSC_VER)
  64. #define SDL_FORCE_INLINE __forceinline
  65. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  66. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  67. #else
  68. #define SDL_FORCE_INLINE static SDL_INLINE
  69. #endif
  70. #endif /* SDL_FORCE_INLINE not defined */
  71. #if defined(_MSC_VER)
  72. # define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  73. #else
  74. # define PAL_FORCE_INLINE SDL_FORCE_INLINE
  75. #endif
  76. #ifdef _WIN32
  77. # include <windows.h>
  78. # include <io.h>
  79. # if defined(_MSC_VER)
  80. # if _MSC_VER < 1900
  81. # define vsnprintf _vsnprintf
  82. # define snprintf _snprintf
  83. # endif
  84. # define strdup _strdup
  85. # pragma warning (disable:4244)
  86. # endif
  87. # ifndef _LPCBYTE_DEFINED
  88. # define _LPCBYTE_DEFINED
  89. typedef const BYTE *LPCBYTE;
  90. # endif
  91. #else
  92. # include <unistd.h>
  93. # include <dirent.h>
  94. # ifndef FALSE
  95. # define FALSE 0
  96. # endif
  97. # ifndef TRUE
  98. # define TRUE 1
  99. # endif
  100. # define VOID void
  101. typedef char CHAR;
  102. typedef wchar_t WCHAR;
  103. typedef short SHORT;
  104. typedef long LONG;
  105. typedef unsigned long ULONG, *PULONG;
  106. typedef unsigned short USHORT, *PUSHORT;
  107. typedef unsigned char UCHAR, *PUCHAR;
  108. typedef unsigned short WORD, *LPWORD;
  109. typedef unsigned int DWORD, *LPDWORD;
  110. typedef int INT, *LPINT;
  111. # ifndef __OBJC__
  112. typedef int BOOL, *LPBOOL;
  113. # endif
  114. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  115. typedef unsigned char BYTE, *LPBYTE;
  116. typedef const BYTE *LPCBYTE;
  117. typedef float FLOAT, *LPFLOAT;
  118. typedef void *LPVOID;
  119. typedef const void *LPCVOID;
  120. typedef CHAR *LPSTR;
  121. typedef const CHAR *LPCSTR;
  122. typedef WCHAR *LPWSTR;
  123. typedef const WCHAR *LPCWSTR;
  124. #endif
  125. #ifdef __cplusplus
  126. # define PAL_C_LINKAGE extern "C"
  127. # define PAL_C_LINKAGE_BEGIN PAL_C_LINKAGE {
  128. # define PAL_C_LINKAGE_END }
  129. #else
  130. # define PAL_C_LINKAGE
  131. # define PAL_C_LINKAGE_BEGIN
  132. # define PAL_C_LINKAGE_END
  133. #endif
  134. /* When porting SDLPAL to a new platform, please make a separate directory and put a file
  135. named 'pal_config.h' that contains marco definitions & header includes into the directory.
  136. The example of this file can be found in directories of existing portings.
  137. */
  138. #include "pal_config.h"
  139. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  140. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  141. #endif
  142. /* Default for 1024 samples */
  143. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  144. # define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  145. #endif
  146. #ifndef PAL_HAS_SDLCD
  147. # define PAL_HAS_SDLCD 0
  148. #endif
  149. #ifndef PAL_HAS_MP3
  150. # define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  151. #endif
  152. #ifndef PAL_HAS_OGG
  153. # define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  154. #endif
  155. #ifndef PAL_CONFIG_PREFIX
  156. # define PAL_CONFIG_PREFIX PAL_PREFIX
  157. #endif
  158. #ifndef PAL_SCREENSHOT_PREFIX
  159. # define PAL_SCREENSHOT_PREFIX PAL_SAVE_PREFIX
  160. #endif
  161. #ifndef PAL_HAS_NATIVEMIDI
  162. # define PAL_HAS_NATIVEMIDI 0
  163. #endif
  164. #ifndef PAL_LARGE
  165. # define PAL_LARGE
  166. #endif
  167. #ifndef PAL_SCALE_SCREEN
  168. # define PAL_SCALE_SCREEN TRUE
  169. #endif
  170. #ifndef PAL_IS_VALID_JOYSTICK
  171. # define PAL_IS_VALID_JOYSTICK(s) TRUE
  172. #endif
  173. #ifndef PAL_FATAL_OUTPUT
  174. # define PAL_FATAL_OUTPUT(s)
  175. #endif
  176. #endif