Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -49,7 +49,7 @@ public:
49 49
 class Gb_Env : public Gb_Osc
50 50
 {
51 51
 public:
52
-	Gb_Env() : env_enabled(false), env_delay(0) { }
52
+	Gb_Env() : env_delay(0), env_enabled(false) { }
53 53
 	int env_delay;
54 54
 	int volume;
55 55
 	bool env_enabled;
Browse code

[GSF] Copied a few things from kode54's viogsf.

Naram Qashat authored on 2014/09/15 14:27:18
Showing 1 changed files
... ...
@@ -37,7 +37,7 @@ public:
37 37
 	const Good_Synth *good_synth;
38 38
 	const Med_Synth *med_synth;
39 39
 
40
-	int delay; // clocks until frequency timer expires
40
+	int32_t delay; // clocks until frequency timer expires
41 41
 	int length_ctr; // length counter
42 42
 	unsigned phase; // waveform phase (or equivalent)
43 43
 	bool enabled; // internal enabled flag
Browse code

Updating the VBA-M code to revision 1231.

Naram Qashat authored on 2014/09/08 12:20:28
Showing 1 changed files
... ...
@@ -1,8 +1,7 @@
1 1
 // Private oscillators used by Gb_Apu
2 2
 
3 3
 // Gb_Snd_Emu 0.2.0
4
-#ifndef GB_OSCS_H
5
-#define GB_OSCS_H
4
+#pragma once
6 5
 
7 6
 #include "blargg_common.h"
8 7
 #include "Blip_Buffer.h"
... ...
@@ -170,7 +169,7 @@ private:
170 169
 
171 170
 	void corrupt_wave();
172 171
 
173
-	uint8_t *wave_bank() const { return &this->wave_ram[((~this->regs[0] & bank40_mask) >> 2) & agb_mask]; }
172
+	uint8_t *wave_bank() const { return &this->wave_ram[(~this->regs[0] & bank40_mask) >> 2 & this->agb_mask]; }
174 173
 
175 174
 	// Wave index that would be accessed, or -1 if no access would occur
176 175
 	int access(unsigned addr) const;
... ...
@@ -188,5 +187,3 @@ inline void Gb_Wave::write(unsigned addr, int data)
188 187
 	if (index >= 0)
189 188
 		this->wave_bank()[index] = data;
190 189
 }
191
-
192
-#endif
Browse code

[GSF] Some more code cleanup, also removed a few files that were unneeded.

Naram Qashat authored on 2013/05/16 01:25:34
Showing 1 changed files
... ...
@@ -186,7 +186,7 @@ inline void Gb_Wave::write(unsigned addr, int data)
186 186
 {
187 187
 	int index = this->access(addr);
188 188
 	if (index >= 0)
189
-		this->wave_bank()[index] = data;;
189
+		this->wave_bank()[index] = data;
190 190
 }
191 191
 
192 192
 #endif
Browse code

[GSF] Massive code cleanup.

