Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/apu/blargg_source.h
28798 views
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. */
5
6
// snes_spc 0.9.0
7
#ifndef BLARGG_SOURCE_H
8
#define BLARGG_SOURCE_H
9
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>
14
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 )
21
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_
28
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)
34
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 )
41
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 )
45
46
// Avoid any macros which evaluate their arguments multiple times
47
#undef min
48
#undef max
49
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; }
53
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 )
60
61
#undef DEF_MIN_MAX
62
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
66
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
}
76
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
*/
85
86
// TODO: good idea? bad idea?
87
#undef byte
88
#define byte byte_
89
typedef unsigned char byte;
90
91
// deprecated
92
#define BLARGG_CHECK_ALLOC CHECK_ALLOC
93
#define BLARGG_RETURN_ERR RETURN_ERR
94
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
99
100
#endif
101
102