-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSID.cpp
executable file
·240 lines (188 loc) · 4.27 KB
/
SID.cpp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
Frodo, Commodore 64 emulator for the iPhone
Copyright (C) 1994-1997,2002 Christian Bauer
See gpl.txt for license information.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if 1
/*
* SID.cpp - 6581 emulation
*
* Frodo (C) 1994-1997,2002 Christian Bauer
*
*
* Incompatibilities:
* ------------------
*
* - Lots of empirically determined constants in the filter calculations
* - Voice 3 cannot be muted
*/
#include "sysdeps.h"
#include <math.h>
#include "SID.h"
#include "Prefs.h"
#include "Display.h"
#include "VIC.h"
#ifdef USE_FIXPOINT_MATHS
#include "FixPoint.i"
#endif
/*
* Constructor
*/
MOS6581::MOS6581(C64 *c64) : the_c64(c64)
{
the_renderer = NULL;
for (int i=0; i<32; i++)
regs[i] = 0;
// Open the renderer
open_close_renderer(SIDTYPE_NONE, ThePrefs.SIDType);
}
/*
* Destructor
*/
MOS6581::~MOS6581()
{
// Close the renderer
open_close_renderer(ThePrefs.SIDType, SIDTYPE_NONE);
}
/*
* Reset the SID
*/
void MOS6581::Reset(void)
{
assert(the_renderer != NULL);
for (int i=0; i<32; i++)
regs[i] = 0;
last_sid_byte = 0;
the_renderer->Reset();
}
/*
* Preferences may have changed
*/
void MOS6581::NewPrefs(Prefs *prefs)
{
assert(the_renderer != NULL);
open_close_renderer(ThePrefs.SIDType, prefs->SIDType);
the_renderer->NewPrefs(prefs);
}
/*
* Pause sound output
*/
void MOS6581::PauseSound(void)
{
assert(the_renderer != NULL);
the_renderer->Pause();
}
/*
* Resume sound output
*/
void MOS6581::ResumeSound(void)
{
assert(the_renderer != NULL);
the_renderer->Resume();
}
/*
* Get SID state
*/
void MOS6581::GetState(MOS6581State *ss)
{
ss->freq_lo_1 = regs[0];
ss->freq_hi_1 = regs[1];
ss->pw_lo_1 = regs[2];
ss->pw_hi_1 = regs[3];
ss->ctrl_1 = regs[4];
ss->AD_1 = regs[5];
ss->SR_1 = regs[6];
ss->freq_lo_2 = regs[7];
ss->freq_hi_2 = regs[8];
ss->pw_lo_2 = regs[9];
ss->pw_hi_2 = regs[10];
ss->ctrl_2 = regs[11];
ss->AD_2 = regs[12];
ss->SR_2 = regs[13];
ss->freq_lo_3 = regs[14];
ss->freq_hi_3 = regs[15];
ss->pw_lo_3 = regs[16];
ss->pw_hi_3 = regs[17];
ss->ctrl_3 = regs[18];
ss->AD_3 = regs[19];
ss->SR_3 = regs[20];
ss->fc_lo = regs[21];
ss->fc_hi = regs[22];
ss->res_filt = regs[23];
ss->mode_vol = regs[24];
ss->pot_x = 0xff;
ss->pot_y = 0xff;
ss->osc_3 = 0;
ss->env_3 = 0;
}
/*
* Restore SID state
*/
void MOS6581::SetState(MOS6581State *ss)
{
regs[0] = ss->freq_lo_1;
regs[1] = ss->freq_hi_1;
regs[2] = ss->pw_lo_1;
regs[3] = ss->pw_hi_1;
regs[4] = ss->ctrl_1;
regs[5] = ss->AD_1;
regs[6] = ss->SR_1;
regs[7] = ss->freq_lo_2;
regs[8] = ss->freq_hi_2;
regs[9] = ss->pw_lo_2;
regs[10] = ss->pw_hi_2;
regs[11] = ss->ctrl_2;
regs[12] = ss->AD_2;
regs[13] = ss->SR_2;
regs[14] = ss->freq_lo_3;
regs[15] = ss->freq_hi_3;
regs[16] = ss->pw_lo_3;
regs[17] = ss->pw_hi_3;
regs[18] = ss->ctrl_3;
regs[19] = ss->AD_3;
regs[20] = ss->SR_3;
regs[21] = ss->fc_lo;
regs[22] = ss->fc_hi;
regs[23] = ss->res_filt;
regs[24] = ss->mode_vol;
// Stuff the new register values into the renderer
if (the_renderer != NULL)
for (int i=0; i<25; i++)
the_renderer->WriteRegister(i, regs[i]);
}
//#import "DigitalRenderer.h"
#ifdef USE_FASTSID
#import "FastDigitalRenderer.h"
#else
#import "DigitalRenderer.h"
#endif
/*
* Open/close the renderer, according to old and new prefs
*/
void MOS6581::open_close_renderer(int old_type, int new_type)
{
if (old_type == new_type)
return;
// Delete the old renderer
delete the_renderer;
// Create new renderer
if (new_type == SIDTYPE_DIGITAL)
the_renderer = new RENDERER_TYPE();
else
the_renderer = NULL;
// Stuff the current register values into the new renderer
if (the_renderer != NULL)
for (int i=0; i<25; i++)
the_renderer->WriteRegister(i, regs[i]);
}
#endif