Debian Codegraph @

src/engine/platform/sound/sid2/wave.cc

raw
1 // ---------------------------------------------------------------------------
2 // This file is part of reSID, a MOS6581_2 SID2 emulator engine.
3 // Copyright (C) 2004 Dag Lem <[email protected]>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ---------------------------------------------------------------------------
19
20 #define __WAVE_CC__
21 #include "wave.h"
22
23 // ----------------------------------------------------------------------------
24 // Constructor.
25 // ----------------------------------------------------------------------------
26 WaveformGenerator2::WaveformGenerator2()
27 {
28 sync_source = this;
29
30 set_chip_model(MOS6581_2);
31
32 reset();
33 }
34
35
36 // ----------------------------------------------------------------------------
37 // Set sync source.
38 // ----------------------------------------------------------------------------
39 void WaveformGenerator2::set_sync_source(WaveformGenerator2* source)
40 {
41 sync_source = source;
42 source->sync_dest = this;
43 }
44
45
46 // ----------------------------------------------------------------------------
47 // Set chip model.
48 // ----------------------------------------------------------------------------
49 void WaveformGenerator2::set_chip_model(chip_model2 model)
50 {
51 wave__ST = wave8580__ST;
52 wave_P_T = wave8580_P_T;
53 wave_PS_ = wave8580_PS_;
54 wave_PST = wave8580_PST;
55 }
56
57
58 // ----------------------------------------------------------------------------
59 // Register functions.
60 // ----------------------------------------------------------------------------
61 void WaveformGenerator2::writeFREQ_LO(reg8 freq_lo)
62 {
63 freq = (freq & 0x1ff00) | (freq_lo & 0x00ff);
64 }
65
66 void WaveformGenerator2::writeFREQ_HI(reg8 freq_hi)
67 {
68 freq = ((freq_hi << 8) & 0xff00) | (freq & 0x100ff);
69 }
70
71 void WaveformGenerator2::writeFREQ_HIGHEST(reg8 freq_highest)
72 {
73 freq = ((freq_highest << 16) & 0x10000) | (freq & 0xffff);
74 }
75
76 void WaveformGenerator2::writePW_LO(reg8 pw_lo)
77 {
78 pw = (pw & 0xf00) | (pw_lo & 0x0ff);
79 }
80
81 void WaveformGenerator2::writePW_HI(reg8 pw_hi)
82 {
83 pw = ((pw_hi << 8) & 0xf00) | (pw & 0x0ff);
84 }
85
86 void WaveformGenerator2::writeCONTROL_REG(reg8 control)
87 {
88 waveform = (control >> 4) & 0x0f;
89 ring_mod = control & 0x04;
90 sync = control & 0x02;
91
92 reg8 test_next = control & 0x08;
93
94 // Test bit set.
95 // The accumulator and the shift register are both cleared.
96 // NB! The shift register is not really cleared immediately. It seems like
97 // the individual bits in the shift register start to fade down towards
98 // zero when test is set. All bits reach zero within approximately
99 // $2000 - $4000 cycles.
100 // This is not modeled. There should fortunately be little audible output
101 // from this peculiar behavior.
102 if (test_next) {
103 accumulator = 0;
104 shift_register = 0;
105 }
106 // Test bit cleared.
107 // The accumulator starts counting, and the shift register is reset to
108 // the value 0x7ffff8.
109 // NB! The shift register will not actually be set to this exact value if the
110 // shift register bits have not had time to fade to zero.
111 // This is not modeled.
112 else if (test) {
113 shift_register = 0x7ffff8;
114 }
115
116 test = test_next;
117
118 // The gate bit is handled by the EnvelopeGenerator2.
119 }
120
121 void WaveformGenerator2::writeNOISE_MODE(reg8 value)
122 {
123 if(noise_mode != value)
124 {
125 shift_register = 0x7ffff8;
126 }
127
128 noise_mode = value;
129 }
130
131 void WaveformGenerator2::writeMIX_MODE(reg8 value)
132 {
133 mix_mode = value;
134 }
135
136 reg8 WaveformGenerator2::readOSC()
137 {
138 return output() >> 4;
139 }
140
141 // ----------------------------------------------------------------------------
142 // SID2 reset.
143 // ----------------------------------------------------------------------------
144 void WaveformGenerator2::reset()
145 {
146 accumulator = 0;
147 shift_register = 0x7ffff8;
148 freq = 0;
149 pw = 0;
150
151 test = 0;
152 ring_mod = 0;
153 sync = 0;
154
155 msb_rising = false;
156
157 mix_mode = 0;
158 noise_mode = 3;
159 }