forked from gardners/c65gs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sid_6581.vhd
356 lines (320 loc) · 13 KB
/
sid_6581.vhd
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
-------------------------------------------------------------------------------
--
-- SID 6581
--
-- A fully functional SID chip implementation in VHDL
--
-------------------------------------------------------------------------------
-- to do: - filter
-- - smaller implementation, use multiplexed channels
--
--
-- "The Filter was a classic multi-mode (state variable) VCF design. There was
-- no way to create a variable transconductance amplifier in our NMOS process,
-- so I simply used FETs as voltage-controlled resistors to control the cutoff
-- frequency. An 11-bit D/A converter generates the control voltage for the
-- FETs (it's actually a 12-bit D/A, but the LSB had no audible affect so I
-- disconnected it!)."
-- "Filter resonance was controlled by a 4-bit weighted resistor ladder. Each
-- bit would turn on one of the weighted resistors and allow a portion of the
-- output to feed back to the input. The state-variable design provided
-- simultaneous low-pass, band-pass and high-pass outputs. Analog switches
-- selected which combination of outputs were sent to the final amplifier (a
-- notch filter was created by enabling both the high and low-pass outputs
-- simultaneously)."
-- "The filter is the worst part of SID because I could not create high-gain
-- op-amps in NMOS, which were essential to a resonant filter. In addition,
-- the resistance of the FETs varied considerably with processing, so different
-- lots of SID chips had different cutoff frequency characteristics. I knew it
-- wouldn't work very well, but it was better than nothing and I didn't have
-- time to make it better."
--
-------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
-------------------------------------------------------------------------------
entity sid6581 is
port (
clk_1MHz : in std_logic; -- main SID clock signal
clk32 : in std_logic; -- main clock signal
reset : in std_logic; -- high active signal (reset when reset = '1')
cs : in std_logic; -- "chip select", when this signal is '1' this model can be accessed
we : in std_logic; -- when '1' this model can be written to, otherwise access is considered as read
addr : in unsigned(4 downto 0); -- address lines
di : in unsigned(7 downto 0); -- data in (to chip)
do : out unsigned(7 downto 0); -- data out (from chip)
pot_x : in unsigned(7 downto 0); -- paddle input-X
pot_y : in unsigned(7 downto 0); -- paddle input-Y
audio_data : out unsigned(17 downto 0)
);
end sid6581;
architecture Behavioral of sid6581 is
signal reset_drive : std_logic;
signal Voice_1_Freq_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_1_Freq_hi : unsigned(7 downto 0) := (others => '0');
signal Voice_1_Pw_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_1_Pw_hi : unsigned(3 downto 0) := (others => '0');
signal Voice_1_Control : unsigned(7 downto 0) := (others => '0');
signal Voice_1_Att_dec : unsigned(7 downto 0) := (others => '0');
signal Voice_1_Sus_Rel : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Freq_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Freq_hi : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Pw_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Pw_hi : unsigned(3 downto 0) := (others => '0');
signal Voice_2_Control : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Att_dec : unsigned(7 downto 0) := (others => '0');
signal Voice_2_Sus_Rel : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Freq_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Freq_hi : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Pw_lo : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Pw_hi : unsigned(3 downto 0) := (others => '0');
signal Voice_3_Control : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Att_dec : unsigned(7 downto 0) := (others => '0');
signal Voice_3_Sus_Rel : unsigned(7 downto 0) := (others => '0');
signal Filter_Fc_lo : unsigned(7 downto 0) := (others => '0');
signal Filter_Fc_hi : unsigned(7 downto 0) := (others => '0');
signal Filter_Res_Filt : unsigned(7 downto 0) := (others => '0');
signal Filter_Mode_Vol : unsigned(7 downto 0) := (others => '0');
signal Misc_Osc3_Random : unsigned(7 downto 0) := (others => '0');
signal Misc_Env3 : unsigned(7 downto 0) := (others => '0');
signal do_buf : unsigned(7 downto 0) := (others => '0');
signal voice_1 : unsigned(11 downto 0) := (others => '0');
signal voice_2 : unsigned(11 downto 0) := (others => '0');
signal voice_3 : unsigned(11 downto 0) := (others => '0');
signal divide_0 : unsigned(31 downto 0) := (others => '0');
signal voice_1_PA_MSB : std_logic := '0';
signal voice_2_PA_MSB : std_logic := '0';
signal voice_3_PA_MSB : std_logic := '0';
signal voice1_signed : signed(12 downto 0);
signal voice2_signed : signed(12 downto 0);
signal voice3_signed : signed(12 downto 0);
-- filter
constant ext_in_signed : signed(12 downto 0) := to_signed(0,13);
signal filtered_audio : signed(18 downto 0);
signal tick_q1, tick_q2 : std_logic;
signal input_valid : std_logic;
signal unsigned_audio : unsigned(17 downto 0);
signal unsigned_filt : unsigned(18 downto 0);
signal ff1 : std_logic;
-------------------------------------------------------------------------------
begin
sid_voice_1: entity work.sid_voice
port map(
clk_1MHz => clk_1MHz,
reset => reset_drive,
Freq_lo => Voice_1_Freq_lo,
Freq_hi => Voice_1_Freq_hi,
Pw_lo => Voice_1_Pw_lo,
Pw_hi => Voice_1_Pw_hi,
Control => Voice_1_Control,
Att_dec => Voice_1_Att_dec,
Sus_Rel => Voice_1_Sus_Rel,
PA_MSB_in => voice_3_PA_MSB,
PA_MSB_out => voice_1_PA_MSB,
-- Osc => open,
-- Env => open,
voice => voice_1
);
sid_voice_2: entity work.sid_voice
port map(
clk_1MHz => clk_1MHz,
reset => reset_drive,
Freq_lo => Voice_2_Freq_lo,
Freq_hi => Voice_2_Freq_hi,
Pw_lo => Voice_2_Pw_lo,
Pw_hi => Voice_2_Pw_hi,
Control => Voice_2_Control,
Att_dec => Voice_2_Att_dec,
Sus_Rel => Voice_2_Sus_Rel,
PA_MSB_in => voice_1_PA_MSB,
PA_MSB_out => voice_2_PA_MSB,
-- Osc => open,
-- Env => open,
voice => voice_2
);
sid_voice_3: entity work.sid_voice
port map(
clk_1MHz => clk_1MHz,
reset => reset_drive,
Freq_lo => Voice_3_Freq_lo,
Freq_hi => Voice_3_Freq_hi,
Pw_lo => Voice_3_Pw_lo,
Pw_hi => Voice_3_Pw_hi,
Control => Voice_3_Control,
Att_dec => Voice_3_Att_dec,
Sus_Rel => Voice_3_Sus_Rel,
PA_MSB_in => voice_2_PA_MSB,
PA_MSB_out => voice_3_PA_MSB,
Osc => Misc_Osc3_Random,
Env => Misc_Env3,
voice => voice_3
);
-------------------------------------------------------------------------------------
-- SID filters
process (do_buf,cs)
begin
-- Tristate data lines
if cs='1' then
-- Read from SID-register
-------------------------
case addr is
-------------------------------------- Misc
when "11001" => do <= pot_x;
when "11010" => do <= pot_Y;
when "11011" => do <= Misc_Osc3_Random;
when "11100" => do <= Misc_Env3;
--------------------------------------
when others => do <= x"FF";
end case;
else
do <= (others => 'Z');
end if;
end process;
process (clk_1MHz,reset)
begin
if reset_drive='1' then
ff1<='0';
else
if rising_edge(clk_1MHz) then
ff1<=not ff1;
end if;
end if;
end process;
process(clk32)
begin
if rising_edge(clk32) then
reset_drive <= reset;
tick_q1 <= ff1;
tick_q2 <= tick_q1;
end if;
end process;
input_valid <= '1' when tick_q1 /=tick_q2 else '0';
voice1_signed <= signed("0" & voice_1) - 2048;
voice2_signed <= signed("0" & voice_2) - 2048;
voice3_signed <= signed("0" & voice_3) - 2048;
filters: entity work.sid_filters
port map (
clk => clk32,
rst => reset_drive,
-- SID registers.
Fc_lo => Filter_Fc_lo,
Fc_hi => Filter_Fc_hi,
Res_Filt => Filter_Res_Filt,
Mode_Vol => Filter_Mode_Vol,
-- Voices - resampled to 13 bit
voice1 => voice1_signed,
voice2 => voice2_signed,
voice3 => voice3_signed,
--
input_valid => input_valid,
ext_in => ext_in_signed,
sound => filtered_audio,
valid => open
);
unsigned_filt <= unsigned(filtered_audio + "1000000000000000000");
unsigned_audio <= unsigned_filt(18 downto 1);
audio_data <= unsigned_audio;
-- Register decoding
register_decoder:process(clk32)
begin
if rising_edge(clk32) then
if (reset_drive = '1') then
--------------------------------------- Voice-1
Voice_1_Freq_lo <= (others => '0');
Voice_1_Freq_hi <= (others => '0');
Voice_1_Pw_lo <= (others => '0');
Voice_1_Pw_hi <= (others => '0');
Voice_1_Control <= (others => '0');
Voice_1_Att_dec <= (others => '0');
Voice_1_Sus_Rel <= (others => '0');
--------------------------------------- Voice-2
Voice_2_Freq_lo <= (others => '0');
Voice_2_Freq_hi <= (others => '0');
Voice_2_Pw_lo <= (others => '0');
Voice_2_Pw_hi <= (others => '0');
Voice_2_Control <= (others => '0');
Voice_2_Att_dec <= (others => '0');
Voice_2_Sus_Rel <= (others => '0');
--------------------------------------- Voice-3
Voice_3_Freq_lo <= (others => '0');
Voice_3_Freq_hi <= (others => '0');
Voice_3_Pw_lo <= (others => '0');
Voice_3_Pw_hi <= (others => '0');
Voice_3_Control <= (others => '0');
Voice_3_Att_dec <= (others => '0');
Voice_3_Sus_Rel <= (others => '0');
--------------------------------------- Filter & volume
Filter_Fc_lo <= (others => '0');
Filter_Fc_hi <= (others => '0');
Filter_Res_Filt <= (others => '0');
Filter_Mode_Vol <= (others => '0');
else
Voice_1_Freq_lo <= Voice_1_Freq_lo;
Voice_1_Freq_hi <= Voice_1_Freq_hi;
Voice_1_Pw_lo <= Voice_1_Pw_lo;
Voice_1_Pw_hi <= Voice_1_Pw_hi;
Voice_1_Control <= Voice_1_Control;
Voice_1_Att_dec <= Voice_1_Att_dec;
Voice_1_Sus_Rel <= Voice_1_Sus_Rel;
Voice_2_Freq_lo <= Voice_2_Freq_lo;
Voice_2_Freq_hi <= Voice_2_Freq_hi;
Voice_2_Pw_lo <= Voice_2_Pw_lo;
Voice_2_Pw_hi <= Voice_2_Pw_hi;
Voice_2_Control <= Voice_2_Control;
Voice_2_Att_dec <= Voice_2_Att_dec;
Voice_2_Sus_Rel <= Voice_2_Sus_Rel;
Voice_3_Freq_lo <= Voice_3_Freq_lo;
Voice_3_Freq_hi <= Voice_3_Freq_hi;
Voice_3_Pw_lo <= Voice_3_Pw_lo;
Voice_3_Pw_hi <= Voice_3_Pw_hi;
Voice_3_Control <= Voice_3_Control;
Voice_3_Att_dec <= Voice_3_Att_dec;
Voice_3_Sus_Rel <= Voice_3_Sus_Rel;
Filter_Fc_lo <= Filter_Fc_lo;
Filter_Fc_hi <= Filter_Fc_hi;
Filter_Res_Filt <= Filter_Res_Filt;
Filter_Mode_Vol <= Filter_Mode_Vol;
do_buf <= (others => '0');
if (cs='1') then
if (we='1') then -- Write to SID-register
------------------------
case addr is
-------------------------------------- Voice-1
when "00000" => Voice_1_Freq_lo <= di;
when "00001" => Voice_1_Freq_hi <= di;
when "00010" => Voice_1_Pw_lo <= di;
when "00011" => Voice_1_Pw_hi <= di(3 downto 0);
when "00100" => Voice_1_Control <= di;
when "00101" => Voice_1_Att_dec <= di;
when "00110" => Voice_1_Sus_Rel <= di;
--------------------------------------- Voice-2
when "00111" => Voice_2_Freq_lo <= di;
when "01000" => Voice_2_Freq_hi <= di;
when "01001" => Voice_2_Pw_lo <= di;
when "01010" => Voice_2_Pw_hi <= di(3 downto 0);
when "01011" => Voice_2_Control <= di;
when "01100" => Voice_2_Att_dec <= di;
when "01101" => Voice_2_Sus_Rel <= di;
--------------------------------------- Voice-3
when "01110" => Voice_3_Freq_lo <= di;
when "01111" => Voice_3_Freq_hi <= di;
when "10000" => Voice_3_Pw_lo <= di;
when "10001" => Voice_3_Pw_hi <= di(3 downto 0);
when "10010" => Voice_3_Control <= di;
when "10011" => Voice_3_Att_dec <= di;
when "10100" => Voice_3_Sus_Rel <= di;
--------------------------------------- Filter & volume
when "10101" => Filter_Fc_lo <= di;
when "10110" => Filter_Fc_hi <= di;
when "10111" => Filter_Res_Filt <= di;
when "11000" => Filter_Mode_Vol <= di;
--------------------------------------
when others => null;
end case;
end if;
end if;
end if;
end if;
end process;
end Behavioral;