(As an aside, blargg's code style makes me go blarg myself.)

Naram Qashat authored on 2013/05/14 01:07:18
Showing 1 changed files
... ...
@@ -8,184 +8,185 @@
8 8
 #include "Blip_Buffer.h"
9 9
 
10 10
 #ifndef GB_APU_OVERCLOCK
11
-	#define GB_APU_OVERCLOCK 1
11
+# define GB_APU_OVERCLOCK 1
12 12
 #endif
13 13
 
14 14
 #if GB_APU_OVERCLOCK & (GB_APU_OVERCLOCK - 1)
15
-	#error "GB_APU_OVERCLOCK must be a power of 2"
15
+# error "GB_APU_OVERCLOCK must be a power of 2"
16 16
 #endif
17 17
 
18
-class Gb_Osc {
18
+class Gb_Osc
19
+{
19 20
 protected:
20
-
21 21
 	// 11-bit frequency in NRx3 and NRx4
22
-	int frequency() const { return (regs [4] & 7) * 0x100 + regs [3]; }
22
+	int frequency() const { return (this->regs[4] & 7) * 0x100 + this->regs[3]; }
23 23
 
24
-	void update_amp( blip_time_t, int new_amp );
25
-	int write_trig( int frame_phase, int max_len, int old_data );
24
+	void update_amp(blip_time_t, int new_amp);
25
+	int write_trig(int frame_phase, int max_len, int old_data);
26 26
 public:
27
-
28
-	enum { clk_mul  = GB_APU_OVERCLOCK };
27
+	enum { clk_mul = GB_APU_OVERCLOCK };
29 28
 	enum { dac_bias = 7 };
30 29
 
31
-	Blip_Buffer*    outputs [4];// NULL, right, left, center
32
-	Blip_Buffer*    output;     // where to output sound
33
-	BOOST::uint8_t* regs;       // osc's 5 registers
34
-	int             mode;       // mode_dmg, mode_cgb, mode_agb
35
-	int             dac_off_amp;// amplitude when DAC is off
36
-	int             last_amp;   // current amplitude in Blip_Buffer
37
-	typedef Blip_Synth<blip_good_quality,1> Good_Synth;
38
-	typedef Blip_Synth<blip_med_quality ,1> Med_Synth;
39
-	Good_Synth const* good_synth;
40
-	Med_Synth  const* med_synth;
41
-
42
-	int         delay;      // clocks until frequency timer expires
43
-	int         length_ctr; // length counter
44
-	unsigned    phase;      // waveform phase (or equivalent)
45
-	bool        enabled;    // internal enabled flag
30
+	Blip_Buffer *outputs[4];// NULL, right, left, center
31
+	Blip_Buffer *output; // where to output sound
32
+	uint8_t *regs; // osc's 5 registers
33
+	int mode; // mode_dmg, mode_cgb, mode_agb
34
+	int dac_off_amp; // amplitude when DAC is off
35
+	int last_amp; // current amplitude in Blip_Buffer
36
+	typedef Blip_Synth<blip_good_quality, 1> Good_Synth;
37
+	typedef Blip_Synth<blip_med_quality, 1> Med_Synth;
38
+	const Good_Synth *good_synth;
39
+	const Med_Synth *med_synth;
40
+
41
+	int delay; // clocks until frequency timer expires
42
+	int length_ctr; // length counter
43
+	unsigned phase; // waveform phase (or equivalent)
44
+	bool enabled; // internal enabled flag
46 45
 
47 46
 	void clock_length();
48 47
 	void reset();
49 48
 };
50 49
 
51
-class Gb_Env : public Gb_Osc {
50
+class Gb_Env : public Gb_Osc
51
+{
52 52
 public:
53
-	Gb_Env() : env_enabled(false), env_delay(0) {}
54
-	int  env_delay;
55
-	int  volume;
53
+	Gb_Env() : env_enabled(false), env_delay(0) { }
54
+	int env_delay;
55
+	int volume;
56 56
 	bool env_enabled;
57 57
 
58 58
 	void clock_envelope();
59
-	bool write_register( int frame_phase, int reg, int old_data, int data );
59
+	bool write_register(int frame_phase, int reg, int old_data, int data);
60 60
 
61 61
 	void reset()
62 62
 	{
63
-		env_delay = 0;
64
-		volume    = 0;
63
+		this->env_delay = 0;
64
+		this->volume = 0;
65 65
 		Gb_Osc::reset();
66 66
 	}
67 67
 protected:
68 68
 	// Non-zero if DAC is enabled
69
-	int dac_enabled() const { return regs [2] & 0xF8; }
69
+	int dac_enabled() const { return this->regs[2] & 0xF8; }
70 70
 private:
71
-	void zombie_volume( int old, int data );
71
+	void zombie_volume(int old, int data);
72 72
 	int reload_env_timer();
73 73
 };
74 74
 
75
-class Gb_Square : public Gb_Env {
75
+class Gb_Square : public Gb_Env
76
+{
76 77
 public:
77
-	bool write_register( int frame_phase, int reg, int old_data, int data );
78
-	void run( blip_time_t, blip_time_t );
78
+	bool write_register(int frame_phase, int reg, int old_data, int data);
79
+	void run(blip_time_t, blip_time_t);
79 80
 
80 81
 	void reset()
81 82
 	{
82 83
 		Gb_Env::reset();
83
-		delay = 0x40000000; // TODO: something less hacky (never clocked until first trigger)
84
+		this->delay = 0x40000000; // TODO: something less hacky (never clocked until first trigger)
84 85
 	}
85 86
 private:
86 87
 	// Frequency timer period
87
-	int period() const { return (2048 - frequency()) * (4 * clk_mul); }
88
+	int period() const { return (2048 - this->frequency()) * (4 * clk_mul); }
88 89
 };
89 90
 
90
-class Gb_Sweep_Square : public Gb_Square {
91
+class Gb_Sweep_Square : public Gb_Square
92
+{
91 93
 public:
92
-	int  sweep_freq;
93
-	int  sweep_delay;
94
+	int sweep_freq;
95
+	int sweep_delay;
94 96
 	bool sweep_enabled;
95 97
 	bool sweep_neg;
96 98
 
97 99
 	void clock_sweep();
98
-	void write_register( int frame_phase, int reg, int old_data, int data );
100
+	void write_register(int frame_phase, int reg, int old_data, int data);
99 101
 
100 102
 	void reset()
101 103
 	{
102
-		sweep_freq    = 0;
103
-		sweep_delay   = 0;
104
-		sweep_enabled = false;
105
-		sweep_neg     = false;
104
+		this->sweep_freq = this->sweep_delay = 0;
105
+		this->sweep_enabled = this->sweep_neg = false;
106 106
 		Gb_Square::reset();
107 107
 	}
108 108
 private:
109 109
 	enum { period_mask = 0x70 };
110 110
 	enum { shift_mask  = 0x07 };
111 111
 
112
-	void calc_sweep( bool update );
112
+	void calc_sweep(bool update);
113 113
 	void reload_sweep_timer();
114 114
 };
115 115
 
116
-class Gb_Noise : public Gb_Env {
116
+class Gb_Noise : public Gb_Env
117
+{
117 118
 public:
118
-
119 119
 	int divider; // noise has more complex frequency divider setup
120 120
 
121
-	void run( blip_time_t, blip_time_t );
122
-	void write_register( int frame_phase, int reg, int old_data, int data );
121
+	void run(blip_time_t, blip_time_t);
122
+	void write_register(int frame_phase, int reg, int old_data, int data);
123 123
 
124 124
 	void reset()
125 125
 	{
126
-		divider = 0;
126
+		this->divider = 0;
127 127
 		Gb_Env::reset();
128
-		delay = 4 * clk_mul; // TODO: remove?
128
+		this->delay = 4 * clk_mul; // TODO: remove?
129 129
 	}
130 130
 private:
131 131
 	enum { period2_mask = 0x1FFFF };
132 132
 
133
-	int period2_index() const { return regs [3] >> 4; }
134
-	int period2( int base = 8 ) const { return base << period2_index(); }
135
-	unsigned lfsr_mask() const { return (regs [3] & 0x08) ? ~0x4040 : ~0x4000; }
133
+	int period2_index() const { return this->regs[3] >> 4; }
134
+	int period2(int base = 8) const { return base << this->period2_index(); }
135
+	unsigned lfsr_mask() const { return (this->regs[3] & 0x08) ? ~0x4040 : ~0x4000; }
136 136
 };
137 137
 
138
-class Gb_Wave : public Gb_Osc {
138
+class Gb_Wave : public Gb_Osc
139
+{
139 140
 public:
140 141
 	int sample_buf; // last wave RAM byte read (hardware has this as well)
141 142
 
142
-	void write_register( int frame_phase, int reg, int old_data, int data );
143
-	void run( blip_time_t, blip_time_t );
143
+	void write_register(int frame_phase, int reg, int old_data, int data);
144
+	void run(blip_time_t, blip_time_t);
144 145
 
145 146
 	// Reads/writes wave RAM
146
-	int read( unsigned addr ) const;
147
-	void write( unsigned addr, int data );
147
+	int read(unsigned addr) const;
148
+	void write(unsigned addr, int data);
148 149
 
149 150
 	void reset()
150 151
 	{
151
-		sample_buf = 0;
152
+		this->sample_buf = 0;
152 153
 		Gb_Osc::reset();
153 154
 	}
154 155
 
155 156
 private:
156 157
 	enum { bank40_mask = 0x40 };
157
-	enum { bank_size   = 32 };
158
+	enum { bank_size = 32 };
158 159
 
159
-	int agb_mask;               // 0xFF if AGB features enabled, 0 otherwise
160
-	BOOST::uint8_t* wave_ram;   // 32 bytes (64 nybbles), stored in APU
160
+	int agb_mask; // 0xFF if AGB features enabled, 0 otherwise
161
+	uint8_t *wave_ram; // 32 bytes (64 nybbles), stored in APU
161 162
 
162 163
 	friend class Gb_Apu;
163 164
 
164 165
 	// Frequency timer period
165
-	int period() const { return (2048 - frequency()) * (2 * clk_mul); }
166
+	int period() const { return (2048 - this->frequency()) * (2 * clk_mul); }
166 167
 
167 168
 	// Non-zero if DAC is enabled
168
-	int dac_enabled() const { return regs [0] & 0x80; }
169
+	int dac_enabled() const { return this->regs[0] & 0x80; }
169 170
 
170 171
 	void corrupt_wave();
171 172
 
172
-	BOOST::uint8_t* wave_bank() const { return &wave_ram [(~regs [0] & bank40_mask) >> 2 & agb_mask]; }
173
+	uint8_t *wave_bank() const { return &this->wave_ram[((~this->regs[0] & bank40_mask) >> 2) & agb_mask]; }
173 174
 
174 175
 	// Wave index that would be accessed, or -1 if no access would occur
175
-	int access( unsigned addr ) const;
176
+	int access(unsigned addr) const;
176 177
 };
177 178
 
178
-inline int Gb_Wave::read( unsigned addr ) const
179
+inline int Gb_Wave::read(unsigned addr) const
179 180
 {
180
-	int index = access( addr );
181
-	return (index < 0 ? 0xFF : wave_bank() [index]);
181
+	int index = this->access(addr);
182
+	return index < 0 ? 0xFF : this->wave_bank()[index];
182 183
 }
183 184
 
184
-inline void Gb_Wave::write( unsigned addr, int data )
185
+inline void Gb_Wave::write(unsigned addr, int data)
185 186
 {
186
-	int index = access( addr );
187
-	if ( index >= 0 )
188
-		wave_bank() [index] = data;;
187
+	int index = this->access(addr);
188
+	if (index >= 0)
189
+		this->wave_bank()[index] = data;;
189 190
 }
190 191
 
191 192
 #endif
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,191 @@
1
+// Private oscillators used by Gb_Apu
2
+
3
+// Gb_Snd_Emu 0.2.0
4
+#ifndef GB_OSCS_H
5
+#define GB_OSCS_H
6
+
7
+#include "blargg_common.h"
8
+#include "Blip_Buffer.h"
9
+
10
+#ifndef GB_APU_OVERCLOCK
11
+	#define GB_APU_OVERCLOCK 1
12
+#endif
13
+
14
+#if GB_APU_OVERCLOCK & (GB_APU_OVERCLOCK - 1)
15
+	#error "GB_APU_OVERCLOCK must be a power of 2"
16
+#endif
17
+
18
+class Gb_Osc {
19
+protected:
20
+
21
+	// 11-bit frequency in NRx3 and NRx4
22
+	int frequency() const { return (regs [4] & 7) * 0x100 + regs [3]; }
23
+
24
+	void update_amp( blip_time_t, int new_amp );
25
+	int write_trig( int frame_phase, int max_len, int old_data );
26
+public:
27
+
28
+	enum { clk_mul  = GB_APU_OVERCLOCK };
29
+	enum { dac_bias = 7 };
30
+
31
+	Blip_Buffer*    outputs [4];// NULL, right, left, center
32
+	Blip_Buffer*    output;     // where to output sound
33
+	BOOST::uint8_t* regs;       // osc's 5 registers
34
+	int             mode;       // mode_dmg, mode_cgb, mode_agb
35
+	int             dac_off_amp;// amplitude when DAC is off
36
+	int             last_amp;   // current amplitude in Blip_Buffer
37
+	typedef Blip_Synth<blip_good_quality,1> Good_Synth;
38
+	typedef Blip_Synth<blip_med_quality ,1> Med_Synth;
39
+	Good_Synth const* good_synth;
40
+	Med_Synth  const* med_synth;
41
+
42
+	int         delay;      // clocks until frequency timer expires
43
+	int         length_ctr; // length counter
44
+	unsigned    phase;      // waveform phase (or equivalent)
45
+	bool        enabled;    // internal enabled flag
46
+
47
+	void clock_length();
48
+	void reset();
49
+};
50
+
51
+class Gb_Env : public Gb_Osc {
52
+public:
53
+	Gb_Env() : env_enabled(false), env_delay(0) {}
54
+	int  env_delay;
55
+	int  volume;
56
+	bool env_enabled;
57
+
58
+	void clock_envelope();
59
+	bool write_register( int frame_phase, int reg, int old_data, int data );
60
+
61
+	void reset()
62
+	{
63
+		env_delay = 0;
64
+		volume    = 0;
65
+		Gb_Osc::reset();
66
+	}
67
+protected:
68
+	// Non-zero if DAC is enabled
69
+	int dac_enabled() const { return regs [2] & 0xF8; }
70
+private:
71
+	void zombie_volume( int old, int data );
72
+	int reload_env_timer();
73
+};
74
+
75
+class Gb_Square : public Gb_Env {
76
+public:
77
+	bool write_register( int frame_phase, int reg, int old_data, int data );
78
+	void run( blip_time_t, blip_time_t );
79
+
80
+	void reset()
81
+	{
82
+		Gb_Env::reset();
83
+		delay = 0x40000000; // TODO: something less hacky (never clocked until first trigger)
84
+	}
85
+private:
86
+	// Frequency timer period
87
+	int period() const { return (2048 - frequency()) * (4 * clk_mul); }
88
+};
89
+
90
+class Gb_Sweep_Square : public Gb_Square {
91
+public:
92
+	int  sweep_freq;
93
+	int  sweep_delay;
94
+	bool sweep_enabled;
95
+	bool sweep_neg;
96
+
97
+	void clock_sweep();
98
+	void write_register( int frame_phase, int reg, int old_data, int data );
99
+
100
+	void reset()
101
+	{
102
+		sweep_freq    = 0;
103
+		sweep_delay   = 0;
104
+		sweep_enabled = false;
105
+		sweep_neg     = false;
106
+		Gb_Square::reset();
107
+	}
108
+private:
109
+	enum { period_mask = 0x70 };
110
+	enum { shift_mask  = 0x07 };
111
+
112
+	void calc_sweep( bool update );
113
+	void reload_sweep_timer();
114
+};
115
+
116
+class Gb_Noise : public Gb_Env {
117
+public:
118
+
119
+	int divider; // noise has more complex frequency divider setup
120
+
121
+	void run( blip_time_t, blip_time_t );
122
+	void write_register( int frame_phase, int reg, int old_data, int data );
123
+
124
+	void reset()
125
+	{
126
+		divider = 0;
127
+		Gb_Env::reset();
128
+		delay = 4 * clk_mul; // TODO: remove?
129
+	}
130
+private:
131
+	enum { period2_mask = 0x1FFFF };
132
+
133
+	int period2_index() const { return regs [3] >> 4; }
134
+	int period2( int base = 8 ) const { return base << period2_index(); }
135
+	unsigned lfsr_mask() const { return (regs [3] & 0x08) ? ~0x4040 : ~0x4000; }
136
+};
137
+
138
+class Gb_Wave : public Gb_Osc {
139
+public:
140
+	int sample_buf; // last wave RAM byte read (hardware has this as well)
141
+
142
+	void write_register( int frame_phase, int reg, int old_data, int data );
143
+	void run( blip_time_t, blip_time_t );
144
+
145
+	// Reads/writes wave RAM
146
+	int read( unsigned addr ) const;
147
+	void write( unsigned addr, int data );
148
+
149
+	void reset()
150
+	{
151
+		sample_buf = 0;
152
+		Gb_Osc::reset();
153
+	}
154
+
155
+private:
156
+	enum { bank40_mask = 0x40 };
157
+	enum { bank_size   = 32 };
158
+
159
+	int agb_mask;               // 0xFF if AGB features enabled, 0 otherwise
160
+	BOOST::uint8_t* wave_ram;   // 32 bytes (64 nybbles), stored in APU
161
+
162
+	friend class Gb_Apu;
163
+
164
+	// Frequency timer period
165
+	int period() const { return (2048 - frequency()) * (2 * clk_mul); }
166
+
167
+	// Non-zero if DAC is enabled
168
+	int dac_enabled() const { return regs [0] & 0x80; }
169
+
170
+	void corrupt_wave();
171
+
172
+	BOOST::uint8_t* wave_bank() const { return &wave_ram [(~regs [0] & bank40_mask) >> 2 & agb_mask]; }
173
+
174
+	// Wave index that would be accessed, or -1 if no access would occur
175
+	int access( unsigned addr ) const;
176
+};
177
+
178
+inline int Gb_Wave::read( unsigned addr ) const
179
+{
180
+	int index = access( addr );
181
+	return (index < 0 ? 0xFF : wave_bank() [index]);
182
+}
183
+
184
+inline void Gb_Wave::write( unsigned addr, int data )
185
+{
186
+	int index = access( addr );
187
+	if ( index >= 0 )
188
+		wave_bank() [index] = data;;
189
+}
190
+
191
+#endif