ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

scummsys.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_SCUMMSYS_H
00024 #define COMMON_SCUMMSYS_H
00025 
00026 #ifndef __has_feature           // Optional of course.
00027     #define __has_feature(x) 0  // Compatibility with non-clang compilers.
00028 #endif
00029 
00030 // This is a convenience macro to test whether the compiler used is a GCC
00031 // version, which is at least major.minor.
00032 #ifdef __GNUC__
00033     #define GCC_ATLEAST(major, minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
00034 #else
00035     #define GCC_ATLEAST(major, minor) 0
00036 #endif
00037 
00038 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
00039     #define NONSTANDARD_PORT
00040 #endif
00041 
00042 #if defined(NONSTANDARD_PORT)
00043 
00044     // Ports which need to perform #includes and #defines visible in
00045     // virtually all the source of ScummVM should do so by providing a
00046     // "portdefs.h" header file (and not by directly modifying this
00047     // header file).
00048     #include <portdefs.h>
00049 #else // defined(NONSTANDARD_PORT)
00050 
00051     #if defined(WIN32)
00052 
00053         #if defined(_MSC_VER) && _MSC_VER <= 1800
00054 
00055         // FIXME: The placement of the workaround functions for MSVC below
00056         // require us to include stdio.h and stdarg.h for MSVC here. This
00057         // is not exactly nice...
00058         // We should think of a better way of doing this.
00059         #include <stdio.h>
00060         #include <stdarg.h>
00061 
00062         // MSVC's vsnprintf is either non-existent (2003) or bugged since it
00063         // does not always include a terminating NULL (2005+). To work around
00064         // that we fix up the _vsnprintf included. Note that the return value
00065         // will still not match C99's specs!
00066         inline int vsnprintf_msvc(char *str, size_t size, const char *format, va_list args) {
00067             // We do not pass size - 1 here, to ensure we would get the same
00068             // return value as when we would use _vsnprintf directly, since
00069             // for example Common::String::format relies on this.
00070             int retValue = _vsnprintf(str, size, format, args);
00071             str[size - 1] = 0;
00072             return retValue;
00073         }
00074 
00075         #define vsnprintf vsnprintf_msvc
00076 
00077         // Visual Studio does not include snprintf in its standard C library.
00078         // Instead it includes a function called _snprintf with somewhat
00079         // similar semantics. The minor difference is that the return value in
00080         // case the formatted string exceeds the buffer size is different.
00081         // A much more dangerous one is that _snprintf does not always include
00082         // a terminating null (Whoops!). Instead we map to our fixed vsnprintf.
00083         inline int snprintf(char *str, size_t size, const char *format, ...) {
00084             va_list args;
00085             va_start(args, format);
00086             int len = vsnprintf(str, size, format, args);
00087             va_end(args);
00088             return len;
00089         }
00090         #endif
00091 
00092         #if !defined(_WIN32_WCE)
00093 
00094         #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
00095         #define NOGDICAPMASKS
00096         #define OEMRESOURCE
00097         #define NONLS
00098         #define NOICONS
00099         #define NOMCX
00100         #define NOPROFILER
00101         #define NOKANJI
00102         #define NOSERVICE
00103         #define NOMETAFILE
00104         #define NOCOMM
00105         #define NOCRYPT
00106         #define NOIME
00107         #define NOATOM
00108         #define NOCTLMGR
00109         #define NOCLIPBOARD
00110         #define NOMEMMGR
00111         #define NOSYSMETRICS
00112         #define NOMENUS
00113         #define NOOPENFILE
00114         #define NOWH
00115         #define NOSOUND
00116         #define NODRAWTEXT
00117 
00118         #endif
00119 
00120     #endif
00121 
00122     #if defined(__QNXNTO__)
00123     #include <strings.h>    /* For strcasecmp */
00124     #endif
00125 
00126     #include <stdio.h>
00127     #include <stdlib.h>
00128     #include <string.h>
00129     #include <stdarg.h>
00130     #include <stddef.h>
00131     #include <assert.h>
00132     #include <ctype.h>
00133     // MSVC does not define M_PI, M_SQRT2 and other math defines by default.
00134     // _USE_MATH_DEFINES must be defined in order to have these defined, thus
00135     // we enable it here. For more information, check:
00136     // http://msdn.microsoft.com/en-us/library/4hwaceh6(v=VS.100).aspx
00137     #define _USE_MATH_DEFINES
00138     #include <math.h>
00139 
00140     // FIXME: We sadly can't assume standard C++ headers to be present on every
00141     // system we support, so we should get rid of this. The solution should be to
00142     // write a simple placement new on our own. It might be noteworthy we can't
00143     // easily do that for systems which do have a <new>, since it might clash with
00144     // the default definition otherwise!
00145     // Symbian does not have <new> but the new operator
00146     #if !defined(__SYMBIAN32__)
00147     #include <new>
00148     #endif
00149 #endif
00150 
00151 #ifndef STATIC_ASSERT
00152 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER > 1600)
00153 
00160     #define STATIC_ASSERT(expression, message) \
00161         static_assert((expression), #message)
00162 #else
00163 
00170     #define STATIC_ASSERT(expression, message) \
00171         do { \
00172             extern int STATIC_ASSERT_##message[(expression) ? 1 : -1]; \
00173             (void)(STATIC_ASSERT_##message); \
00174         } while (false)
00175 #endif
00176 #endif
00177 
00178 // The following math constants are usually defined by the system math.h header, but
00179 // they are not part of the ANSI C++ standards and so can NOT be relied upon to be
00180 // present i.e. when -std=c++11 is passed to GCC, enabling strict ANSI compliance.
00181 // As we rely on these being present, we define them if they are not set.
00182 
00183 #ifndef M_E
00184     #define M_E 2.7182818284590452354 /* e */
00185 #endif
00186 
00187 #ifndef M_LOG2E
00188     #define M_LOG2E 1.4426950408889634074 /* log_2 e */
00189 #endif
00190 
00191 #ifndef M_LOG10E
00192     #define M_LOG10E 0.43429448190325182765 /* log_10 e */
00193 #endif
00194 
00195 #ifndef M_LN2
00196     #define M_LN2 0.69314718055994530942 /* log_e 2 */
00197 #endif
00198 
00199 #ifndef M_LN10
00200     #define M_LN10 2.30258509299404568402 /* log_e 10 */
00201 #endif
00202 
00203 #ifndef M_PI
00204     #define M_PI 3.14159265358979323846 /* pi */
00205 #endif
00206 
00207 #ifndef M_PI_2
00208     #define M_PI_2 1.57079632679489661923 /* pi/2 */
00209 #endif
00210 
00211 #ifndef M_PI_4
00212     #define M_PI_4 0.78539816339744830962 /* pi/4 */
00213 #endif
00214 
00215 #ifndef M_1_PI
00216     #define M_1_PI 0.31830988618379067154 /* 1/pi */
00217 #endif
00218 
00219 #ifndef M_2_PI
00220     #define M_2_PI 0.63661977236758134308 /* 2/pi */
00221 #endif
00222 
00223 #ifndef M_2_SQRTPI
00224     #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
00225 #endif
00226 
00227 #ifndef M_SQRT2
00228     #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
00229 #endif
00230 
00231 #ifndef M_SQRT1_2
00232     #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
00233 #endif
00234 
00235 // Include our C++11 compatability header for pre-C++11 compilers.
00236 #if __cplusplus < 201103L
00237 #include "common/c++11-compat.h"
00238 #endif
00239 
00240 // Use config.h, generated by configure
00241 #if defined(HAVE_CONFIG_H)
00242 #include "config.h"
00243 #endif
00244 
00245 
00246 // In the following we configure various targets, in particular those
00247 // which can't use our "configure" tool and hence don't use config.h.
00248 //
00249 // Some #defines that occur here frequently:
00250 // SCUMM_LITTLE_ENDIAN
00251 //    - Define this on a little endian target
00252 // SCUMM_BIG_ENDIAN
00253 //    - Define this on a big endian target
00254 // SCUMM_NEED_ALIGNMENT
00255 //    - Define this if your system has problems reading e.g. an int32 from an odd address
00256 // SMALL_SCREEN_DEVICE
00257 //    - ...
00258 // ...
00259 
00260 
00261 //
00262 // By default we try to use pragma push/pop to ensure various structs we use
00263 // are "packed". If your compiler doesn't support this pragma, you are in for
00264 // a problem. If you are lucky, there is a compiler switch, or another pragma,
00265 // doing the same thing -- in that case, try to modify common/pack-begin.h and
00266 // common/pack-end.h accordingly. Or maybe your port simply *always* packs
00267 // everything, in which case you could #undefine SCUMMVM_USE_PRAGMA_PACK.
00268 //
00269 // If neither is possible, tough luck. Try to contact the team, maybe we can
00270 // come up with a solution, though I wouldn't hold my breath on it :-/.
00271 //
00272 #define SCUMMVM_USE_PRAGMA_PACK
00273 
00274 //
00275 // Determine the host endianess and whether memory alignment is required.
00276 //
00277 #if !defined(HAVE_CONFIG_H)
00278 
00279     #if defined(__DC__) || \
00280           defined(__DS__) || \
00281           defined(__3DS__) || \
00282           defined(IPHONE) || \
00283           defined(__PLAYSTATION2__) || \
00284           defined(__PSP__) || \
00285           defined(__SYMBIAN32__)
00286 
00287         #define SCUMM_LITTLE_ENDIAN
00288         #define SCUMM_NEED_ALIGNMENT
00289 
00290     #elif defined(_WIN32_WCE) || defined(_MSC_VER) || defined(__MINGW32__)
00291 
00292         #define SCUMM_LITTLE_ENDIAN
00293 
00294     #elif defined(__amigaos4__) || defined(__N64__) || defined(__WII__)
00295 
00296         #define SCUMM_BIG_ENDIAN
00297         #define SCUMM_NEED_ALIGNMENT
00298 
00299     #elif defined(SDL_BACKEND)
00300         // On SDL based ports, we try to use SDL_BYTEORDER to determine the
00301         // endianess. We explicitly do this as the *last* thing we try, so that
00302         // platform specific settings have precedence.
00303         #include <SDL_endian.h>
00304 
00305         #if SDL_BYTEORDER == SDL_LIL_ENDIAN
00306         #define SCUMM_LITTLE_ENDIAN
00307         #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
00308         #define SCUMM_BIG_ENDIAN
00309         #else
00310         #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
00311         #endif
00312 
00313     #else
00314 
00315         #error No system type defined, host endianess unknown.
00316 
00317     #endif
00318 #endif
00319 
00320 //
00321 // Some more system specific settings.
00322 // TODO/FIXME: All of these should be moved to backend specific files (such as portdefs.h)
00323 //
00324 #if defined(DINGUX)
00325 
00326     // Very BAD hack following, used to avoid triggering an assert in uClibc dingux library
00327     // "toupper" when pressing keyboard function keys.
00328     #undef toupper
00329     #define toupper(c) (((c & 0xFF) >= 97) && ((c & 0xFF) <= 122) ? ((c & 0xFF) - 32) : (c & 0xFF))
00330 
00331 #elif defined(__PSP__)
00332 
00333     #include <malloc.h>
00334     #include "backends/platform/psp/memory.h"
00335 
00336     /* to make an efficient, inlined memcpy implementation */
00337     #define memcpy(dst, src, size)   psp_memcpy(dst, src, size)
00338 
00339 #endif
00340 
00341 #if defined(USE_TREMOR) && !defined(USE_VORBIS)
00342 #define USE_VORBIS // make sure this one is defined together with USE_TREMOR!
00343 #endif
00344 
00345 //
00346 // Fallbacks / default values for various special macros
00347 //
00348 #ifndef GCC_PRINTF
00349     #if defined(__GNUC__) || defined(__INTEL_COMPILER)
00350         #define GCC_PRINTF(x,y) __attribute__((__format__(__printf__, x, y)))
00351     #else
00352         #define GCC_PRINTF(x,y)
00353     #endif
00354 #endif
00355 
00356 #ifndef PACKED_STRUCT
00357     #if defined(__GNUC__) || defined(__INTEL_COMPILER)
00358         #define PACKED_STRUCT __attribute__((__packed__))
00359     #else
00360         #define PACKED_STRUCT
00361     #endif
00362 #endif
00363 
00364 #ifndef FORCEINLINE
00365     #if defined(_MSC_VER)
00366         #define FORCEINLINE __forceinline
00367     #elif GCC_ATLEAST(3, 1)
00368         #define FORCEINLINE inline __attribute__((__always_inline__))
00369     #else
00370         #define FORCEINLINE inline
00371     #endif
00372 #endif
00373 
00374 #ifndef PLUGIN_EXPORT
00375     #if defined(_MSC_VER) || defined(_WIN32_WCE) || defined(__MINGW32__)
00376         #define PLUGIN_EXPORT __declspec(dllexport)
00377     #else
00378         #define PLUGIN_EXPORT
00379     #endif
00380 #endif
00381 
00382 #ifndef NORETURN_PRE
00383     #if defined(_MSC_VER)
00384         #define NORETURN_PRE __declspec(noreturn)
00385     #else
00386         #define NORETURN_PRE
00387     #endif
00388 #endif
00389 
00390 #ifndef NORETURN_POST
00391     #if defined(__GNUC__) || defined(__INTEL_COMPILER)
00392         #define NORETURN_POST __attribute__((__noreturn__))
00393     #else
00394         #define NORETURN_POST
00395     #endif
00396 #endif
00397 
00398 #ifndef WARN_UNUSED_RESULT
00399     #if __cplusplus >= 201703L
00400         #define WARN_UNUSED_RESULT [[nodiscard]]
00401     #elif GCC_ATLEAST(3, 4)
00402         #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
00403     #elif defined(_Check_return_)
00404         #define WARN_UNUSED_RESULT _Check_return_
00405     #else
00406         #define WARN_UNUSED_RESULT
00407     #endif
00408 #endif
00409 
00410 #ifndef STRINGBUFLEN
00411     #if defined(__N64__) || defined(__DS__) || defined(__3DS__)
00412         #define STRINGBUFLEN 256
00413     #else
00414         #define STRINGBUFLEN 1024
00415     #endif
00416 #endif
00417 
00418 // ResidualVM specific:
00419 #ifndef LOCAL_PI
00420 #define LOCAL_PI 3.14159265358979323846
00421 #endif
00422 
00423 #ifndef MAXPATHLEN
00424 #define MAXPATHLEN 256
00425 #endif
00426 
00427 #ifndef scumm_va_copy
00428     #if defined(va_copy)
00429         #define scumm_va_copy va_copy
00430     #elif defined(__va_copy)
00431         #define scumm_va_copy __va_copy
00432     #elif defined(_MSC_VER) || defined(__SYMBIAN32__)
00433         #define scumm_va_copy(dst, src)       ((dst) = (src))
00434     #else
00435         #error scumm_va_copy undefined for this port
00436     #endif
00437 #endif
00438 
00439 
00440 
00441 //
00442 // Typedef our system types unless they have already been defined by config.h,
00443 // or SCUMMVM_DONT_DEFINE_TYPES is set.
00444 //
00445 #if !defined(HAVE_CONFIG_H) && !defined(SCUMMVM_DONT_DEFINE_TYPES)
00446     typedef unsigned char byte;
00447     typedef unsigned char uint8;
00448     typedef signed char int8;
00449     typedef unsigned short uint16;
00450     typedef signed short int16;
00451     typedef unsigned int uint32;
00452     typedef signed int int32;
00453     typedef unsigned int uint;
00454     #ifdef __PLAYSTATION2__
00455     typedef signed long int64;
00456     typedef unsigned long uint64;
00457     #else
00458     typedef signed long long int64;
00459     typedef unsigned long long uint64;
00460     #endif
00461 #endif
00462 
00463 //
00464 // Determine 64 bitness
00465 // Reference: http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros
00466 //
00467 #if !defined(HAVE_CONFIG_H)
00468 
00469 #if defined(__x86_64__) || \
00470           defined(_M_X64) || \
00471           defined(__ppc64__) || \
00472           defined(__powerpc64__) || \
00473           defined(__LP64__)
00474 
00475 typedef uint64 uintptr;
00476 
00477 #else
00478 
00479 typedef uint32 uintptr;
00480 
00481 #endif
00482 
00483 #endif
00484 
00485 #include "common/forbidden.h"
00486 
00487 #endif


Generated on Sat Feb 16 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge