VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
sid.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 "C64Types.h"
17#include "ReSID.h"
18
19namespace vc64 {
20
21class SID final : public SubComponent, public Inspectable<SIDInfo>
22{
23 friend class SIDBridge;
24 friend class AudioPort;
25
26 Descriptions descriptions = {
27 {
28 .name = "SID",
29 .description = "Primary Sound Interface Device"
30 },
31 {
32 .name = "SID2",
33 .description = "First Auxiliary SID"
34 },
35 {
36 .name = "SID3",
37 .description = "Second Auxiliary SID"
38 },
39 {
40 .name = "SID4",
41 .description = "Third Auxiliary SID"
42 }
43 };
44
45 ConfigOptions options = {
46
54 };
55
56 // Current configuration
57 SIDConfig config = { };
58
59 // Mirrored SID register contents (for spypeek)
60 u8 sidreg[32];
61
62 // This SID has been executed up to this cycle
63 Cycle clock = 0;
64
65 // The audio stream
66 SampleStream stream;
67
68public:
69
70 // Backends
71 ReSID resid = ReSID(c64, objid);
72
73
74 //
75 // Methods
76 //
77
78public:
79
80 SID(C64 &ref, isize id);
81
82 SID& operator= (const SID& other) {
83
84 CLONE(resid)
85 CLONE(config)
86 CLONE(clock)
87
88 return *this;
89 }
90
91
92 //
93 // Methods from Serializable
94 //
95
96public:
97
98 template <class T>
99 void serialize(T& worker)
100 {
101 worker
102
103 << sidreg
104 << clock
105 << resid;
106
107 if (isResetter(worker)) return;
108
109 worker
110
111 << config.enabled
112 << config.address
113 << config.revision
114 << config.filter
115 << config.sampling;
116 }
117
118 void operator << (SerResetter &worker) override { serialize(worker); }
119 void operator << (SerChecker &worker) override { serialize(worker); }
120 void operator << (SerCounter &worker) override { serialize(worker); }
121 void operator << (SerReader &worker) override;
122 void operator << (SerWriter &worker) override { serialize(worker); }
123
124
125 //
126 // Methods from CoreComponent
127 //
128
129public:
130
131 const Descriptions &getDescriptions() const override { return descriptions; }
132
133private:
134
135 void _dump(Category category, std::ostream& os) const override;
136
137
138 //
139 // Methods from Inspectable
140 //
141
142private:
143
144 void cacheInfo(SIDInfo &result) const override;
145
146
147 //
148 // Methods from Configurable
149 //
150
151public:
152
153 const SIDConfig &getConfig() const { return config; }
154 const ConfigOptions &getOptions() const override { return options; }
155 i64 getFallback(Option opt) const override;
156 i64 getOption(Option opt) const override;
157 void checkOption(Option opt, i64 value) override;
158 void setOption(Option opt, i64 value) override;
159
160
161 //
162 // Accessing
163 //
164
165public:
166
167 // Checks if this SID is present
168 bool isEnabled() const { return config.enabled; }
169
170 // Reads the real value of a SID register (used by the debugger only)
171 u8 spypeek(u16 addr) const;
172
173 // Reads a SID register
174 u8 peek(u16 addr);
175
176 // Writes a SID register
177 void poke(u16 addr, u8 value);
178
179
180 //
181 // Computing audio samples
182 //
183
184 /* Executes SID until a certain cycle is reached. The function returns the
185 * number of produced sound samples (not yet).
186 */
187 void executeUntil(Cycle targetCycle);
188
189 // Indicates if sample synthesis should be skipped
190 bool powerSave() const;
191
192
193 //
194 // Bridge functions
195 //
196
197public:
198
199 u32 getClockFrequency() const;
200 void setClockFrequency(u32 frequency);
201
202 SIDRevision getRevision() const;
203 void setRevision(SIDRevision revision);
204
205 double getSampleRate() const;
206 void setSampleRate(double rate);
207
208 bool getAudioFilter() const;
209 void setAudioFilter(bool enable);
210
211 SamplingMethod getSamplingMethod() const;
212 void setSamplingMethod(SamplingMethod method);
213};
214
215};
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
@ OPT_SID_SAMPLING
Audio sampling mode.
Definition OptionTypes.h:113
@ OPT_SID_ENGINE
SID backend (e.g., reSID)
Definition OptionTypes.h:112
@ OPT_SID_FILTER
Enable or disables the audio filter.
Definition OptionTypes.h:111
@ OPT_SID_ADDRESS
Mapping address in memory.
Definition OptionTypes.h:109
@ OPT_SID_ENABLE
Enable or disable SID.
Definition OptionTypes.h:108
@ OPT_SID_REVISION
Chip revision.
Definition OptionTypes.h:110
@ OPT_SID_POWER_SAVE
Enable fast-paths.
Definition OptionTypes.h:114