summaryrefslogtreecommitdiffstats
path: root/apps/codecs/libgme/blargg_common.h
blob: 74cc227eed25cc1bffebb0ad884be401a8ac3b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Sets up common environment for Shay Green's libraries.
// To change configuration options, modify blargg_config.h, not this file.

#ifndef BLARGG_COMMON_H
#define BLARGG_COMMON_H

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#undef BLARGG_COMMON_H
// allow blargg_config.h to #include blargg_common.h
#include "blargg_config.h"
#include "blargg_source.h"
#ifndef BLARGG_COMMON_H
#define BLARGG_COMMON_H

#if defined(ROCKBOX)
#include "codeclib.h"
#endif

// common defines
#define FP_ONE_CLOCK  (1LL << 12)
#define FP_ONE_TEMPO  (1LL << 24)
#define FP_ONE_GAIN   (1LL << 24)
#define FP_ONE_VOLUME FP_ONE_GAIN

// IRAM configuration
#if   (CONFIG_CPU == MCF5250)
#define EMU2413_CALC_ICODE

#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
#define EMU2413_CALC_ICODE  ICODE_ATTR

#elif defined(CPU_S5L870X)
#define EMU2413_CALC_ICODE

#else
#define EMU2413_CALC_ICODE

#endif

// BLARGG_RESTRICT: equivalent to C99's restrict, where supported
#if __GNUC__ >= 3 || _MSC_VER >= 1100
	#define BLARGG_RESTRICT __restrict
#else
	#define BLARGG_RESTRICT
#endif

// STATIC_CAST(T,expr): Used in place of static_cast<T> (expr)
#ifndef STATIC_CAST
	#define STATIC_CAST(T,expr) ((T) (expr))
#endif

// blargg_err_t (0 on success, otherwise error string)
#ifndef blargg_err_t
	typedef const char* blargg_err_t;
#endif

#define BLARGG_4CHAR( a, b, c, d ) \
	((a&0xFF)*0x1000000L + (b&0xFF)*0x10000L + (c&0xFF)*0x100L + (d&0xFF))

// BOOST_STATIC_ASSERT( expr ): Generates compile error if expr is 0.
#ifndef BOOST_STATIC_ASSERT
	#ifdef _MSC_VER
		// MSVC6 (_MSC_VER < 1300) fails for use of __LINE__ when /Zl is specified
		#define BOOST_STATIC_ASSERT( expr ) \
			void blargg_failed_( int (*arg) [2 / (int) !!(expr) - 1] )
	#else
		// Some other compilers fail when declaring same function multiple times in class,
		// so differentiate them by line
		#define BOOST_STATIC_ASSERT( expr ) \
			void blargg_failed_( int (*arg) [2 / !!(expr) - 1] [__LINE__] )
	#endif
#endif

// BLARGG_COMPILER_HAS_BOOL: If 0, provides bool support for old compiler. If 1,
// compiler is assumed to support bool. If undefined, availability is determined.
#ifndef BLARGG_COMPILER_HAS_BOOL
	#if defined (__MWERKS__)
		#if !__option(bool)
			#define BLARGG_COMPILER_HAS_BOOL 0
		#endif
	#elif defined (_MSC_VER)
		#if _MSC_VER < 1100
			#define BLARGG_COMPILER_HAS_BOOL 0
		#endif
	#elif defined (__GNUC__)
		// supports bool
	#elif __cplusplus < 199711
		#define BLARGG_COMPILER_HAS_BOOL 0
	#endif
#endif
#if defined (BLARGG_COMPILER_HAS_BOOL) && !BLARGG_COMPILER_HAS_BOOL
	// If you get errors here, modify your blargg_config.h file
	typedef int bool;
	static bool true  = 1;
	static bool false = 0;
#endif

/* My code depends on int being at least 32 bits. Almost everything these days
uses at least 32-bit ints, so it's hard to even find a system with 16-bit ints
to test with. The issue can't be gotten around by using a suitable blargg_int
everywhere either, because int is often converted to implicitly when doing
arithmetic on smaller types. */
#if UINT_MAX < 0xFFFFFFFF
    #error "int must be at least 32 bits"
#endif

// int8_t etc.


// ROCKBOX: If defined, use <codeclib.h> for int_8_t etc
#if defined (ROCKBOX)
	#include <codecs/lib/codeclib.h>
// HAVE_STDINT_H: If defined, use <stdint.h> for int8_t etc.
#elif defined (HAVE_STDINT_H)
	#include <stdint.h>
	#define BOOST

// HAVE_INTTYPES_H: If defined, use <stdint.h> for int8_t etc.
#elif defined (HAVE_INTTYPES_H)
	#include <inttypes.h>
	#define BOOST

#else
	#if UCHAR_MAX == 0xFF && SCHAR_MAX == 0x7F
		typedef signed char     int8_t;
		typedef unsigned char   uint8_t;
	#else
		// No suitable 8-bit type available
		typedef struct see_blargg_common_h int8_t;
		typedef struct see_blargg_common_h uint8_t;
	#endif
		
	#if USHRT_MAX == 0xFFFF
		typedef short           int16_t;
		typedef unsigned short  uint16_t;
	#else
		// No suitable 16-bit type available
		typedef struct see_blargg_common_h int16_t;
		typedef struct see_blargg_common_h uint16_t;
	#endif
		
	#if ULONG_MAX == 0xFFFFFFFF
		typedef long            int32_t;
		typedef unsigned long   uint32_t;
	#elif UINT_MAX == 0xFFFFFFFF
		typedef int             int32_t;
		typedef unsigned int    uint32_t;
	#else
		// No suitable 32-bit type available
		typedef struct see_blargg_common_h int32_t;
		typedef struct see_blargg_common_h uint32_t;
	#endif
#endif

#endif
#endif