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


Generated on Sat Jul 13 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge