annotate snes_spc/blargg_source.h @ 8:a37863126396

reordered error messages
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Oct 2011 07:26:53 -0700
parents e38dacceb958
children
rev   line source
rlm@0 1 /* Included at the beginning of library source files, after all other #include lines.
rlm@0 2 Sets up helpful macros and services used in my source code. They don't need
rlm@0 3 module an annoying module prefix on their names since they are defined after
rlm@0 4 all other #include lines. */
rlm@0 5
rlm@0 6 // snes_spc 0.9.0
rlm@0 7 #ifndef BLARGG_SOURCE_H
rlm@0 8 #define BLARGG_SOURCE_H
rlm@0 9
rlm@0 10 // If debugging is enabled, abort program if expr is false. Meant for checking
rlm@0 11 // internal state and consistency. A failed assertion indicates a bug in the module.
rlm@0 12 // void assert( bool expr );
rlm@0 13 #include <assert.h>
rlm@0 14
rlm@0 15 // If debugging is enabled and expr is false, abort program. Meant for checking
rlm@0 16 // caller-supplied parameters and operations that are outside the control of the
rlm@0 17 // module. A failed requirement indicates a bug outside the module.
rlm@0 18 // void require( bool expr );
rlm@0 19 #undef require
rlm@0 20 #define require( expr ) assert( expr )
rlm@0 21
rlm@0 22 // Like printf() except output goes to debug log file. Might be defined to do
rlm@0 23 // nothing (not even evaluate its arguments).
rlm@0 24 // void dprintf( const char* format, ... );
rlm@0 25 static inline void blargg_dprintf_( const char*, ... ) { }
rlm@0 26 #undef dprintf
rlm@0 27 #define dprintf (1) ? (void) 0 : blargg_dprintf_
rlm@0 28
rlm@0 29 // If enabled, evaluate expr and if false, make debug log entry with source file
rlm@0 30 // and line. Meant for finding situations that should be examined further, but that
rlm@0 31 // don't indicate a problem. In all cases, execution continues normally.
rlm@0 32 #undef check
rlm@0 33 #define check( expr ) ((void) 0)
rlm@0 34
rlm@0 35 // If expr yields error string, return it from current function, otherwise continue.
rlm@0 36 #undef RETURN_ERR
rlm@0 37 #define RETURN_ERR( expr ) do { \
rlm@0 38 blargg_err_t blargg_return_err_ = (expr); \
rlm@0 39 if ( blargg_return_err_ ) return blargg_return_err_; \
rlm@0 40 } while ( 0 )
rlm@0 41
rlm@0 42 // If ptr is 0, return out of memory error string.
rlm@0 43 #undef CHECK_ALLOC
rlm@0 44 #define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
rlm@0 45
rlm@0 46 // Avoid any macros which evaluate their arguments multiple times
rlm@0 47 #undef min
rlm@0 48 #undef max
rlm@0 49
rlm@0 50 #define DEF_MIN_MAX( type ) \
rlm@0 51 static inline type min( type x, type y ) { if ( x < y ) return x; return y; }\
rlm@0 52 static inline type max( type x, type y ) { if ( y < x ) return x; return y; }
rlm@0 53
rlm@0 54 DEF_MIN_MAX( int )
rlm@0 55 DEF_MIN_MAX( unsigned )
rlm@0 56 DEF_MIN_MAX( long )
rlm@0 57 DEF_MIN_MAX( unsigned long )
rlm@0 58 DEF_MIN_MAX( float )
rlm@0 59 DEF_MIN_MAX( double )
rlm@0 60
rlm@0 61 #undef DEF_MIN_MAX
rlm@0 62
rlm@0 63 /*
rlm@0 64 // using const references generates crappy code, and I am currenly only using these
rlm@0 65 // for built-in types, so they take arguments by value
rlm@0 66
rlm@0 67 // TODO: remove
rlm@0 68 inline int min( int x, int y )
rlm@0 69 template<class T>
rlm@0 70 inline T min( T x, T y )
rlm@0 71 {
rlm@0 72 if ( x < y )
rlm@0 73 return x;
rlm@0 74 return y;
rlm@0 75 }
rlm@0 76
rlm@0 77 template<class T>
rlm@0 78 inline T max( T x, T y )
rlm@0 79 {
rlm@0 80 if ( x < y )
rlm@0 81 return y;
rlm@0 82 return x;
rlm@0 83 }
rlm@0 84 */
rlm@0 85
rlm@0 86 // TODO: good idea? bad idea?
rlm@0 87 #undef byte
rlm@0 88 #define byte byte_
rlm@0 89 typedef unsigned char byte;
rlm@0 90
rlm@0 91 // deprecated
rlm@0 92 #define BLARGG_CHECK_ALLOC CHECK_ALLOC
rlm@0 93 #define BLARGG_RETURN_ERR RETURN_ERR
rlm@0 94
rlm@0 95 // BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check
rlm@0 96 #ifdef BLARGG_SOURCE_BEGIN
rlm@0 97 #include BLARGG_SOURCE_BEGIN
rlm@0 98 #endif
rlm@0 99
rlm@0 100 #endif