VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Emulator.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 "C64.h"
16#include "Defaults.h"
17#include "EmulatorTypes.h"
18#include "Host.h"
19#include "Thread.h"
20#include "CmdQueue.h"
21
22namespace vc64 {
23
24class VirtualC64;
25
26class Emulator : public Thread, public Synchronizable,
27public Inspectable<EmulatorInfo, EmulatorStats>, public Configurable {
28
29 friend class API;
30 friend class VirtualC64;
31
32 ConfigOptions options = { };
33 EmulatorConfig config = { };
34
35 // The virtual C64
36 C64 main = C64(*this, 0);
37
38 // The run-ahead instance
39 C64 ahead = C64(*this, 1);
40
41 // Keeps track of the number of recreated run-ahead instances
42 isize clones = 0;
43
44public:
45
46 // Storage for external events
47 CmdQueue cmdQueue;
48
49 // User default settings
50 static Defaults defaults;
51
52 // Information about the host system
53 Host host = Host(*this);
54
55
56 //
57 // Methods
58 //
59
60public:
61
62 Emulator();
63 ~Emulator();
64
65 // Launches the emulator thread
66 void launch(const void *listener, Callback *func);
67
68 // Initializes all components
69 void initialize();
70
71 // Checks the initialization state
72 bool isInitialized() const;
73
74 // Marks the run-ahead instance as dirty
75 // [[deprecated]] void markAsDirty() { main.markAsDirty(); }
76
77
78 //
79 // Methods from CoreComponent
80 //
81
82public:
83
84 const char *objectName() const override { return "Emulator"; }
85
86private:
87
88 void _dump(Category category, std::ostream& os) const override;
89
90
91 //
92 // Methods from Inspectable
93 //
94
95public:
96
97 void cacheInfo(EmulatorInfo &result) const override;
98 void cacheStats(EmulatorStats &result) const override;
99
100
101 //
102 // Methods from Configurable
103 //
104
105public:
106
107 const ConfigOptions &getOptions() const override { return options; }
108 i64 getOption(Option opt) const override;
109 void checkOption(Option opt, i64 value) override;
110 void setOption(Option opt, i64 value) override;
111
112
113 //
114 // Main entry points for configuring the emulator
115 //
116
117public:
118
119 // Queries an option
120 i64 get(Option opt, isize id = 0) const;
121
122 // Checks an option
123 void check(Option opt, i64 value, std::optional<isize> id = std::nullopt);
124
125 // Sets an option
126 void set(Option opt, i64 value, std::optional<isize> id = std::nullopt);
127
128 // Convenience wrappers
129 void set(Option opt, const string &value) throws;
130 void set(Option opt, const string &value, isize id) throws;
131 void set(const string &opt, const string &value) throws;
132 void set(const string &opt, const string &value, isize id) throws;
133
134 // Configures the emulator to match a specific C64 model
135 void set(C64Model model);
136
137private:
138
139 const EmulatorConfig &getConfig() const { return config; }
140 void resetConfig();
141
142 // Returns the target component for an option
143 std::vector<Configurable *> routeOption(Option opt);
144 std::vector<const Configurable *> routeOption(Option opt) const;
145
146 // Overrides a config option if the corresponding debug option is enabled
147 i64 overrideOption(Option opt, i64 value) const;
148
149 // Powers off and resets the emulator to it's initial state
150 void revertToFactorySettings();
151
152
153 //
154 // Methods from Thread
155 //
156
157private:
158
159 void update() override;
160 bool shouldWarp();
161 isize missingFrames() const override;
162 void computeFrame() override;
163 void recreateRunAheadInstance();
164
165 void _powerOn() override { main.powerOn(); }
166 void _powerOff() override { main.powerOff(); }
167 void _pause() override { main.pause(); }
168 void _run() override { main.run(); }
169 void _halt() override { main.halt(); }
170 void _warpOn() override { main.warpOn(); }
171 void _warpOff() override { main.warpOff(); }
172 void _trackOn() override { main.trackOn(); }
173 void _trackOff() override { main.trackOff(); }
174
175 void isReady() override;
176
177public:
178
179 double refreshRate() const override;
180
181
182 //
183 // Execution control
184 //
185
186public:
187
188 void stepInto();
189 void stepOver();
190
191
192 //
193 // Audio and Video
194 //
195
196 u32 *getTexture() const;
197 u32 *getDmaTexture() const;
198
199
200 //
201 // Command queue
202 //
203
204public:
205
206 // Feeds a command into the command queue
207 void put(const Cmd &cmd);
208 void put(CmdType type, i64 payload) { put (Cmd(type, payload)); }
209
210private:
211
212 // Processes a command from the command queue
213 void process(const Cmd &cmd);
214};
215
216}
Command queue.
Definition CmdQueue.h:25
Inspection interface.
Definition Inspectable.h:32
Implements the emulator's state model.
Definition Thread.h:35
Public API.
Definition VirtualC64.h:1086
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
C64_MODEL
C64 model.
Definition C64Types.h:33
CMD_TYPE
Emulator command.
Definition CmdQueueTypes.h:28
OPT
Configuration option.
Definition OptionTypes.h:26
The current emulator configuration.
Definition EmulatorTypes.h:302
The current emulator state.
Definition EmulatorTypes.h:309
Collected run-time data.
Definition EmulatorTypes.h:323