Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/nes_emu/Nes_Oscs.h
2 views
1
2
// Private oscillators used by Nes_Apu
3
4
// Nes_Snd_Emu 0.1.7
5
6
#ifndef NES_OSCS_H
7
#define NES_OSCS_H
8
9
#include "blargg_common.h"
10
#include "Blip_Buffer.h"
11
12
class Nes_Apu;
13
14
struct Nes_Osc
15
{
16
unsigned char regs [4];
17
bool reg_written [4];
18
Blip_Buffer* output;
19
int length_counter;// length counter (0 if unused by oscillator)
20
int delay; // delay until next (potential) transition
21
int last_amp; // last amplitude oscillator was outputting
22
23
void clock_length( int halt_mask );
24
int period() const {
25
return (regs [3] & 7) * 0x100 + (regs [2] & 0xff);
26
}
27
void reset() {
28
delay = 0;
29
last_amp = 0;
30
}
31
int update_amp( int amp ) {
32
int delta = amp - last_amp;
33
last_amp = amp;
34
return delta;
35
}
36
};
37
38
struct Nes_Envelope : Nes_Osc
39
{
40
int envelope;
41
int env_delay;
42
43
void clock_envelope();
44
int volume() const;
45
void reset() {
46
envelope = 0;
47
env_delay = 0;
48
Nes_Osc::reset();
49
}
50
};
51
52
// Nes_Square
53
struct Nes_Square : Nes_Envelope
54
{
55
enum { negate_flag = 0x08 };
56
enum { shift_mask = 0x07 };
57
enum { phase_range = 8 };
58
int phase;
59
int sweep_delay;
60
61
typedef Blip_Synth<blip_good_quality,1> Synth;
62
Synth const& synth; // shared between squares
63
64
Nes_Square( Synth const* s ) : synth( *s ) { }
65
66
void clock_sweep( int adjust );
67
void run( nes_time_t, nes_time_t );
68
void reset() {
69
sweep_delay = 0;
70
Nes_Envelope::reset();
71
}
72
nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time,
73
nes_time_t timer_period );
74
};
75
76
// Nes_Triangle
77
struct Nes_Triangle : Nes_Osc
78
{
79
enum { phase_range = 16 };
80
int phase;
81
int linear_counter;
82
Blip_Synth<blip_med_quality,1> synth;
83
84
int calc_amp() const;
85
void run( nes_time_t, nes_time_t );
86
void clock_linear_counter();
87
void reset() {
88
linear_counter = 0;
89
phase = 1;
90
Nes_Osc::reset();
91
}
92
nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time,
93
nes_time_t timer_period );
94
};
95
96
// Nes_Noise
97
struct Nes_Noise : Nes_Envelope
98
{
99
int noise;
100
Blip_Synth<blip_med_quality,1> synth;
101
102
void run( nes_time_t, nes_time_t );
103
void reset() {
104
noise = 1 << 14;
105
Nes_Envelope::reset();
106
}
107
};
108
109
// Nes_Dmc
110
struct Nes_Dmc : Nes_Osc
111
{
112
int address; // address of next byte to read
113
int period;
114
//int length_counter; // bytes remaining to play (already defined in Nes_Osc)
115
int buf;
116
int bits_remain;
117
int bits;
118
bool buf_full;
119
bool silence;
120
121
enum { loop_flag = 0x40 };
122
123
int dac;
124
125
nes_time_t next_irq;
126
bool irq_enabled;
127
bool irq_flag;
128
bool pal_mode;
129
bool nonlinear;
130
131
int (*prg_reader)( void*, nes_addr_t ); // needs to be initialized to prg read function
132
void* prg_reader_data;
133
134
Nes_Apu* apu;
135
136
Blip_Synth<blip_med_quality,1> synth;
137
138
void start();
139
void write_register( int, int );
140
void run( nes_time_t, nes_time_t );
141
void recalc_irq();
142
void fill_buffer();
143
void reload_sample();
144
void reset();
145
int count_reads( nes_time_t, nes_time_t* ) const;
146
nes_time_t next_read_time() const;
147
};
148
149
#endif
150
151
152