Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/fex/blargg_source.h
2 views
1
/* Included at the beginning of library source files, AFTER all other #include
2
lines. Sets up helpful macros and services used in my source code. Since this
3
is only "active" in my source code, I don't have to worry about polluting the
4
global namespace with unprefixed names. */
5
6
// File_Extractor 1.0.0
7
#ifndef BLARGG_SOURCE_H
8
#define BLARGG_SOURCE_H
9
10
#ifndef BLARGG_COMMON_H // optimization only
11
#include "blargg_common.h"
12
#endif
13
#include "blargg_errors.h"
14
15
#include <string.h> /* memcpy(), memset(), memmove() */
16
#include <stddef.h> /* offsetof() */
17
18
/* The following four macros are for debugging only. Some or all might be
19
defined to do nothing, depending on the circumstances. Described is what
20
happens when a particular macro is defined to do something. When defined to
21
do nothing, the macros do NOT evaluate their argument(s). */
22
23
/* If expr is false, prints file and line number, then aborts program. Meant
24
for checking internal state and consistency. A failed assertion indicates a bug
25
in MY code.
26
27
void assert( bool expr ); */
28
#include <assert.h>
29
30
/* If expr is false, prints file and line number, then aborts program. Meant
31
for checking caller-supplied parameters and operations that are outside the
32
control of the module. A failed requirement probably indicates a bug in YOUR
33
code.
34
35
void require( bool expr ); */
36
#undef require
37
#define require( expr ) assert( expr )
38
39
/* Like printf() except output goes to debugging console/file.
40
41
void dprintf( const char format [], ... ); */
42
static inline void blargg_dprintf_( const char [], ... ) { }
43
#undef dprintf
44
#define dprintf (1) ? (void) 0 : blargg_dprintf_
45
46
/* If expr is false, prints file and line number to debug console/log, then
47
continues execution normally. Meant for flagging potential problems or things
48
that should be looked into, but that aren't serious problems.
49
50
void check( bool expr ); */
51
#undef check
52
#define check( expr ) ((void) 0)
53
54
/* If expr yields non-NULL error string, returns it from current function,
55
otherwise continues normally. */
56
#undef RETURN_ERR
57
#define RETURN_ERR( expr ) \
58
do {\
59
blargg_err_t blargg_return_err_ = (expr);\
60
if ( blargg_return_err_ )\
61
return blargg_return_err_;\
62
} while ( 0 )
63
64
/* If ptr is NULL, returns out-of-memory error, otherwise continues normally. */
65
#undef CHECK_ALLOC
66
#define CHECK_ALLOC( ptr ) \
67
do {\
68
if ( !(ptr) )\
69
return blargg_err_memory;\
70
} while ( 0 )
71
72
/* The usual min/max functions for built-in types. */
73
74
template<typename T> T min( T x, T y ) { return x < y ? x : y; }
75
template<typename T> T max( T x, T y ) { return x > y ? x : y; }
76
77
#define BLARGG_DEF_MIN_MAX( type )
78
79
BLARGG_DEF_MIN_MAX( int )
80
BLARGG_DEF_MIN_MAX( unsigned )
81
BLARGG_DEF_MIN_MAX( long )
82
BLARGG_DEF_MIN_MAX( unsigned long )
83
BLARGG_DEF_MIN_MAX( float )
84
BLARGG_DEF_MIN_MAX( double )
85
#if __WORDSIZE != 64
86
BLARGG_DEF_MIN_MAX( BOOST::uint64_t )
87
#endif
88
89
// typedef unsigned char byte;
90
typedef unsigned char blargg_byte;
91
#undef byte
92
#define byte blargg_byte
93
94
#ifndef BLARGG_EXPORT
95
#if defined (_WIN32) && BLARGG_BUILD_DLL
96
#define BLARGG_EXPORT __declspec(dllexport)
97
#elif defined (__GNUC__)
98
// can always set visibility, even when not building DLL
99
#define BLARGG_EXPORT __attribute__ ((visibility ("default")))
100
#else
101
#define BLARGG_EXPORT
102
#endif
103
#endif
104
105
#if BLARGG_LEGACY
106
#define BLARGG_CHECK_ALLOC CHECK_ALLOC
107
#define BLARGG_RETURN_ERR RETURN_ERR
108
#endif
109
110
// Called after failed operation when overall operation may still complete OK.
111
// Only used by unit testing framework.
112
#undef ACK_FAILURE
113
#define ACK_FAILURE() ((void)0)
114
115
/* BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf etc.
116
and check */
117
#ifdef BLARGG_SOURCE_BEGIN
118
#include BLARGG_SOURCE_BEGIN
119
#endif
120
121
#endif
122
123