Mercurial > audlegacy
annotate Plugins/Input/console/blargg_source.h @ 1188:35dc5d2a1675 trunk
[svn] - another API change [sorry!]
author | nenolod |
---|---|
date | Sun, 11 Jun 2006 23:51:02 -0700 |
parents | c04dff121e1d |
children |
rev | line source |
---|---|
493
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
1 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
2 // By default, #included at beginning of library source files. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
3 // Can be overridden by #defining BLARGG_SOURCE_BEGIN to path of alternate file. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
4 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
5 // Copyright (C) 2005 Shay Green. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
6 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
7 #ifndef BLARGG_SOURCE_H |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
8 #define BLARGG_SOURCE_H |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
9 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
10 // If debugging is enabled, abort program if expr is false. Meant for checking |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
11 // internal state and consistency. A failed assertion indicates a bug in the module. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
12 // void assert( bool expr ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
13 #include <assert.h> |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
14 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
15 // If debugging is enabled and expr is false, abort program. Meant for checking |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
16 // caller-supplied parameters and operations that are outside the control of the |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
17 // module. A failed requirement indicates a bug outside the module. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
18 // void require( bool expr ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
19 #undef require |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
20 #define require( expr ) assert( expr ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
21 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
22 // Like printf() except output goes to debug log file. Might be defined to do |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
23 // nothing (not even evaluate its arguments). |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
24 // void dprintf( const char* format, ... ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
25 #undef dprintf |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
26 #ifdef BLARGG_DPRINTF |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
27 #define dprintf BLARGG_DPRINTF |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
28 #else |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
29 inline void blargg_dprintf_( const char*, ... ) { } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
30 #define dprintf (1) ? (void) 0 : blargg_dprintf_ |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
31 #endif |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
32 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
33 // If enabled, evaluate expr and if false, make debug log entry with source file |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
34 // and line. Meant for finding situations that should be examined further, but that |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
35 // don't indicate a problem. In all cases, execution continues normally. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
36 #undef check |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
37 #ifdef BLARGG_CHECK |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
38 #define check( expr ) BLARGG_CHECK( expr ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
39 #else |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
40 #define check( expr ) ((void) 0) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
41 #endif |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
42 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
43 // If expr returns non-NULL error string, return it from current function, otherwise continue. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
44 #define BLARGG_RETURN_ERR( expr ) do { \ |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
45 blargg_err_t blargg_return_err_ = (expr); \ |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
46 if ( blargg_return_err_ ) return blargg_return_err_; \ |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
47 } while ( 0 ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
48 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
49 // If ptr is NULL, return out of memory error string. |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
50 #define BLARGG_CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
51 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
52 // Avoid any macros which evaluate their arguments multiple times |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
53 #undef min |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
54 #undef max |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
55 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
56 // using const references generates crappy code, and I am currenly only using these |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
57 // for built-in types, so they take arguments by value |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
58 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
59 template<class T> |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
60 inline T min( T x, T y ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
61 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
62 if ( x < y ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
63 return x; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
64 return y; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
65 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
66 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
67 template<class T> |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
68 inline T max( T x, T y ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
69 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
70 if ( x < y ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
71 return y; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
72 return x; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
73 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
74 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
75 #endif |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
76 |