Path: blob/a-new-beginning/Cherry/Core/include/audio/blargg_source.h
2 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. Since this is only "active"2in my source code, I don't have to worry about polluting the global namespace with3unprefixed names. */45// Gb_Snd_Emu 0.2.06#ifndef BLARGG_SOURCE_H7#define BLARGG_SOURCE_H89// The following four macros are for debugging only. Some or all might be defined10// to do nothing, depending on the circumstances. Described is what happens when11// a particular macro is defined to do something. When defined to do nothing, the12// macros do NOT evaluate their argument(s).1314// If expr is false, prints file and line number, then aborts program. Meant for15// checking internal state and consistency. A failed assertion indicates a bug16// in MY code.17//18// void assert( bool expr );19#include <assert.h>2021// If expr is false, prints file and line number, then aborts program. Meant for22// checking caller-supplied parameters and operations that are outside the control23// of the module. A failed requirement probably indicates a bug in YOUR code.24//25// void require( bool expr );26#undef require27#define require( expr ) assert( expr )2829// Like printf() except output goes to debugging console/file.30//31// void dprintf( const char* format, ... );32static inline void blargg_dprintf_( const char*, ... ) { }33#undef dprintf34#define dprintf (1) ? (void) 0 : blargg_dprintf_3536// If expr is false, prints file and line number to debug console/log, then37// continues execution normally. Meant for flagging potential problems or things38// that should be looked into, but that aren't serious problems.39//40// void check( bool expr );41#undef check42#define check( expr ) ((void) 0)4344// If expr yields non-NULL error string, returns it from current function,45// otherwise continues normally.46#undef RETURN_ERR47#define RETURN_ERR( expr ) do { \48blargg_err_t blargg_return_err_ = (expr); \49if ( blargg_return_err_ ) return blargg_return_err_; \50} while ( 0 )5152// If ptr is NULL, returns "Out of memory" error string, otherwise continues normally.53#undef CHECK_ALLOC54#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )5556// The usual min/max functions for built-in types.57//58// template<typename T> T min( T x, T y ) { return x < y ? x : y; }59// template<typename T> T max( T x, T y ) { return x > y ? x : y; }60#define BLARGG_DEF_MIN_MAX( type ) \61static inline type blargg_min( type x, type y ) { if ( y < x ) x = y; return x; }\62static inline type blargg_max( type x, type y ) { if ( x < y ) x = y; return x; }6364BLARGG_DEF_MIN_MAX( int )65BLARGG_DEF_MIN_MAX( unsigned )66BLARGG_DEF_MIN_MAX( long )67BLARGG_DEF_MIN_MAX( unsigned long )68BLARGG_DEF_MIN_MAX( float )69BLARGG_DEF_MIN_MAX( double )7071#undef min72#define min blargg_min7374#undef max75#define max blargg_max7677// typedef unsigned char byte;78typedef unsigned char blargg_byte;79#undef byte80#define byte blargg_byte8182// deprecated83#define BLARGG_CHECK_ALLOC CHECK_ALLOC84#define BLARGG_RETURN_ERR RETURN_ERR8586// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check87#ifdef BLARGG_SOURCE_BEGIN88#include BLARGG_SOURCE_BEGIN89#endif9091#endif929394