scummsys.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef COMMON_SCUMMSYS_H
  16. #define COMMON_SCUMMSYS_H
  17. #if defined(_WIN32_WCE) && _WIN32_WCE < 300
  18. #define NONSTANDARD_PORT
  19. #endif
  20. #if defined(NONSTANDARD_PORT)
  21. // Ports which need to perform #includes and #defines visible in
  22. // virtually all the source of ScummVM should do so by providing a
  23. // "portdefs.h" header file (and not by directly modifying this
  24. // header file).
  25. #include <portdefs.h>
  26. #else // defined(NONSTANDARD_PORT)
  27. #if defined(WIN32)
  28. #ifdef _MSC_VER
  29. // vsnprintf is already defined in Visual Studio 2008
  30. #if (_MSC_VER < 1500)
  31. #define vsnprintf _vsnprintf
  32. #endif
  33. #endif
  34. #if !defined(_WIN32_WCE)
  35. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  36. #define NOGDICAPMASKS
  37. #define OEMRESOURCE
  38. #define NONLS
  39. #define NOICONS
  40. #define NOMCX
  41. #define NOPROFILER
  42. #define NOKANJI
  43. #define NOSERVICE
  44. #define NOMETAFILE
  45. #define NOCOMM
  46. #define NOCRYPT
  47. #define NOIME
  48. #define NOATOM
  49. #define NOCTLMGR
  50. #define NOCLIPBOARD
  51. #define NOMEMMGR
  52. #define NOSYSMETRICS
  53. #define NOMENUS
  54. #define NOOPENFILE
  55. #define NOWH
  56. #define NOSOUND
  57. #define NODRAWTEXT
  58. #endif
  59. #if defined(ARRAYSIZE)
  60. // VS2005beta2 introduces new stuff in winnt.h
  61. #undef ARRAYSIZE
  62. #endif
  63. #endif
  64. #if defined(__QNXNTO__)
  65. #include <strings.h> /* For strcasecmp */
  66. #endif
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #include <stdarg.h>
  71. #include <assert.h>
  72. #include <ctype.h>
  73. #include <math.h>
  74. #endif
  75. // Use config.h, generated by configure
  76. #if defined(HAVE_CONFIG_H)
  77. #include "config.h"
  78. #endif
  79. // make sure we really are compiling for WIN32
  80. #ifndef WIN32
  81. #undef _MSC_VER
  82. #endif
  83. // In the following we configure various targets, in particular those
  84. // which can't use our "configure" tool and hence don't use config.h.
  85. //
  86. // Some #defines that occur here frequently:
  87. // SCUMM_LITTLE_ENDIAN
  88. // - Define this on a little endian target
  89. // SCUMM_BIG_ENDIAN
  90. // - Define this on a big endian target
  91. // SCUMM_NEED_ALIGNMENT
  92. // - Define this if your system has problems reading e.g. an int32 from an odd address
  93. // SCUMMVM_DONT_DEFINE_TYPES
  94. // - Define this if you need to provide your own typedefs, e.g. because your
  95. // system headers conflict with our typenames, or because you have odd
  96. // type requirements.
  97. // SMALL_SCREEN_DEVICE
  98. // - ...
  99. // ...
  100. // We define all types in config.h, so we don't want to typedef those types
  101. // here again!
  102. #ifdef HAVE_CONFIG_H
  103. #define SCUMMVM_DONT_DEFINE_TYPES
  104. #endif
  105. //
  106. // By default we try to use pragma push/pop to ensure various structs we use
  107. // are "packed". If your compiler doesn't support this pragma, you are in for
  108. // a problem. If you are lucky, there is a compiler switch, or another pragma,
  109. // doing the same thing -- in that case, try to modify common/pack-begin.h and
  110. // common/pack-end.h accordingly. Or maybe your port simply *always* packs
  111. // everything, in which case you could #undefine SCUMMVM_USE_PRAGMA_PACK.
  112. //
  113. // If neither is possible, tough luck. Try to contact the team, maybe we can
  114. // come up with a solution, though I wouldn't hold my breath on it :-/.
  115. //
  116. #define SCUMMVM_USE_PRAGMA_PACK
  117. #if defined(__SYMBIAN32__)
  118. #define scumm_stricmp strcasecmp
  119. #define scumm_strnicmp strncasecmp
  120. #define SCUMM_LITTLE_ENDIAN
  121. #define SCUMM_NEED_ALIGNMENT
  122. #define SMALL_SCREEN_DEVICE
  123. // Enable Symbians own datatypes
  124. // This is done for two reasons
  125. // a) uint is already defined by Symbians libc component
  126. // b) Symbian is using its "own" datatyping, and the Scummvm port
  127. // should follow this to ensure the best compability possible.
  128. #define SCUMMVM_DONT_DEFINE_TYPES
  129. typedef unsigned char byte;
  130. typedef unsigned char uint8;
  131. typedef signed char int8;
  132. typedef unsigned short int uint16;
  133. typedef signed short int int16;
  134. typedef unsigned long int uint32;
  135. typedef signed long int int32;
  136. #elif defined(_WIN32_WCE)
  137. #define scumm_stricmp stricmp
  138. #define scumm_strnicmp _strnicmp
  139. #define snprintf _snprintf
  140. #define SCUMM_LITTLE_ENDIAN
  141. #ifndef __GNUC__
  142. #define FORCEINLINE __forceinline
  143. #define NORETURN_PRE __declspec(noreturn)
  144. #endif
  145. #define PLUGIN_EXPORT __declspec(dllexport)
  146. #if _WIN32_WCE < 300
  147. #define SMALL_SCREEN_DEVICE
  148. #endif
  149. #elif defined(_MSC_VER)
  150. #define scumm_stricmp _stricmp
  151. #define scumm_strnicmp _strnicmp
  152. #define snprintf _snprintf
  153. #define SCUMM_LITTLE_ENDIAN
  154. #define FORCEINLINE __forceinline
  155. #define NORETURN_PRE __declspec(noreturn)
  156. #define PLUGIN_EXPORT __declspec(dllexport)
  157. #elif defined(__MINGW32__)
  158. #define scumm_stricmp stricmp
  159. #define scumm_strnicmp strnicmp
  160. #define SCUMM_LITTLE_ENDIAN
  161. #define PLUGIN_EXPORT __declspec(dllexport)
  162. #elif defined(POSIX)
  163. #define scumm_stricmp strcasecmp
  164. #define scumm_strnicmp strncasecmp
  165. #ifndef CONFIG_H
  166. /* need this for the SDL_BYTEORDER define */
  167. //#include <SDL_byteorder.h>
  168. #define SDL_BYTEORDER SDL_LIL_ENDIAN
  169. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  170. #define SCUMM_LITTLE_ENDIAN
  171. #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
  172. #define SCUMM_BIG_ENDIAN
  173. #else
  174. #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
  175. #endif
  176. #endif
  177. // You need to set this manually if necessary
  178. // #define SCUMM_NEED_ALIGNMENT
  179. #if defined(__DECCXX) // Assume alpha architecture
  180. #define INVERSE_MKID
  181. #define SCUMM_NEED_ALIGNMENT
  182. #endif
  183. #elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__)
  184. #ifdef __PALMOS_ARMLET__
  185. #include <extras_string.h>
  186. #endif
  187. #define SCUMM_LITTLE_ENDIAN
  188. #define scumm_stricmp stricmp
  189. #define scumm_strnicmp strnicmp
  190. #define SCUMM_NEED_ALIGNMENT
  191. #define STRINGBUFLEN 256
  192. extern const char *SCUMMVM_SAVEPATH;
  193. #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
  194. # define NEWGUI_256
  195. #else
  196. # undef UNUSED
  197. #endif
  198. #elif defined(__DC__)
  199. #define scumm_stricmp strcasecmp
  200. #define scumm_strnicmp strncasecmp
  201. #define SCUMM_LITTLE_ENDIAN
  202. #define SCUMM_NEED_ALIGNMENT
  203. #elif defined(__GP32__)
  204. #define scumm_stricmp stricmp
  205. #define scumm_strnicmp strnicmp
  206. #define SCUMM_LITTLE_ENDIAN
  207. #define SCUMM_NEED_ALIGNMENT
  208. // Override typenames. uint is already defined by system header files.
  209. #define SCUMMVM_DONT_DEFINE_TYPES
  210. typedef unsigned char byte;
  211. typedef unsigned char uint8;
  212. typedef signed char int8;
  213. typedef unsigned short int uint16;
  214. typedef signed short int int16;
  215. typedef unsigned long int uint32;
  216. typedef signed long int int32;
  217. #elif defined(__PLAYSTATION2__)
  218. #define scumm_stricmp strcasecmp
  219. #define scumm_strnicmp strncasecmp
  220. #define SCUMM_LITTLE_ENDIAN
  221. #define SCUMM_NEED_ALIGNMENT
  222. #elif defined(__N64__)
  223. #define scumm_stricmp strcasecmp
  224. #define scumm_strnicmp strncasecmp
  225. #define SCUMM_BIG_ENDIAN
  226. #define SCUMM_NEED_ALIGNMENT
  227. #define STRINGBUFLEN 256
  228. #define SCUMMVM_DONT_DEFINE_TYPES
  229. typedef unsigned char byte;
  230. typedef unsigned char uint8;
  231. typedef signed char int8;
  232. typedef unsigned short int uint16;
  233. typedef signed short int int16;
  234. typedef unsigned int uint32;
  235. typedef signed int int32;
  236. typedef unsigned long long uint64;
  237. typedef signed long long int64;
  238. #elif defined(__PSP__)
  239. #include <malloc.h>
  240. #define scumm_stricmp strcasecmp
  241. #define scumm_strnicmp strncasecmp
  242. #define SCUMM_LITTLE_ENDIAN
  243. #define SCUMM_NEED_ALIGNMENT
  244. #elif defined(__amigaos4__)
  245. #define scumm_stricmp strcasecmp
  246. #define scumm_strnicmp strncasecmp
  247. #define SCUMM_BIG_ENDIAN
  248. #define SCUMM_NEED_ALIGNMENT
  249. #elif defined (__DS__)
  250. #define scumm_stricmp stricmp
  251. #define scumm_strnicmp strnicmp
  252. #define SCUMM_NEED_ALIGNMENT
  253. #define SCUMM_LITTLE_ENDIAN
  254. #define SCUMMVM_DONT_DEFINE_TYPES
  255. #define STRINGBUFLEN 256
  256. // #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
  257. #elif defined(__WII__)
  258. #define scumm_stricmp strcasecmp
  259. #define scumm_strnicmp strncasecmp
  260. #define SCUMM_BIG_ENDIAN
  261. #define SCUMM_NEED_ALIGNMENT
  262. #else
  263. #error No system type defined
  264. #endif
  265. //
  266. // GCC specific stuff
  267. //
  268. #if defined(__GNUC__)
  269. #define NORETURN_POST __attribute__((__noreturn__))
  270. #define PACKED_STRUCT __attribute__((__packed__))
  271. #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
  272. #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  273. #define FORCEINLINE inline __attribute__((__always_inline__))
  274. #endif
  275. #else
  276. #define PACKED_STRUCT
  277. #define GCC_PRINTF(x,y)
  278. #endif
  279. //
  280. // Fallbacks / default values for various special macros
  281. //
  282. #ifndef FORCEINLINE
  283. #define FORCEINLINE inline
  284. #endif
  285. #ifndef PLUGIN_EXPORT
  286. #define PLUGIN_EXPORT
  287. #endif
  288. #ifndef NORETURN_PRE
  289. #define NORETURN_PRE
  290. #endif
  291. #ifndef NORETURN_POST
  292. #define NORETURN_POST
  293. #endif
  294. #ifndef STRINGBUFLEN
  295. #define STRINGBUFLEN 1024
  296. #endif
  297. #ifndef PI
  298. #define PI 3.14159265358979323846
  299. #endif
  300. #ifndef MAXPATHLEN
  301. #define MAXPATHLEN 256
  302. #endif
  303. //
  304. // Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
  305. //
  306. #ifndef SCUMMVM_DONT_DEFINE_TYPES
  307. typedef unsigned char byte;
  308. typedef unsigned char uint8;
  309. typedef signed char int8;
  310. typedef unsigned short uint16;
  311. typedef signed short int16;
  312. typedef unsigned int uint32;
  313. typedef signed int int32;
  314. typedef unsigned int uint;
  315. #endif
  316. //
  317. // Overlay color type (FIXME: shouldn't be declared here)
  318. //
  319. #if defined(NEWGUI_256)
  320. // 256 color only on PalmOS
  321. typedef byte OverlayColor;
  322. #else
  323. // 15/16 bit color mode everywhere else...
  324. typedef uint16 OverlayColor;
  325. #endif
  326. #endif