Path: blob/main/misc/emulator/xnes/snes9x/apu/blargg_source.h
28798 views
/* Included at the beginning of library source files, after all other #include lines.1Sets up helpful macros and services used in my source code. They don't need2module an annoying module prefix on their names since they are defined after3all other #include lines. */45// snes_spc 0.9.06#ifndef BLARGG_SOURCE_H7#define BLARGG_SOURCE_H89// If debugging is enabled, abort program if expr is false. Meant for checking10// internal state and consistency. A failed assertion indicates a bug in the module.11// void assert( bool expr );12#include <assert.h>1314// If debugging is enabled and expr is false, abort program. Meant for checking15// caller-supplied parameters and operations that are outside the control of the16// module. A failed requirement indicates a bug outside the module.17// void require( bool expr );18#undef require19#define require( expr ) assert( expr )2021// Like printf() except output goes to debug log file. Might be defined to do22// nothing (not even evaluate its arguments).23// void dprintf( const char* format, ... );24static inline void blargg_dprintf_( const char*, ... ) { }25#undef dprintf26#define dprintf (1) ? (void) 0 : blargg_dprintf_2728// If enabled, evaluate expr and if false, make debug log entry with source file29// and line. Meant for finding situations that should be examined further, but that30// don't indicate a problem. In all cases, execution continues normally.31#undef check32#define check( expr ) ((void) 0)3334// If expr yields error string, return it from current function, otherwise continue.35#undef RETURN_ERR36#define RETURN_ERR( expr ) do { \37blargg_err_t blargg_return_err_ = (expr); \38if ( blargg_return_err_ ) return blargg_return_err_; \39} while ( 0 )4041// If ptr is 0, return out of memory error string.42#undef CHECK_ALLOC43#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )4445// Avoid any macros which evaluate their arguments multiple times46#undef min47#undef max4849#define DEF_MIN_MAX( type ) \50static inline type min( type x, type y ) { if ( x < y ) return x; return y; }\51static inline type max( type x, type y ) { if ( y < x ) return x; return y; }5253DEF_MIN_MAX( int )54DEF_MIN_MAX( unsigned )55DEF_MIN_MAX( long )56DEF_MIN_MAX( unsigned long )57DEF_MIN_MAX( float )58DEF_MIN_MAX( double )5960#undef DEF_MIN_MAX6162/*63// using const references generates crappy code, and I am currenly only using these64// for built-in types, so they take arguments by value6566// TODO: remove67inline int min( int x, int y )68template<class T>69inline T min( T x, T y )70{71if ( x < y )72return x;73return y;74}7576template<class T>77inline T max( T x, T y )78{79if ( x < y )80return y;81return x;82}83*/8485// TODO: good idea? bad idea?86#undef byte87#define byte byte_88typedef unsigned char byte;8990// deprecated91#define BLARGG_CHECK_ALLOC CHECK_ALLOC92#define BLARGG_RETURN_ERR RETURN_ERR9394// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check95#ifdef BLARGG_SOURCE_BEGIN96#include BLARGG_SOURCE_BEGIN97#endif9899#endif100101102