/* Included at the beginning of library source files, AFTER all other #include1lines. Sets up helpful macros and services used in my source code. Since this2is only "active" in my source code, I don't have to worry about polluting the3global namespace with unprefixed names. */45// File_Extractor 1.0.06#ifndef BLARGG_SOURCE_H7#define BLARGG_SOURCE_H89#ifndef BLARGG_COMMON_H // optimization only10#include "blargg_common.h"11#endif12#include "blargg_errors.h"1314#include <string.h> /* memcpy(), memset(), memmove() */15#include <stddef.h> /* offsetof() */1617/* The following four macros are for debugging only. Some or all might be18defined to do nothing, depending on the circumstances. Described is what19happens when a particular macro is defined to do something. When defined to20do nothing, the macros do NOT evaluate their argument(s). */2122/* If expr is false, prints file and line number, then aborts program. Meant23for checking internal state and consistency. A failed assertion indicates a bug24in MY code.2526void assert( bool expr ); */27#include <assert.h>2829/* If expr is false, prints file and line number, then aborts program. Meant30for checking caller-supplied parameters and operations that are outside the31control of the module. A failed requirement probably indicates a bug in YOUR32code.3334void require( bool expr ); */35#undef require36#define require( expr ) assert( expr )3738/* Like printf() except output goes to debugging console/file.3940void dprintf( const char format [], ... ); */41static inline void blargg_dprintf_( const char [], ... ) { }42#undef dprintf43#define dprintf (1) ? (void) 0 : blargg_dprintf_4445/* If expr is false, prints file and line number to debug console/log, then46continues execution normally. Meant for flagging potential problems or things47that should be looked into, but that aren't serious problems.4849void check( bool expr ); */50#undef check51#define check( expr ) ((void) 0)5253/* If expr yields non-NULL error string, returns it from current function,54otherwise continues normally. */55#undef RETURN_ERR56#define RETURN_ERR( expr ) \57do {\58blargg_err_t blargg_return_err_ = (expr);\59if ( blargg_return_err_ )\60return blargg_return_err_;\61} while ( 0 )6263/* If ptr is NULL, returns out-of-memory error, otherwise continues normally. */64#undef CHECK_ALLOC65#define CHECK_ALLOC( ptr ) \66do {\67if ( !(ptr) )\68return blargg_err_memory;\69} while ( 0 )7071/* The usual min/max functions for built-in types. */7273template<typename T> T min( T x, T y ) { return x < y ? x : y; }74template<typename T> T max( T x, T y ) { return x > y ? x : y; }7576#define BLARGG_DEF_MIN_MAX( type )7778BLARGG_DEF_MIN_MAX( int )79BLARGG_DEF_MIN_MAX( unsigned )80BLARGG_DEF_MIN_MAX( long )81BLARGG_DEF_MIN_MAX( unsigned long )82BLARGG_DEF_MIN_MAX( float )83BLARGG_DEF_MIN_MAX( double )84#if __WORDSIZE != 6485BLARGG_DEF_MIN_MAX( BOOST::uint64_t )86#endif8788// typedef unsigned char byte;89typedef unsigned char blargg_byte;90#undef byte91#define byte blargg_byte9293#ifndef BLARGG_EXPORT94#if defined (_WIN32) && BLARGG_BUILD_DLL95#define BLARGG_EXPORT __declspec(dllexport)96#elif defined (__GNUC__)97// can always set visibility, even when not building DLL98#define BLARGG_EXPORT __attribute__ ((visibility ("default")))99#else100#define BLARGG_EXPORT101#endif102#endif103104#if BLARGG_LEGACY105#define BLARGG_CHECK_ALLOC CHECK_ALLOC106#define BLARGG_RETURN_ERR RETURN_ERR107#endif108109// Called after failed operation when overall operation may still complete OK.110// Only used by unit testing framework.111#undef ACK_FAILURE112#define ACK_FAILURE() ((void)0)113114/* BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf etc.115and check */116#ifdef BLARGG_SOURCE_BEGIN117#include BLARGG_SOURCE_BEGIN118#endif119120#endif121122123