VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
ReSID.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "SIDTypes.h"
16#include "SubComponent.h"
17#include "AudioPort.h"
18#include "resid/sid.h"
19
20namespace vc64 {
21
22/* This class is a wrapper around the third-party reSID library.
23 *
24 * List of modifications applied to reSID:
25 *
26 * - Changed visibility of some objects from protected to public
27 *
28 * Good candidate for testing sound emulation:
29 *
30 * - INTERNAT.P00
31 * - DEFEND1.PRG ("Das Boot" intro music)
32 * - To Norah (Elysium)
33 * - Vortex (LMan)
34 */
35
36class ReSID final : public SubComponent, public Inspectable<SIDInfo> {
37
38 friend class SID;
39
40 Descriptions descriptions = {{
41
42 .name = "ReSID",
43 .description = "ReSID Backend"
44 }};
45
46
47 // Entry point to the reSID backend
48 reSID::SID *sid;
49
50 // Result of the latest inspection
51 mutable VoiceInfo voiceInfo[3] = { };
52
53private:
54
55 // ReSID state
56 reSID::SID::State st = { };
57
58 // The emulated chip model
59 SIDRevision model = SIDRevision(0);
60
61 // Clock frequency
62 u32 clockFrequency = 0;
63
64 // Sample rate (usually set to 44.1 kHz or 48.0 kHz)
65 double sampleRate = 0;
66
67 // Sampling method
68 SamplingMethod samplingMethod = SamplingMethod(0);
69
70 // Switches filter emulation on or off
71 bool emulateFilter = true;
72
73
74 //
75 // Methods
76 //
77
78public:
79
80 ReSID(C64 &ref, isize id);
81 ~ReSID();
82
83 ReSID& operator= (const ReSID& other) {
84
85 CLONE(st)
86 CLONE(model)
87 CLONE(clockFrequency)
88 CLONE(samplingMethod)
89 CLONE(emulateFilter)
90
91 return *this;
92 }
93
94
95 //
96 // Methods from Serializable
97 //
98
99public:
100
101 template <class T>
102 void serialize(T& worker)
103 {
104 if (isResetter(worker)) return;
105
106 worker
107
108 << st.sid_register
109 << st.bus_value
110 << st.bus_value_ttl
111 << st.write_pipeline
112 << st.write_address
113 << st.voice_mask
114 << st.accumulator
115 << st.shift_register
116 << st.shift_register_reset
117 << st.shift_pipeline
118 << st.pulse_output
119 << st.floating_output_ttl
120 << st.rate_counter
121 << st.rate_counter_period
122 << st.exponential_counter
123 << st.exponential_counter_period
124 << st.envelope_counter
125 << st.envelope_state
126 << st.hold_zero
127 << st.envelope_pipeline
128
129 << model
130 << clockFrequency
131 << samplingMethod
132 << emulateFilter;
133 }
134
135 void operator << (SerResetter &worker) override { serialize(worker); }
136 void operator << (SerChecker &worker) override { }
137 void operator << (SerCounter &worker) override { serialize(worker); }
138 void operator << (SerReader &worker) override;
139 void operator << (SerWriter &worker) override;
140
141
142 //
143 // Methods from CoreComponent
144 //
145
146public:
147
148 const Descriptions &getDescriptions() const override { return descriptions; }
149
150private:
151
152 void _reset(bool hard) override;
153
154
155 //
156 // Methods from Inspectable
157 //
158
159public:
160
161 virtual void record() const override;
162 void cacheInfo(SIDInfo &result) const override;
163
164
165 //
166 // Configuring
167 //
168
169public:
170
171 u32 getClockFrequency() const;
172 void setClockFrequency(u32 frequency);
173
174 SIDRevision getRevision() const;
175 void setRevision(SIDRevision m);
176
177 double getSampleRate() const { return sampleRate; }
178 void setSampleRate(double rate);
179
180 bool getAudioFilter() const { return emulateFilter; }
181 void setAudioFilter(bool enable);
182
183 SamplingMethod getSamplingMethod() const;
184 void setSamplingMethod(SamplingMethod value);
185
186
187 //
188 // Analyzing
189 //
190
191private:
192
193 void _dump(Category category, std::ostream& os) const override;
194
195
196 //
197 // Accessing
198 //
199
200public:
201
202 // Reads or writes a SID register
203 u8 peek(u16 addr);
204 void poke(u16 addr, u8 value);
205
206
207 //
208 // Emulating
209 //
210
211 /* Runs SID for the specified amount of CPU cycles. The generated sound
212 * samples are written into the provided ring buffer. The fuction returns
213 * the number of written audio samples.
214 */
215 isize executeCycles(isize numCycles, SampleStream &stream);
216 isize executeCycles(isize numCycles);
217};
218
219}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16