| 1 | |
| 2 | // Sets up common environment for Shay Green's libraries. |
| 3 | // |
| 4 | // Don't modify this file directly; #define HAVE_CONFIG_H and put your |
| 5 | // configuration into "config.h". |
| 6 | |
| 7 | // Copyright (C) 2004-2005 Shay Green. |
| 8 | |
| 9 | #ifndef BLARGG_COMMON_H |
| 10 | #define BLARGG_COMMON_H |
| 11 | |
| 12 | // Allow prefix configuration file *which can re-include blargg_common.h* |
| 13 | // (probably indirectly). |
| 14 | #ifdef HAVE_CONFIG_H |
| 15 | #undef BLARGG_COMMON_H |
| 16 | #include "config.h" |
| 17 | #define BLARGG_COMMON_H |
| 18 | #endif |
| 19 | |
| 20 | // Source files use #include BLARGG_ENABLE_OPTIMIZER before performance-critical code |
| 21 | #ifndef BLARGG_ENABLE_OPTIMIZER |
| 22 | #define BLARGG_ENABLE_OPTIMIZER "blargg_common.h" |
| 23 | #endif |
| 24 | |
| 25 | // Source files have #include BLARGG_SOURCE_BEGIN at the beginning |
| 26 | #ifndef BLARGG_SOURCE_BEGIN |
| 27 | #define BLARGG_SOURCE_BEGIN "blargg_source.h" |
| 28 | #endif |
| 29 | |
| 30 | // Determine compiler's language support |
| 31 | |
| 32 | #if defined (__MWERKS__) |
| 33 | // Metrowerks CodeWarrior |
| 34 | #define BLARGG_COMPILER_HAS_NAMESPACE 1 |
| 35 | #if !__option(bool) |
| 36 | #define BLARGG_COMPILER_HAS_BOOL 0 |
| 37 | #endif |
| 38 | |
| 39 | #elif defined (_MSC_VER) |
| 40 | // Microsoft Visual C++ |
| 41 | #if _MSC_VER < 1100 |
| 42 | #define BLARGG_COMPILER_HAS_BOOL 0 |
| 43 | #endif |
| 44 | |
| 45 | #elif defined (__GNUC__) |
| 46 | // GNU C++ |
| 47 | #define BLARGG_COMPILER_HAS_NAMESPACE 1 |
| 48 | #define BLARGG_COMPILER_HAS_BOOL 1 |
| 49 | |
| 50 | #elif defined (__MINGW32__) |
| 51 | // Mingw? |
| 52 | #define BLARGG_COMPILER_HAS_BOOL 1 |
| 53 | |
| 54 | #elif __cplusplus < 199711 |
| 55 | // Pre-ISO C++ compiler |
| 56 | #define BLARGG_COMPILER_HAS_BOOL 0 |
| 57 | #define BLARGG_NEW new |
| 58 | #define STATIC_CAST( type ) (type) |
| 59 | |
| 60 | #endif |
| 61 | |
| 62 | // STATIC_CAST(T) (expr) -> static_cast< T > (expr) |
| 63 | #ifndef STATIC_CAST |
| 64 | #define STATIC_CAST( type ) static_cast< type > |
| 65 | #endif |
| 66 | |
| 67 | // Set up boost |
| 68 | #include "boost/config.hpp" |
| 69 | #ifndef BOOST_MINIMAL |
| 70 | #define BOOST boost |
| 71 | #ifndef BLARGG_COMPILER_HAS_NAMESPACE |
| 72 | #define BLARGG_COMPILER_HAS_NAMESPACE 1 |
| 73 | #endif |
| 74 | #ifndef BLARGG_COMPILER_HAS_BOOL |
| 75 | #define BLARGG_COMPILER_HAS_BOOL 1 |
| 76 | #endif |
| 77 | #endif |
| 78 | |
| 79 | // Bool support |
| 80 | #ifndef BLARGG_COMPILER_HAS_BOOL |
| 81 | #define BLARGG_COMPILER_HAS_BOOL 1 |
| 82 | #elif !BLARGG_COMPILER_HAS_BOOL |
| 83 | typedef int bool; |
| 84 | const bool true = 1; |
| 85 | const bool false = 0; |
| 86 | #endif |
| 87 | |
| 88 | // Set up namespace support |
| 89 | |
| 90 | #ifndef BLARGG_COMPILER_HAS_NAMESPACE |
| 91 | #define BLARGG_COMPILER_HAS_NAMESPACE 0 |
| 92 | #endif |
| 93 | |
| 94 | #ifndef BLARGG_USE_NAMESPACE |
| 95 | #define BLARGG_USE_NAMESPACE BLARGG_COMPILER_HAS_NAMESPACE |
| 96 | #endif |
| 97 | |
| 98 | #ifndef BOOST |
| 99 | #if BLARGG_USE_NAMESPACE |
| 100 | #define BOOST boost |
| 101 | #else |
| 102 | #define BOOST |
| 103 | #endif |
| 104 | #endif |
| 105 | |
| 106 | #undef BLARGG_BEGIN_NAMESPACE |
| 107 | #undef BLARGG_END_NAMESPACE |
| 108 | #if BLARGG_USE_NAMESPACE |
| 109 | #define BLARGG_BEGIN_NAMESPACE( name ) namespace name { |
| 110 | #define BLARGG_END_NAMESPACE } |
| 111 | #else |
| 112 | #define BLARGG_BEGIN_NAMESPACE( name ) |
| 113 | #define BLARGG_END_NAMESPACE |
| 114 | #endif |
| 115 | |
| 116 | #if BLARGG_USE_NAMESPACE |
| 117 | #define STD std |
| 118 | #else |
| 119 | #define STD |
| 120 | #endif |
| 121 | |
| 122 | // BOOST::uint8_t, BOOST::int16_t, etc. |
| 123 | #include "boost/cstdint.hpp" |
| 124 | |
| 125 | // BOOST_STATIC_ASSERT( expr ) |
| 126 | #include "boost/static_assert.hpp" |
| 127 | |
| 128 | // Common standard headers |
| 129 | #if BLARGG_COMPILER_HAS_NAMESPACE |
| 130 | #include <cstddef> |
| 131 | #include <cassert> |
| 132 | #include <new> |
| 133 | #else |
| 134 | #include <stddef.h> |
| 135 | #include <assert.h> |
| 136 | #endif |
| 137 | |
| 138 | // blargg_err_t (NULL on success, otherwise error string) |
| 139 | typedef const char* blargg_err_t; |
| 140 | const blargg_err_t blargg_success = 0; |
| 141 | |
| 142 | // BLARGG_NEW is used in place of 'new' to create objects. By default, |
| 143 | // nothrow new is used. |
| 144 | #ifndef BLARGG_NEW |
| 145 | #define BLARGG_NEW new (STD::nothrow) |
| 146 | #endif |
| 147 | |
| 148 | // BLARGG_BIG_ENDIAN and BLARGG_LITTLE_ENDIAN |
| 149 | // Only needed if modules are used which must know byte order. |
| 150 | #if !defined (BLARGG_BIG_ENDIAN) && !defined (BLARGG_LITTLE_ENDIAN) |
| 151 | #if defined (__powerc) || defined (macintosh) |
| 152 | #define BLARGG_BIG_ENDIAN 1 |
| 153 | |
| 154 | #elif defined (_MSC_VER) && defined (_M_IX86) |
| 155 | #define BLARGG_LITTLE_ENDIAN 1 |
| 156 | |
| 157 | #endif |
| 158 | #endif |
| 159 | |
| 160 | // BLARGG_NONPORTABLE (allow use of nonportable optimizations/features) |
| 161 | #ifndef BLARGG_NONPORTABLE |
| 162 | #define BLARGG_NONPORTABLE 0 |
| 163 | #endif |
| 164 | #ifdef BLARGG_MOST_PORTABLE |
| 165 | #error "BLARGG_MOST_PORTABLE has been removed; use BLARGG_NONPORTABLE." |
| 166 | #endif |
| 167 | |
| 168 | // BLARGG_CPU_* |
| 169 | #if !defined (BLARGG_CPU_POWERPC) && !defined (BLARGG_CPU_X86) |
| 170 | #if defined (__powerc) |
| 171 | #define BLARGG_CPU_POWERPC 1 |
| 172 | |
| 173 | #elif defined (_MSC_VER) && defined (_M_IX86) |
| 174 | #define BLARGG_CPU_X86 1 |
| 175 | |
| 176 | #endif |
| 177 | #endif |
| 178 | |
| 179 | #endif |
| 180 | |
| 181 | |