#ifndef BLARGG_COMMON_H
#define BLARGG_COMMON_H
#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#undef BLARGG_COMMON_H
#include "blargg_config.h"
#ifndef BLARGG_COMMON_H
#define BLARGG_COMMON_H
#if __GNUC__ >= 3 || _MSC_VER >= 1100
#define BLARGG_RESTRICT __restrict
#else
#define BLARGG_RESTRICT
#endif
#ifndef STATIC_CAST
#define STATIC_CAST(T,expr) ((T) (expr))
#endif
#ifndef blargg_err_t
typedef const char* blargg_err_t;
#endif
template<class T>
class blargg_vector {
T* begin_;
size_t size_;
public:
blargg_vector() : begin_( 0 ), size_( 0 ) { }
~blargg_vector() { free( begin_ ); }
size_t size() const { return size_; }
T* begin() const { return begin_; }
T* end() const { return begin_ + size_; }
blargg_err_t resize( size_t n )
{
void* p = realloc( begin_, n * sizeof (T) );
if ( !p && n )
return "Out of memory";
begin_ = (T*) p;
size_ = n;
return 0;
}
void clear() { free( begin_ ); begin_ = nullptr; size_ = 0; }
T& operator [] ( size_t n ) const
{
assert( n <= size_ ); return begin_ [n];
}
};
#include <new>
#ifndef BLARGG_DISABLE_NOTHROW
#define BLARGG_DISABLE_NOTHROW \
void* operator new ( size_t s ) noexcept { return malloc( s ); }\
void* operator new ( size_t s, const std::nothrow_t& ) noexcept { return malloc( s ); }\
void operator delete ( void* p ) noexcept { free( p ); }
#endif
#define BLARGG_NEW new (std::nothrow)
#define BLARGG_4CHAR( a, b, c, d ) \
((a&0xFF)*0x1000000L + (b&0xFF)*0x10000L + (c&0xFF)*0x100L + (d&0xFF))
#define BLARGG_2CHAR( a, b ) \
((a&0xFF)*0x100L + (b&0xFF))
#ifndef BLARGG_COMPILER_HAS_BOOL
#if defined (__MWERKS__)
#if !__option(bool)
#define BLARGG_COMPILER_HAS_BOOL 0
#endif
#elif defined (_MSC_VER)
#if _MSC_VER < 1100
#define BLARGG_COMPILER_HAS_BOOL 0
#endif
#elif defined (__GNUC__)
#elif __cplusplus < 199711
#define BLARGG_COMPILER_HAS_BOOL 0
#endif
#endif
#if defined (BLARGG_COMPILER_HAS_BOOL) && !BLARGG_COMPILER_HAS_BOOL
typedef int bool;
const bool true = 1;
const bool false = 0;
#endif
#if defined(__has_cpp_attribute)
# if __has_cpp_attribute(maybe_unused)
# define BLARGG_MAYBE_UNUSED [[maybe_unused]]
# endif
#endif
#ifndef BLARGG_MAYBE_UNUSED
# define BLARGG_MAYBE_UNUSED
#endif
#if INT_MAX < 0x7FFFFFFF || LONG_MAX == 0x7FFFFFFF
typedef long blargg_long;
#else
typedef int blargg_long;
#endif
#if UINT_MAX < 0xFFFFFFFF || ULONG_MAX == 0xFFFFFFFF
typedef unsigned long blargg_ulong;
#else
typedef unsigned blargg_ulong;
#endif
#if 1 || defined (HAVE_STDINT_H)
#include <stdint.h>
#endif
#if __GNUC__ >= 3
#define BLARGG_DEPRECATED __attribute__ ((deprecated))
#else
#define BLARGG_DEPRECATED
#endif
#ifndef BLARGG_PURE
#define BLARGG_PURE( def ) def
#endif
#endif
#endif