openMSX
MSXMotherBoard.hh
Go to the documentation of this file.
1#ifndef MSXMOTHERBOARD_HH
2#define MSXMOTHERBOARD_HH
3
4#include "BooleanSetting.hh"
5#include "EmuTime.hh"
6#include "RecordedCommand.hh"
8#include "hash_map.hh"
9#include "openmsx.hh"
10#include "serialize_meta.hh"
11#include "xxhash.hh"
12
13#include <array>
14#include <cassert>
15#include <memory>
16#include <string_view>
17#include <vector>
18
19namespace openmsx {
20
21class AddRemoveUpdate;
22class CartridgeSlotManager;
23class CassettePortInterface;
24class CommandController;
25class Debugger;
26class DeviceInfo;
27class EventDelay;
28class ExtCmd;
29class FastForwardHelper;
30class HardwareConfig;
31class InfoCommand;
32class JoyPortDebuggable;
33class JoystickPortIf;
34class LedStatus;
35class ListExtCmd;
36class LoadMachineCmd;
37class MachineExtensionInfo;
38class MachineMediaInfo;
39class MachineNameInfo;
40class MachineTypeInfo;
41class MSXCliComm;
42class MSXCommandController;
43class MSXCPU;
44class MSXCPUInterface;
45class MSXDevice;
46class MSXDeviceSwitch;
47class MSXEventDistributor;
48class MSXMapperIO;
49class MSXMixer;
50class PanasonicMemory;
51class PluggingController;
52class Reactor;
53class RealTime;
54class RemoveExtCmd;
55class RenShaTurbo;
56class ResetCmd;
57class ReverseManager;
58class SettingObserver;
59class Scheduler;
60class StateChangeDistributor;
61
63{
64public:
69
74 virtual void getMediaInfo(TclObject& result) = 0;
75
76protected:
77 MediaInfoProvider() = default;
78 ~MediaInfoProvider() = default;
79};
80
81
82class MSXMotherBoard final
83{
84public:
89
90 explicit MSXMotherBoard(Reactor& reactor);
92
93 [[nodiscard]] std::string_view getMachineID() const { return machineID; }
94 [[nodiscard]] std::string_view getMachineName() const { return machineName; }
95
100 [[nodiscard]] bool execute();
101
104 void fastForward(EmuTime::param time, bool fast);
105
107 void exitCPULoopAsync();
108 void exitCPULoopSync();
109
113 void pause();
114 void unpause();
115
116 void powerUp();
117 [[nodiscard]] bool isPowered() const { return powered; }
118
119 void doReset();
120 void activate(bool active);
121 [[nodiscard]] bool isActive() const { return active; }
122 [[nodiscard]] bool isFastForwarding() const { return fastForwarding; }
123
124 [[nodiscard]] byte readIRQVector() const;
125
126 [[nodiscard]] const HardwareConfig* getMachineConfig() const { return machineConfig; }
127 [[nodiscard]] HardwareConfig* getMachineConfig() { return machineConfig; }
128 void setMachineConfig(HardwareConfig* machineConfig);
129 [[nodiscard]] std::string_view getMachineType() const;
130 [[nodiscard]] bool isTurboR() const;
131 [[nodiscard]] bool hasToshibaEngine() const;
132
133 std::string loadMachine(const std::string& machine);
134
135 using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
136 [[nodiscard]] const Extensions& getExtensions() const { return extensions; }
137 [[nodiscard]] HardwareConfig* findExtension(std::string_view extensionName);
138 std::unique_ptr<HardwareConfig> loadExtension(std::string_view extensionName, std::string_view slotName);
139 std::string insertExtension(std::string_view name,
140 std::unique_ptr<HardwareConfig> extension);
141 void removeExtension(const HardwareConfig& extension);
142
143 // The following classes are unique per MSX machine
144 [[nodiscard]] MSXCliComm& getMSXCliComm();
145 [[nodiscard]] MSXCommandController& getMSXCommandController() { return *msxCommandController; }
146 [[nodiscard]] Scheduler& getScheduler() { return *scheduler; }
147 [[nodiscard]] MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
148 [[nodiscard]] StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
149 [[nodiscard]] CartridgeSlotManager& getSlotManager() { return *slotManager; }
150 [[nodiscard]] RealTime& getRealTime() { return *realTime; }
151 [[nodiscard]] Debugger& getDebugger() { return *debugger; }
152 [[nodiscard]] MSXMixer& getMSXMixer() { return *msxMixer; }
154 [[nodiscard]] MSXCPU& getCPU();
155 [[nodiscard]] MSXCPUInterface& getCPUInterface();
156 [[nodiscard]] PanasonicMemory& getPanasonicMemory();
157 [[nodiscard]] MSXDeviceSwitch& getDeviceSwitch();
158 [[nodiscard]] CassettePortInterface& getCassettePort();
159 [[nodiscard]] JoystickPortIf& getJoystickPort(unsigned port);
160 [[nodiscard]] RenShaTurbo& getRenShaTurbo();
161 [[nodiscard]] LedStatus& getLedStatus();
162 [[nodiscard]] ReverseManager& getReverseManager() { return *reverseManager; }
163 [[nodiscard]] Reactor& getReactor() { return reactor; }
164 [[nodiscard]] VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
165 [[nodiscard]] BooleanSetting& suppressMessages() { return suppressMessagesSetting; }
166
167 // convenience methods
169 [[nodiscard]] InfoCommand& getMachineInfoCommand();
170
173 [[nodiscard]] EmuTime::param getCurrentTime() const;
174
177 void addDevice(MSXDevice& device);
178 void removeDevice(MSXDevice& device);
179
186 [[nodiscard]] MSXDevice* findDevice(std::string_view name);
187
196 template<typename T, typename ... Args>
197 [[nodiscard]] std::shared_ptr<T> getSharedStuff(std::string_view name, Args&& ...args)
198 {
199 auto& weak = sharedStuffMap[name];
200 auto shared = std::static_pointer_cast<T>(weak.lock());
201 if (shared) return shared;
202
203 shared = std::make_shared<T>(std::forward<Args>(args)...);
204 weak = shared;
205 return shared;
206 }
207
211 [[nodiscard]] MSXMapperIO& createMapperIO();
212 [[nodiscard]] MSXMapperIO& getMapperIO() const
213 {
214 assert(mapperIOCounter);
215 return *mapperIO;
216 }
217 void destroyMapperIO();
218
226 [[nodiscard]] std::string getUserName(const std::string& hwName);
227 void freeUserName(const std::string& hwName, const std::string& userName);
228
232 void registerMediaInfo(std::string_view name, MediaInfoProvider& provider);
234
235 template<typename Archive>
236 void serialize(Archive& ar, unsigned version);
237
238private:
239 void powerDown();
240 void deleteMachine();
241
242private:
243 Reactor& reactor;
244 std::string machineID;
245 std::string machineName;
246
247 std::vector<MSXDevice*> availableDevices; // no ownership, no order
248
251
252 std::unique_ptr<MSXMapperIO> mapperIO;
253 unsigned mapperIOCounter = 0;
254
255 // These two should normally be the same, only during savestate loading
256 // machineConfig will already be filled in, but machineConfig2 not yet.
257 // This is important when an exception happens during loading of
258 // machineConfig2 (otherwise machineConfig2 gets deleted twice).
259 // See also HardwareConfig::serialize() and setMachineConfig()
260 std::unique_ptr<HardwareConfig> machineConfig2;
261 HardwareConfig* machineConfig = nullptr;
262
263 Extensions extensions; // order matters: later extension might depend on earlier ones
264
265 // order of unique_ptr's is important!
266 std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
267 std::unique_ptr<MSXCliComm> msxCliComm;
268 std::unique_ptr<MSXEventDistributor> msxEventDistributor;
269 std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
270 std::unique_ptr<MSXCommandController> msxCommandController;
271 std::unique_ptr<Scheduler> scheduler;
272 std::unique_ptr<EventDelay> eventDelay;
273 std::unique_ptr<RealTime> realTime;
274 std::unique_ptr<Debugger> debugger;
275 std::unique_ptr<MSXMixer> msxMixer;
276 // machineMediaInfo must be BEFORE PluggingController!
277 std::unique_ptr<MachineMediaInfo> machineMediaInfo;
278 std::unique_ptr<PluggingController> pluggingController;
279 std::unique_ptr<MSXCPU> msxCpu;
280 std::unique_ptr<MSXCPUInterface> msxCpuInterface;
281 std::unique_ptr<PanasonicMemory> panasonicMemory;
282 std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
283 std::unique_ptr<CassettePortInterface> cassettePort;
284 std::array<std::unique_ptr<JoystickPortIf>, 2> joystickPort;
285 std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
286 std::unique_ptr<RenShaTurbo> renShaTurbo;
287 std::unique_ptr<LedStatus> ledStatus;
288 VideoSourceSetting videoSourceSetting;
289 BooleanSetting suppressMessagesSetting;
290
291 std::unique_ptr<CartridgeSlotManager> slotManager;
292 std::unique_ptr<ReverseManager> reverseManager;
293 std::unique_ptr<ResetCmd> resetCommand;
294 std::unique_ptr<LoadMachineCmd> loadMachineCommand;
295 std::unique_ptr<ListExtCmd> listExtCommand;
296 std::unique_ptr<ExtCmd> extCommand;
297 std::unique_ptr<RemoveExtCmd> removeExtCommand;
298 std::unique_ptr<MachineNameInfo> machineNameInfo;
299 std::unique_ptr<MachineTypeInfo> machineTypeInfo;
300 std::unique_ptr<MachineExtensionInfo> machineExtensionInfo;
301 std::unique_ptr<DeviceInfo> deviceInfo;
302 friend class DeviceInfo;
303
304 std::unique_ptr<FastForwardHelper> fastForwardHelper;
305
306 std::unique_ptr<SettingObserver> settingObserver;
307 friend class SettingObserver;
308 BooleanSetting& powerSetting;
309
310 bool powered = false;
311 bool active = false;
312 bool fastForwarding = false;
313};
315
316class ExtCmd final : public RecordedCommand
317{
318public:
319 ExtCmd(MSXMotherBoard& motherBoard, std::string commandName);
320 void execute(std::span<const TclObject> tokens, TclObject& result,
321 EmuTime::param time) override;
322 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
323 void tabCompletion(std::vector<std::string>& tokens) const override;
324private:
325 MSXMotherBoard& motherBoard;
326 std::string commandName;
327};
328
329} // namespace openmsx
330
331#endif
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
void execute(std::span< const TclObject > tokens, TclObject &result, EmuTime::param time) override
This is like the execute() method of the Command class, it only has an extra time parameter.
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
HardwareConfig * findExtension(std::string_view extensionName)
PluggingController & getPluggingController()
VideoSourceSetting & getVideoSource()
void activate(bool active)
void setMachineConfig(HardwareConfig *machineConfig)
std::shared_ptr< T > getSharedStuff(std::string_view name, Args &&...args)
Some MSX device parts are shared between several MSX devices (e.g.
RenShaTurbo & getRenShaTurbo()
void freeUserName(const std::string &hwName, const std::string &userName)
bool execute()
Run emulation.
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
const HardwareConfig * getMachineConfig() const
MSXMotherBoard(MSXMotherBoard &&)=delete
MSXCPUInterface & getCPUInterface()
MSXEventDistributor & getMSXEventDistributor()
std::unique_ptr< HardwareConfig > loadExtension(std::string_view extensionName, std::string_view slotName)
std::string loadMachine(const std::string &machine)
std::string_view getMachineName() const
StateChangeDistributor & getStateChangeDistributor()
HardwareConfig * getMachineConfig()
void registerMediaInfo(std::string_view name, MediaInfoProvider &provider)
Register and unregister providers of media info, for the media info topic.
std::vector< std::unique_ptr< HardwareConfig > > Extensions
MSXDevice * findDevice(std::string_view name)
Find a MSXDevice by name.
CommandController & getCommandController()
void pause()
Pause MSX machine.
std::string insertExtension(std::string_view name, std::unique_ptr< HardwareConfig > extension)
void fastForward(EmuTime::param time, bool fast)
Run emulation until a certain time in fast forward mode.
void exitCPULoopAsync()
See CPU::exitCPULoopAsync().
MSXMapperIO & getMapperIO() const
MSXMotherBoard(const MSXMotherBoard &)=delete
void unregisterMediaInfo(MediaInfoProvider &provider)
BooleanSetting & suppressMessages()
MSXMotherBoard & operator=(MSXMotherBoard &&)=delete
MSXDeviceSwitch & getDeviceSwitch()
void serialize(Archive &ar, unsigned version)
CartridgeSlotManager & getSlotManager()
void removeDevice(MSXDevice &device)
std::string_view getMachineID() const
MSXMotherBoard & operator=(const MSXMotherBoard &)=delete
void removeExtension(const HardwareConfig &extension)
ReverseManager & getReverseManager()
JoystickPortIf & getJoystickPort(unsigned port)
std::string_view getMachineType() const
MSXCommandController & getMSXCommandController()
const Extensions & getExtensions() const
CassettePortInterface & getCassettePort()
void addDevice(MSXDevice &device)
All MSXDevices should be registered by the MotherBoard.
PanasonicMemory & getPanasonicMemory()
MSXMapperIO & createMapperIO()
All memory mappers in one MSX machine share the same four (logical) memory mapper registers.
InfoCommand & getMachineInfoCommand()
MediaInfoProvider(const MediaInfoProvider &)=delete
virtual void getMediaInfo(TclObject &result)=0
This method gets called when information is required on the media inserted in the media slot of the p...
MediaInfoProvider & operator=(const MediaInfoProvider &)=delete
MediaInfoProvider & operator=(MediaInfoProvider &&)=delete
MediaInfoProvider(MediaInfoProvider &&)=delete
Central administration of Connectors and Pluggables.
Contains the main loop of openMSX.
Definition Reactor.hh:74
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Ren-Sha Turbo is the autofire in several MSX 2+ models and in the MSX turbo R.
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)