Mercurial > spc_convert
view snes_spc/blargg_source.h @ 0:e38dacceb958
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 05:53:11 -0700 |
parents | |
children |
line wrap: on
line source
1 /* Included at the beginning of library source files, after all other #include lines.2 Sets up helpful macros and services used in my source code. They don't need3 module an annoying module prefix on their names since they are defined after4 all other #include lines. */6 // snes_spc 0.9.07 #ifndef BLARGG_SOURCE_H8 #define BLARGG_SOURCE_H10 // If debugging is enabled, abort program if expr is false. Meant for checking11 // internal state and consistency. A failed assertion indicates a bug in the module.12 // void assert( bool expr );13 #include <assert.h>15 // If debugging is enabled and expr is false, abort program. Meant for checking16 // caller-supplied parameters and operations that are outside the control of the17 // module. A failed requirement indicates a bug outside the module.18 // void require( bool expr );19 #undef require20 #define require( expr ) assert( expr )22 // Like printf() except output goes to debug log file. Might be defined to do23 // nothing (not even evaluate its arguments).24 // void dprintf( const char* format, ... );25 static inline void blargg_dprintf_( const char*, ... ) { }26 #undef dprintf27 #define dprintf (1) ? (void) 0 : blargg_dprintf_29 // If enabled, evaluate expr and if false, make debug log entry with source file30 // and line. Meant for finding situations that should be examined further, but that31 // don't indicate a problem. In all cases, execution continues normally.32 #undef check33 #define check( expr ) ((void) 0)35 // If expr yields error string, return it from current function, otherwise continue.36 #undef RETURN_ERR37 #define RETURN_ERR( expr ) do { \38 blargg_err_t blargg_return_err_ = (expr); \39 if ( blargg_return_err_ ) return blargg_return_err_; \40 } while ( 0 )42 // If ptr is 0, return out of memory error string.43 #undef CHECK_ALLOC44 #define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )46 // Avoid any macros which evaluate their arguments multiple times47 #undef min48 #undef max50 #define DEF_MIN_MAX( type ) \51 static inline type min( type x, type y ) { if ( x < y ) return x; return y; }\52 static inline type max( type x, type y ) { if ( y < x ) return x; return y; }54 DEF_MIN_MAX( int )55 DEF_MIN_MAX( unsigned )56 DEF_MIN_MAX( long )57 DEF_MIN_MAX( unsigned long )58 DEF_MIN_MAX( float )59 DEF_MIN_MAX( double )61 #undef DEF_MIN_MAX63 /*64 // using const references generates crappy code, and I am currenly only using these65 // for built-in types, so they take arguments by value67 // TODO: remove68 inline int min( int x, int y )69 template<class T>70 inline T min( T x, T y )71 {72 if ( x < y )73 return x;74 return y;75 }77 template<class T>78 inline T max( T x, T y )79 {80 if ( x < y )81 return y;82 return x;83 }84 */86 // TODO: good idea? bad idea?87 #undef byte88 #define byte byte_89 typedef unsigned char byte;91 // deprecated92 #define BLARGG_CHECK_ALLOC CHECK_ALLOC93 #define BLARGG_RETURN_ERR RETURN_ERR95 // BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check96 #ifdef BLARGG_SOURCE_BEGIN97 #include BLARGG_SOURCE_BEGIN98 #endif100 #endif