common.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #ifndef _COMMON_H
  23. #define _COMMON_H
  24. #ifndef ENABLE_REVISIED_BATTLE
  25. # define PAL_CLASSIC 1
  26. #endif
  27. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  28. #define _CRT_SECURE_NO_WARNINGS
  29. #endif
  30. #include <wchar.h>
  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 <stdint.h>
  39. #include "SDL.h"
  40. #include "SDL_endian.h"
  41. #define __WIDETEXT(quote) L##quote
  42. #define WIDETEXT(quote) __WIDETEXT(quote)
  43. #if !defined(fmax) || !defined(fmin)
  44. # include <math.h>
  45. #endif
  46. #ifndef max
  47. # define max fmax
  48. #endif
  49. #ifndef min
  50. # define min fmin
  51. #endif
  52. // For SDL 1.2 compatibility
  53. #ifndef SDL_TICKS_PASSED
  54. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  55. #endif
  56. #ifndef SDL_INIT_CDROM
  57. # define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  58. #endif
  59. #ifndef SDL_AUDIO_BITSIZE
  60. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  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. #ifdef _WIN32
  78. # include <windows.h>
  79. # include <io.h>
  80. # if defined(_MSC_VER)
  81. # if _MSC_VER < 1900
  82. # define vsnprintf _vsnprintf
  83. # define snprintf _snprintf
  84. # endif
  85. # define strdup _strdup
  86. # pragma warning (disable:4244)
  87. # endif
  88. # ifndef _LPCBYTE_DEFINED
  89. # define _LPCBYTE_DEFINED
  90. typedef const BYTE *LPCBYTE;
  91. # endif
  92. #else
  93. # include <unistd.h>
  94. # include <dirent.h>
  95. # ifndef FALSE
  96. # define FALSE 0
  97. # endif
  98. # ifndef TRUE
  99. # define TRUE 1
  100. # endif
  101. # define VOID void
  102. typedef char CHAR;
  103. typedef wchar_t WCHAR;
  104. typedef short SHORT;
  105. typedef long LONG;
  106. typedef unsigned long ULONG, *PULONG;
  107. typedef unsigned short USHORT, *PUSHORT;
  108. typedef unsigned char UCHAR, *PUCHAR;
  109. typedef unsigned short WORD, *LPWORD;
  110. typedef unsigned int DWORD, *LPDWORD;
  111. typedef int INT, *LPINT;
  112. # ifndef __OBJC__
  113. typedef int BOOL, *LPBOOL;
  114. # endif
  115. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  116. typedef unsigned char BYTE, *LPBYTE;
  117. typedef const BYTE *LPCBYTE;
  118. typedef float FLOAT, *LPFLOAT;
  119. typedef void *LPVOID;
  120. typedef const void *LPCVOID;
  121. typedef CHAR *LPSTR;
  122. typedef const CHAR *LPCSTR;
  123. typedef WCHAR *LPWSTR;
  124. typedef const WCHAR *LPCWSTR;
  125. #endif
  126. #ifdef __cplusplus
  127. # define PAL_C_LINKAGE extern "C"
  128. # define PAL_C_LINKAGE_BEGIN PAL_C_LINKAGE {
  129. # define PAL_C_LINKAGE_END }
  130. #else
  131. # define PAL_C_LINKAGE
  132. # define PAL_C_LINKAGE_BEGIN
  133. # define PAL_C_LINKAGE_END
  134. #endif
  135. /* When porting SDLPAL to a new platform, please make a separate directory and put a file
  136. named 'pal_config.h' that contains marco definitions & header includes into the directory.
  137. The example of this file can be found in directories of existing portings.
  138. */
  139. #include "pal_config.h"
  140. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  141. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  142. #endif
  143. /* Default for 1024 samples */
  144. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  145. # define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  146. #endif
  147. #ifndef PAL_HAS_SDLCD
  148. # define PAL_HAS_SDLCD 0
  149. #endif
  150. #ifndef PAL_HAS_MP3
  151. # define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  152. #endif
  153. #ifndef PAL_HAS_OGG
  154. # define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  155. #endif
  156. #ifndef PAL_CONFIG_PREFIX
  157. # define PAL_CONFIG_PREFIX PAL_PREFIX
  158. #endif
  159. #ifndef PAL_SCREENSHOT_PREFIX
  160. # define PAL_SCREENSHOT_PREFIX PAL_SAVE_PREFIX
  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. #ifndef PAL_IS_VALID_JOYSTICK
  172. # define PAL_IS_VALID_JOYSTICK(s) TRUE
  173. #endif
  174. #ifndef PAL_FATAL_OUTPUT
  175. # define PAL_FATAL_OUTPUT(s)
  176. #endif
  177. #endif