view snes_spc/blargg_source.h @ 5:b6e64e348e47

script will restore lost files now
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Oct 2011 07:12:40 -0700
parents e38dacceb958
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 need
3 module an annoying module prefix on their names since they are defined after
4 all other #include lines. */
6 // snes_spc 0.9.0
7 #ifndef BLARGG_SOURCE_H
8 #define BLARGG_SOURCE_H
10 // If debugging is enabled, abort program if expr is false. Meant for checking
11 // 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 checking
16 // caller-supplied parameters and operations that are outside the control of the
17 // module. A failed requirement indicates a bug outside the module.
18 // void require( bool expr );
19 #undef require
20 #define require( expr ) assert( expr )
22 // Like printf() except output goes to debug log file. Might be defined to do
23 // nothing (not even evaluate its arguments).
24 // void dprintf( const char* format, ... );
25 static inline void blargg_dprintf_( const char*, ... ) { }
26 #undef dprintf
27 #define dprintf (1) ? (void) 0 : blargg_dprintf_
29 // If enabled, evaluate expr and if false, make debug log entry with source file
30 // and line. Meant for finding situations that should be examined further, but that
31 // don't indicate a problem. In all cases, execution continues normally.
32 #undef check
33 #define check( expr ) ((void) 0)
35 // If expr yields error string, return it from current function, otherwise continue.
36 #undef RETURN_ERR
37 #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_ALLOC
44 #define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
46 // Avoid any macros which evaluate their arguments multiple times
47 #undef min
48 #undef max
50 #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_MAX
63 /*
64 // using const references generates crappy code, and I am currenly only using these
65 // for built-in types, so they take arguments by value
67 // TODO: remove
68 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 byte
88 #define byte byte_
89 typedef unsigned char byte;
91 // deprecated
92 #define BLARGG_CHECK_ALLOC CHECK_ALLOC
93 #define BLARGG_RETURN_ERR RETURN_ERR
95 // BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check
96 #ifdef BLARGG_SOURCE_BEGIN
97 #include BLARGG_SOURCE_BEGIN
98 #endif
100 #endif