VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
CoreComponent.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 "EmulatorTypes.h"
16#include "CoreObject.h"
17#include "Synchronizable.h"
18#include "Serializable.h"
19#include "Configurable.h"
20#include "Inspectable.h"
21#include "Concurrency.h"
22#include "Suspendable.h"
23#include "ThreadTypes.h"
24#include <vector>
25
26namespace vc64 {
27
28struct Description {
29
30 const char *name;
31 const char *description;
32};
33
34typedef std::vector<Description> Descriptions;
35
36class CoreComponent :
37public CoreObject, public Serializable, public Suspendable, public Synchronizable, public Configurable {
38
39public:
40
41 // Reference to the emulator this instance belongs to
42 class Emulator &emulator;
43
44 // Object identifier (to distinguish instances of the same component)
45 const isize objid;
46
47 // Sub components
48 std::vector<CoreComponent *> subComponents;
49
50
51 //
52 // Initializing
53 //
54
55public:
56
57 CoreComponent(Emulator& ref) : emulator(ref), objid(0) { }
58 CoreComponent(Emulator& ref, isize id) : emulator(ref), objid(id) { }
59
60 virtual const Descriptions &getDescriptions() const = 0;
61 const char *objectName() const override;
62 const char *description() const override;
63
64 bool operator== (CoreComponent &other);
65 bool operator!= (CoreComponent &other) { return !(other == *this); }
66
67 /* This function is called inside the emulator's launch routine. It iterates
68 * through all components and calls the _initialize() delegate.
69 */
70 void initialize();
71 virtual void _initialize() { }
72
73 // Main reset routines
74 void hardReset();
75 void softReset();
76
77 /* This function is called inside the C64 reset routines. It iterates
78 * through all components and calls the _reset() delegate.
79 */
80 void reset(bool hard);
81 virtual void _reset(bool hard) { }
82
83 // Returns the fallback value for a config option
84 i64 getFallback(Option opt) const override;
85
86 // Resets the configuration of this component and all subcomponents
87 virtual void resetConfig();
88
89 //
90 void routeOption(Option opt, std::vector<Configurable *> &result);
91
92
93 //
94 // Controlling the state (see Thread class for details)
95 //
96
97public:
98
99 virtual bool isPoweredOff() const;
100 virtual bool isPoweredOn() const;
101 virtual bool isPaused() const;
102 virtual bool isRunning() const;
103 virtual bool isSuspended() const;
104 virtual bool isHalted() const;
105
106 void suspend() override;
107 void resume() override;
108
109 // Throws an exception if the emulator is not ready to power on
110 virtual void isReady() const throws;
111
112protected:
113
114 void powerOn();
115 void powerOff();
116 void run();
117 void pause();
118 void halt();
119 void warpOn();
120 void warpOff();
121 void trackOn();
122 void trackOff();
123 void focus();
124 void unfocus();
125
126 void powerOnOff(bool value) { value ? powerOn() : powerOff(); }
127 void warpOnOff(bool value) { value ? warpOn() : warpOff(); }
128 void trackOnOff(bool value) { value ? trackOn() : trackOff(); }
129
130private:
131
132 virtual void _isReady() const throws { }
133 virtual void _powerOn() { }
134 virtual void _powerOff() { }
135 virtual void _run() { }
136 virtual void _pause() { }
137 virtual void _halt() { }
138 virtual void _warpOn() { }
139 virtual void _warpOff() { }
140 virtual void _trackOn() { }
141 virtual void _trackOff() { }
142 virtual void _focus() { }
143 virtual void _unfocus() { }
144
145
146 //
147 // Misc
148 //
149
150public:
151
152 bool isEmulatorThread() const;
153
154 // Experimental
155 void exportConfig(std::ostream& ss, bool diff = false) const;
156 void exportDiff(std::ostream& ss) const { exportConfig(ss, true); }
157};
158
159/* This class exposes references to all subcomponents of the C64. It's purpose
160 * is the simply access to components. E.g., VICII can be accessed via vicii
161 * instead of c64.vicii. */
162class References {
163
164protected:
165
166 class AudioPort &audioPort;
167 class C64 &c64;
168 class CIA1 &cia1;
169 class CIA2 &cia2;
170 class ControlPort &port1;
171 class ControlPort &port2;
172 class CPU &cpu;
173 class Datasette &datasette;
174 class Debugger &debugger;
175 class Drive &drive8;
176 class Drive &drive9;
177 class ExpansionPort &expansionPort;
178 class Host &host;
179 class SerialPort &serialPort;
180 class Keyboard &keyboard;
181 class C64Memory &mem;
182 class Monitor &monitor;
183 class MsgQueue &msgQueue;
184 class ParCable &parCable;
185 class PowerPort &powerSupply;
186 class Recorder &recorder;
187 class RegressionTester &regressionTester;
188 class RetroShell &retroShell;
189 class SIDBridge &sidBridge;
190 class SID& sid0;
191 class SID& sid1;
192 class SID& sid2;
193 class SID& sid3;
194 class VICII &vic;
195 class VideoPort &videoPort;
196
197 Drive *drive[2] = { &drive8, &drive9 };
198
199public:
200
201 References(C64& ref);
202};
203
204}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16