| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,33 +0,0 @@ |
| 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. Since this is only "active" |
|
| 3 |
-in my source code, I don't have to worry about polluting the global namespace with |
|
| 4 |
-unprefixed names. */ |
|
| 5 |
- |
|
| 6 |
-// Gb_Snd_Emu 0.2.0 |
|
| 7 |
-#ifndef BLARGG_SOURCE_H |
|
| 8 |
-#define BLARGG_SOURCE_H |
|
| 9 |
- |
|
| 10 |
-// The following four macros are for debugging only. Some or all might be defined |
|
| 11 |
-// to do nothing, depending on the circumstances. Described is what happens when |
|
| 12 |
-// a particular macro is defined to do something. When defined to do nothing, the |
|
| 13 |
-// macros do NOT evaluate their argument(s). |
|
| 14 |
- |
|
| 15 |
-// If expr is false, prints file and line number, then aborts program. Meant for |
|
| 16 |
-// checking internal state and consistency. A failed assertion indicates a bug |
|
| 17 |
-// in MY code. |
|
| 18 |
-// |
|
| 19 |
-// void assert( bool expr ); |
|
| 20 |
-#include <cassert> |
|
| 21 |
- |
|
| 22 |
-// If expr yields non-NULL error string, returns it from current function, |
|
| 23 |
-// otherwise continues normally. |
|
| 24 |
-#undef RETURN_ERR |
|
| 25 |
-#define RETURN_ERR(expr) \ |
|
| 26 |
-do \ |
|
| 27 |
-{ \
|
|
| 28 |
- blargg_err_t blargg_return_err_ = (expr); \ |
|
| 29 |
- if (blargg_return_err_) \ |
|
| 30 |
- return blargg_return_err_; \ |
|
| 31 |
-} while (0) |
|
| 32 |
- |
|
| 33 |
-#endif |
(As an aside, blargg's code style makes me go blarg myself.)
| ... | ... |
@@ -17,76 +17,17 @@ unprefixed names. */ |
| 17 | 17 |
// in MY code. |
| 18 | 18 |
// |
| 19 | 19 |
// void assert( bool expr ); |
| 20 |
-#include <assert.h> |
|
| 21 |
- |
|
| 22 |
-// If expr is false, prints file and line number, then aborts program. Meant for |
|
| 23 |
-// checking caller-supplied parameters and operations that are outside the control |
|
| 24 |
-// of the module. A failed requirement probably indicates a bug in YOUR code. |
|
| 25 |
-// |
|
| 26 |
-// void require( bool expr ); |
|
| 27 |
-#undef require |
|
| 28 |
-#define require( expr ) assert( expr ) |
|
| 29 |
- |
|
| 30 |
-// Like printf() except output goes to debugging console/file. |
|
| 31 |
-// |
|
| 32 |
-// void dprintf( const char* format, ... ); |
|
| 33 |
-static inline void blargg_dprintf_( const char*, ... ) { }
|
|
| 34 |
-#undef dprintf |
|
| 35 |
-#define dprintf (1) ? (void) 0 : blargg_dprintf_ |
|
| 36 |
- |
|
| 37 |
-// If expr is false, prints file and line number to debug console/log, then |
|
| 38 |
-// continues execution normally. Meant for flagging potential problems or things |
|
| 39 |
-// that should be looked into, but that aren't serious problems. |
|
| 40 |
-// |
|
| 41 |
-// void check( bool expr ); |
|
| 42 |
-#undef check |
|
| 43 |
-#define check( expr ) ((void) 0) |
|
| 20 |
+#include <cassert> |
|
| 44 | 21 |
|
| 45 | 22 |
// If expr yields non-NULL error string, returns it from current function, |
| 46 | 23 |
// otherwise continues normally. |
| 47 |
-#undef RETURN_ERR |
|
| 48 |
-#define RETURN_ERR( expr ) do { \
|
|
| 49 |
- blargg_err_t blargg_return_err_ = (expr); \ |
|
| 50 |
- if ( blargg_return_err_ ) return blargg_return_err_; \ |
|
| 51 |
- } while ( 0 ) |
|
| 52 |
- |
|
| 53 |
-// If ptr is NULL, returns "Out of memory" error string, otherwise continues normally. |
|
| 54 |
-#undef CHECK_ALLOC |
|
| 55 |
-#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
|
|
| 56 |
- |
|
| 57 |
-// The usual min/max functions for built-in types. |
|
| 58 |
-// |
|
| 59 |
-// template<typename T> T min( T x, T y ) { return x < y ? x : y; }
|
|
| 60 |
-// template<typename T> T max( T x, T y ) { return x > y ? x : y; }
|
|
| 61 |
-#define BLARGG_DEF_MIN_MAX( type ) \ |
|
| 62 |
- static inline type blargg_min( type x, type y ) { if ( y < x ) x = y; return x; }\
|
|
| 63 |
- static inline type blargg_max( type x, type y ) { if ( x < y ) x = y; return x; }
|
|
| 64 |
- |
|
| 65 |
-BLARGG_DEF_MIN_MAX( int ) |
|
| 66 |
-BLARGG_DEF_MIN_MAX( unsigned ) |
|
| 67 |
-BLARGG_DEF_MIN_MAX( long ) |
|
| 68 |
-BLARGG_DEF_MIN_MAX( unsigned long ) |
|
| 69 |
-BLARGG_DEF_MIN_MAX( float ) |
|
| 70 |
-BLARGG_DEF_MIN_MAX( double ) |
|
| 71 |
- |
|
| 72 |
-#undef min |
|
| 73 |
-#define min blargg_min |
|
| 74 |
- |
|
| 75 |
-#undef max |
|
| 76 |
-#define max blargg_max |
|
| 77 |
- |
|
| 78 |
-// typedef unsigned char byte; |
|
| 79 |
-typedef unsigned char blargg_byte; |
|
| 80 |
-#undef byte |
|
| 81 |
-#define byte blargg_byte |
|
| 82 |
- |
|
| 83 |
-// deprecated |
|
| 84 |
-#define BLARGG_CHECK_ALLOC CHECK_ALLOC |
|
| 85 |
-#define BLARGG_RETURN_ERR RETURN_ERR |
|
| 86 |
- |
|
| 87 |
-// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check |
|
| 88 |
-#ifdef BLARGG_SOURCE_BEGIN |
|
| 89 |
- #include BLARGG_SOURCE_BEGIN |
|
| 90 |
-#endif |
|
| 24 |
+#undef RETURN_ERR |
|
| 25 |
+#define RETURN_ERR(expr) \ |
|
| 26 |
+do \ |
|
| 27 |
+{ \
|
|
| 28 |
+ blargg_err_t blargg_return_err_ = (expr); \ |
|
| 29 |
+ if (blargg_return_err_) \ |
|
| 30 |
+ return blargg_return_err_; \ |
|
| 31 |
+} while (0) |
|
| 91 | 32 |
|
| 92 | 33 |
#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,92 @@ |
| 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. Since this is only "active" |
|
| 3 |
+in my source code, I don't have to worry about polluting the global namespace with |
|
| 4 |
+unprefixed names. */ |
|
| 5 |
+ |
|
| 6 |
+// Gb_Snd_Emu 0.2.0 |
|
| 7 |
+#ifndef BLARGG_SOURCE_H |
|
| 8 |
+#define BLARGG_SOURCE_H |
|
| 9 |
+ |
|
| 10 |
+// The following four macros are for debugging only. Some or all might be defined |
|
| 11 |
+// to do nothing, depending on the circumstances. Described is what happens when |
|
| 12 |
+// a particular macro is defined to do something. When defined to do nothing, the |
|
| 13 |
+// macros do NOT evaluate their argument(s). |
|
| 14 |
+ |
|
| 15 |
+// If expr is false, prints file and line number, then aborts program. Meant for |
|
| 16 |
+// checking internal state and consistency. A failed assertion indicates a bug |
|
| 17 |
+// in MY code. |
|
| 18 |
+// |
|
| 19 |
+// void assert( bool expr ); |
|
| 20 |
+#include <assert.h> |
|
| 21 |
+ |
|
| 22 |
+// If expr is false, prints file and line number, then aborts program. Meant for |
|
| 23 |
+// checking caller-supplied parameters and operations that are outside the control |
|
| 24 |
+// of the module. A failed requirement probably indicates a bug in YOUR code. |
|
| 25 |
+// |
|
| 26 |
+// void require( bool expr ); |
|
| 27 |
+#undef require |
|
| 28 |
+#define require( expr ) assert( expr ) |
|
| 29 |
+ |
|
| 30 |
+// Like printf() except output goes to debugging console/file. |
|
| 31 |
+// |
|
| 32 |
+// void dprintf( const char* format, ... ); |
|
| 33 |
+static inline void blargg_dprintf_( const char*, ... ) { }
|
|
| 34 |
+#undef dprintf |
|
| 35 |
+#define dprintf (1) ? (void) 0 : blargg_dprintf_ |
|
| 36 |
+ |
|
| 37 |
+// If expr is false, prints file and line number to debug console/log, then |
|
| 38 |
+// continues execution normally. Meant for flagging potential problems or things |
|
| 39 |
+// that should be looked into, but that aren't serious problems. |
|
| 40 |
+// |
|
| 41 |
+// void check( bool expr ); |
|
| 42 |
+#undef check |
|
| 43 |
+#define check( expr ) ((void) 0) |
|
| 44 |
+ |
|
| 45 |
+// If expr yields non-NULL error string, returns it from current function, |
|
| 46 |
+// otherwise continues normally. |
|
| 47 |
+#undef RETURN_ERR |
|
| 48 |
+#define RETURN_ERR( expr ) do { \
|
|
| 49 |
+ blargg_err_t blargg_return_err_ = (expr); \ |
|
| 50 |
+ if ( blargg_return_err_ ) return blargg_return_err_; \ |
|
| 51 |
+ } while ( 0 ) |
|
| 52 |
+ |
|
| 53 |
+// If ptr is NULL, returns "Out of memory" error string, otherwise continues normally. |
|
| 54 |
+#undef CHECK_ALLOC |
|
| 55 |
+#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
|
|
| 56 |
+ |
|
| 57 |
+// The usual min/max functions for built-in types. |
|
| 58 |
+// |
|
| 59 |
+// template<typename T> T min( T x, T y ) { return x < y ? x : y; }
|
|
| 60 |
+// template<typename T> T max( T x, T y ) { return x > y ? x : y; }
|
|
| 61 |
+#define BLARGG_DEF_MIN_MAX( type ) \ |
|
| 62 |
+ static inline type blargg_min( type x, type y ) { if ( y < x ) x = y; return x; }\
|
|
| 63 |
+ static inline type blargg_max( type x, type y ) { if ( x < y ) x = y; return x; }
|
|
| 64 |
+ |
|
| 65 |
+BLARGG_DEF_MIN_MAX( int ) |
|
| 66 |
+BLARGG_DEF_MIN_MAX( unsigned ) |
|
| 67 |
+BLARGG_DEF_MIN_MAX( long ) |
|
| 68 |
+BLARGG_DEF_MIN_MAX( unsigned long ) |
|
| 69 |
+BLARGG_DEF_MIN_MAX( float ) |
|
| 70 |
+BLARGG_DEF_MIN_MAX( double ) |
|
| 71 |
+ |
|
| 72 |
+#undef min |
|
| 73 |
+#define min blargg_min |
|
| 74 |
+ |
|
| 75 |
+#undef max |
|
| 76 |
+#define max blargg_max |
|
| 77 |
+ |
|
| 78 |
+// typedef unsigned char byte; |
|
| 79 |
+typedef unsigned char blargg_byte; |
|
| 80 |
+#undef byte |
|
| 81 |
+#define byte blargg_byte |
|
| 82 |
+ |
|
| 83 |
+// deprecated |
|
| 84 |
+#define BLARGG_CHECK_ALLOC CHECK_ALLOC |
|
| 85 |
+#define BLARGG_RETURN_ERR RETURN_ERR |
|
| 86 |
+ |
|
| 87 |
+// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check |
|
| 88 |
+#ifdef BLARGG_SOURCE_BEGIN |
|
| 89 |
+ #include BLARGG_SOURCE_BEGIN |
|
| 90 |
+#endif |
|
| 91 |
+ |
|
| 92 |
+#endif |