22#ifndef COMMON_SCUMMSYS_H
23#define COMMON_SCUMMSYS_H
26 #define __has_feature(x) 0
33 #define GCC_ATLEAST(major, minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
35 #define GCC_ATLEAST(major, minor) 0
38#if defined(_MSC_VER) && _MSC_VER < 1900
39 #error MSVC support requires MSVC 2015 or newer
42#if defined(NONSTANDARD_PORT)
53 #define WIN32_LEAN_AND_MEAN
80 #if defined(__QNXNTO__)
96 #define __STDC_CONSTANT_MACROS
97 #define __STDC_FORMAT_MACROS
98 #define __STDC_LIMIT_MACROS
102 #if defined(MACOSX) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
103 #undef __PRI_8_LENGTH_MODIFIER__
104 #undef __PRI_64_LENGTH_MODIFIER__
105 #undef __SCN_64_LENGTH_MODIFIER__
106 #define __PRI_8_LENGTH_MODIFIER__ "hh"
107 #define __PRI_64_LENGTH_MODIFIER__ "ll"
108 #define __SCN_64_LENGTH_MODIFIER__ "ll"
117 #define _USE_MATH_DEFINES
139 #define M_E 2.7182818284590452354
143 #define M_LOG2E 1.4426950408889634074
147 #define M_LOG10E 0.43429448190325182765
151 #define M_LN2 0.69314718055994530942
155 #define M_LN10 2.30258509299404568402
159 #define M_PI 3.14159265358979323846
163 #define M_PI_2 1.57079632679489661923
167 #define M_PI_4 0.78539816339744830962
171 #define M_1_PI 0.31830988618379067154
175 #define M_2_PI 0.63661977236758134308
179 #define M_2_SQRTPI 1.12837916709551257390
183 #define M_SQRT2 1.41421356237309504880
187 #define M_SQRT1_2 0.70710678118654752440
191#if defined(HAVE_CONFIG_H)
216#if __has_feature(alignment_sanitizer) || __has_feature(undefined_behavior_sanitizer)
217 #define SCUMM_NEED_ALIGNMENT
231#define SCUMMVM_USE_PRAGMA_PACK
236#if !defined(HAVE_CONFIG_H)
238 #if defined(__DC__) || \
240 defined(__3DS__) || \
244 #define SCUMM_LITTLE_ENDIAN
245 #define SCUMM_NEED_ALIGNMENT
247 #elif defined(_MSC_VER) || defined(__MINGW32__)
249 #define SCUMM_LITTLE_ENDIAN
251 #elif defined(__MORPHOS__) || defined(__amigaos4__) || defined(__N64__) || defined(__WII__)
253 #define SCUMM_BIG_ENDIAN
254 #define SCUMM_NEED_ALIGNMENT
256 #elif defined(SDL_BACKEND)
260 #include <SDL_endian.h>
262 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
263 #define SCUMM_LITTLE_ENDIAN
264 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
265 #define SCUMM_BIG_ENDIAN
267 #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
272 #error No system type defined, host endianess unknown.
277#if !defined(SCUMM_FLOAT_WORD_LITTLE_ENDIAN) && !defined(SCUMM_FLOAT_WORD_BIG_ENDIAN)
279 #if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__FLOAT_WORD_ORDER__)
281 #if (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
282 #define SCUMM_FLOAT_WORD_LITTLE_ENDIAN
283 #elif (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
284 #define SCUMM_FLOAT_WORD_BIG_ENDIAN
286 #error Unsupported endianness
290 #ifdef SCUMM_LITTLE_ENDIAN
291 #define SCUMM_FLOAT_WORD_LITTLE_ENDIAN
293 #define SCUMM_FLOAT_WORD_BIG_ENDIAN
299#if defined(USE_TREMOR) && !defined(USE_VORBIS)
307 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
308 #if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO && !defined(__clang__)
309 #define GCC_PRINTF(x,y) __attribute__((__format__(__gnu_printf__, x, y)))
311 #define GCC_PRINTF(x,y) __attribute__((__format__(__printf__, x, y)))
314 #define GCC_PRINTF(x,y)
319 #if defined(_MSC_VER)
320 #define MSVC_PRINTF _Printf_format_string_
327 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
328 #define PACKED_STRUCT __attribute__((__packed__))
330 #define PACKED_STRUCT
335 #if defined(_MSC_VER)
336 #define FORCEINLINE __forceinline
337 #elif defined(__GNUC__)
338 #define FORCEINLINE inline __attribute__((__always_inline__))
340 #define FORCEINLINE inline
345 #if defined(_MSC_VER) || defined(__MINGW32__)
346 #define PLUGIN_EXPORT __declspec(dllexport)
348 #define PLUGIN_EXPORT
353 #if defined(_MSC_VER)
354 #define NORETURN_PRE __declspec(noreturn)
355 #elif defined(__GNUC__)
356 #define NORETURN_PRE __attribute__((__noreturn__))
363 #if defined(__INTEL_COMPILER)
364 #define NORETURN_POST __attribute__((__noreturn__))
366 #define NORETURN_POST
370#ifndef WARN_UNUSED_RESULT
371 #if __cplusplus >= 201703L
372 #define WARN_UNUSED_RESULT [[nodiscard]]
373 #elif defined(__GNUC__)
374 #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
375 #elif defined(_Check_return_)
376 #define WARN_UNUSED_RESULT _Check_return_
378 #define WARN_UNUSED_RESULT
382#ifndef WARN_DEPRECATED
383 #if __cplusplus >= 201703L
384 #define WARN_DEPRECATED(msg) [[deprecated(msg)]]
385 #elif defined(__GNUC__)
386 #define WARN_DEPRECATED(msg) __attribute__((__deprecated__(msg)))
387 #elif defined(_MSC_VER)
388 #define WARN_DEPRECATED(msg) __declspec(deprecated(msg))
390 #define WARN_DEPRECATED(msg)
395 #if defined(__N64__) || defined(__DS__) || defined(__3DS__)
396 #define STRINGBUFLEN 256
398 #define STRINGBUFLEN 1024
403#define MAXPATHLEN 256
408 #define scumm_va_copy va_copy
409 #elif defined(__va_copy)
410 #define scumm_va_copy __va_copy
411 #elif defined(_MSC_VER)
412 #define scumm_va_copy(dst, src) ((dst) = (src))
414 #error scumm_va_copy undefined for this port
424#ifndef SCUMMVM_DONT_DEFINE_TYPES
425 typedef unsigned char byte;
426 typedef unsigned int uint;
428 typedef uint8_t uint8;
430 typedef uint16_t uint16;
431 typedef int16_t int16;
432#if defined(__3DS__) || defined(__DC__) || defined(__PSP__)
437 typedef unsigned int uint32;
439#elif defined(__amigaos4__) || defined(__MORPHOS__)
445 typedef unsigned long uint32;
446 typedef signed long int32;
448 typedef uint32_t uint32;
449 typedef int32_t int32;
451 typedef uint64_t uint64;
452 typedef int64_t int64;
453 typedef uintptr_t uintptr;
454 typedef intptr_t intptr;
461#if defined(NO_CXX11_NULLPTR_T)
463 typedef decltype(
nullptr) nullptr_t;
471#if defined(NO_CXX11_INITIALIZER_LIST)
473 template<
class T>
class initializer_list {
475 typedef T value_type;
476 typedef const T &reference;
477 typedef const T &const_reference;
478 typedef size_t size_type;
479 typedef const T *iterator;
480 typedef const T *const_iterator;
482 constexpr initializer_list() noexcept = default;
483 constexpr
size_t size() const noexcept {
return _size; };
484 constexpr const T *begin() const noexcept {
return _begin; };
485 constexpr const T *end() const noexcept {
return _begin + _size; }
489 const T *_begin = {
nullptr };
490 size_t _size = { 0 };
493 constexpr initializer_list(
const T* t,
size_t s) noexcept : _begin(t) , _size(s) {}
496 template<
class T>
constexpr const T* begin(initializer_list<T> il)
noexcept {
500 template<
class T>
constexpr const T* end(initializer_list<T> il)
noexcept {
507#include <initializer_list>
520 #define toupper(c) __extension__ ({ auto _x = ((c) & 0xFF); (_x >= 97 && _x <= 122) ? (_x - 32) : _x; })
522#elif defined(__PSP__)
525 #include "backends/platform/psp/memory.h"
528 #define memcpy(dst, src, size) psp_memcpy(dst, src, size)