1 // Included at the beginning of library source files, after all other #include lines
2 #ifndef BLARGG_SOURCE_H
3 #define BLARGG_SOURCE_H
5 // If debugging is enabled and expr is false, abort program. Meant for checking
6 // caller-supplied parameters and operations that are outside the control of the
7 // module. A failed requirement indicates a bug outside the module.
8 // void require( bool expr );
11 #define assert( expr )
13 #define require( expr )
16 #define require( expr ) assert( expr )
19 // Like printf() except output goes to debug log file. Might be defined to do
20 // nothing (not even evaluate its arguments).
21 // void dprintf( const char* format, ... );
23 #define dprintf DEBUGF
25 static inline void blargg_dprintf_( const char* fmt
, ... ) { }
27 #define dprintf (1) ? (void) 0 : blargg_dprintf_
30 // If enabled, evaluate expr and if false, make debug log entry with source file
31 // and line. Meant for finding situations that should be examined further, but that
32 // don't indicate a problem. In all cases, execution continues normally.
34 #define check( expr ) ((void) 0)
36 /* If expr yields non-NULL error string, returns it from current function,
37 otherwise continues normally. */
39 #define RETURN_ERR( expr ) \
41 blargg_err_t blargg_return_err_ = (expr);\
42 if ( blargg_return_err_ )\
43 return blargg_return_err_;\
46 /* If ptr is NULL, returns out-of-memory error, otherwise continues normally. */
48 #define CHECK_ALLOC( ptr ) \
51 return "Out of memory";\
55 #define max(a,b) (((a) > (b)) ? (a) : (b))
59 #define min(a,b) (((a) < (b)) ? (a) : (b))
62 // typedef unsigned char byte;
63 typedef unsigned char blargg_byte
;
65 #define byte blargg_byte
68 #define BLARGG_CHECK_ALLOC CHECK_ALLOC
69 #define BLARGG_RETURN_ERR RETURN_ERR
71 // BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check
72 #ifdef BLARGG_SOURCE_BEGIN
73 #include BLARGG_SOURCE_BEGIN