Debian Codegraph @

src/engine/platform/sound/nes_nsfplay/5e01_dmc.h

raw
1 #ifndef _I5E01_DMC_H_
2 #define _I5E01_DMC_H_
3
4 #include <functional>
5
6 namespace xgm
7 {
8 class I5E01_APU; // forward declaration
9
10 /** Bottom Half of APU **/
11 class I5E01_DMC
12 {
13 public:
14 enum
15 {
16 OPT_ENABLE_4011 = 0,
17 OPT_ENABLE_PNOISE,
18 OPT_UNMUTE_ON_RESET,
19 OPT_DPCM_ANTI_CLICK,
20 OPT_NONLINEAR_MIXER,
21 OPT_RANDOMIZE_NOISE,
22 OPT_TRI_MUTE,
23 OPT_RANDOMIZE_TRI,
24 OPT_DPCM_REVERSE,
25 OPT_END
26 };
27 protected:
28 const int GETA_BITS;
29
30 // DPCM.
31 static const unsigned int freq_table[2][16];
32
33 // Noise.
34 static const unsigned int wavlen_table[2][32];
35
36 unsigned int tnd_table[2][16][16][128];
37
38 int option[OPT_END];
39 int mask;
40 int sm[2][3];
41 unsigned char reg[0x10];
42 unsigned int len_reg;
43 unsigned int adr_reg;
44 std::function<void(unsigned short, unsigned int&)> memory;
45 unsigned int daddress;
46 unsigned int dlength;
47 unsigned int data;
48 bool empty;
49 short damp;
50 int dac_lsb;
51 bool dmc_pop;
52 int dmc_pop_offset;
53 int dmc_pop_follow;
54 double clock;
55 unsigned int rate;
56 int pal;
57 int mode;
58 bool irq;
59
60 int counter[3]; // frequency dividers
61 int tphase; // triangle phase
62 int tduty; // wave shape
63 unsigned int nfreq; // noise frequency
64 unsigned int dfreq; // DPCM frequency
65
66 unsigned int tri_freq;
67 int linear_counter;
68 int linear_counter_reload;
69 bool linear_counter_halt;
70 bool linear_counter_control;
71
72 int noise_volume;
73 unsigned int noise, noise_tap;
74
75 // noise envelope
76 bool envelope_loop;
77 bool envelope_disable;
78 bool envelope_write;
79 int envelope_div_period;
80 int envelope_div;
81 int envelope_counter;
82
83 bool enable[2]; // tri/noise enable
84 int length_counter[2]; // 0=tri, 1=noise
85
86
87 // frame sequencer
88 I5E01_APU* apu; // apu is clocked by DMC's frame sequencer
89 int frame_sequence_count; // current cycle count
90 int frame_sequence_length; // CPU cycles per FrameSequence
91 int frame_sequence_step; // current step of frame sequence
92 int frame_sequence_steps; // 4/5 steps per frame
93 bool frame_irq;
94 bool frame_irq_enable;
95
96 inline unsigned int calc_tri(unsigned int clocks);
97 inline unsigned int calc_dmc(unsigned int clocks);
98 inline unsigned int calc_noise(unsigned int clocks);
99
100 public:
101 unsigned int out[3];
102 I5E01_DMC();
103 ~I5E01_DMC();
104
105 void InitializeTNDTable(double wt, double wn, double wd);
106 void SetPal(bool is_pal);
107 void SetAPU(I5E01_APU* apu_);
108 void SetMemory(std::function<void(unsigned short, unsigned int&)> r);
109 void FrameSequence(int s);
110 int GetDamp() { return (damp << 1) | dac_lsb; }
111 void TickFrameSequence(unsigned int clocks);
112
113 void Reset();
114 void Tick(unsigned int clocks);
115 unsigned int Render(int b[2]);
116 bool Write(unsigned int adr, unsigned int val, unsigned int id = 0);
117 bool Read(unsigned int adr, unsigned int& val, unsigned int id = 0);
118 void SetRate(double rate);
119 void SetClock(double rate);
120 void SetOption(int, int);
121 void SetMask(int m) { mask = m; }
122 void SetStereoMix(int trk, short mixl, short mixr);
123 };
124
125 }
126
127 #endif