openMSX
MSXMotherBoard.hh
Go to the documentation of this file.
1#ifndef MSXMOTHERBOARD_HH
2#define MSXMOTHERBOARD_HH
3
4#include "EmuTime.hh"
6#include "BooleanSetting.hh"
7#include "hash_map.hh"
8#include "serialize_meta.hh"
9#include "xxhash.hh"
10#include "openmsx.hh"
11#include "RecordedCommand.hh"
12#include <array>
13#include <cassert>
14#include <memory>
15#include <string_view>
16#include <vector>
17
18namespace openmsx {
19
20class AddRemoveUpdate;
21class CartridgeSlotManager;
22class CassettePortInterface;
23class CliComm;
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:
67
72 virtual void getMediaInfo(TclObject& result) = 0;
73
74protected:
75 MediaInfoProvider() = default;
76 ~MediaInfoProvider() = default;
77};
78
79
80class MSXMotherBoard final
81{
82public:
85
86 explicit MSXMotherBoard(Reactor& reactor);
88
89 [[nodiscard]] std::string_view getMachineID() const { return machineID; }
90 [[nodiscard]] std::string_view getMachineName() const { return machineName; }
91
96 [[nodiscard]] bool execute();
97
100 void fastForward(EmuTime::param time, bool fast);
101
103 void exitCPULoopAsync();
104 void exitCPULoopSync();
105
109 void pause();
110 void unpause();
111
112 void powerUp();
113
114 void doReset();
115 void activate(bool active);
116 [[nodiscard]] bool isActive() const { return active; }
117 [[nodiscard]] bool isFastForwarding() const { return fastForwarding; }
118
119 [[nodiscard]] byte readIRQVector();
120
121 [[nodiscard]] const HardwareConfig* getMachineConfig() const { return machineConfig; }
122 [[nodiscard]] HardwareConfig* getMachineConfig() { return machineConfig; }
123 void setMachineConfig(HardwareConfig* machineConfig);
124 [[nodiscard]] std::string_view getMachineType() const;
125 [[nodiscard]] bool isTurboR() const;
126 [[nodiscard]] bool hasToshibaEngine() const;
127
128 std::string loadMachine(const std::string& machine);
129
130 using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
131 [[nodiscard]] const Extensions& getExtensions() const { return extensions; }
132 [[nodiscard]] HardwareConfig* findExtension(std::string_view extensionName);
133 std::string loadExtension(std::string_view extensionName, std::string_view slotName);
134 std::string insertExtension(std::string_view name,
135 std::unique_ptr<HardwareConfig> extension);
136 void removeExtension(const HardwareConfig& extension);
137
138 // The following classes are unique per MSX machine
139 [[nodiscard]] CliComm& getMSXCliComm();
140 [[nodiscard]] MSXCommandController& getMSXCommandController() { return *msxCommandController; }
141 [[nodiscard]] Scheduler& getScheduler() { return *scheduler; }
142 [[nodiscard]] MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
143 [[nodiscard]] StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
144 [[nodiscard]] CartridgeSlotManager& getSlotManager() { return *slotManager; }
145 [[nodiscard]] RealTime& getRealTime() { return *realTime; }
146 [[nodiscard]] Debugger& getDebugger() { return *debugger; }
147 [[nodiscard]] MSXMixer& getMSXMixer() { return *msxMixer; }
149 [[nodiscard]] MSXCPU& getCPU();
150 [[nodiscard]] MSXCPUInterface& getCPUInterface();
151 [[nodiscard]] PanasonicMemory& getPanasonicMemory();
152 [[nodiscard]] MSXDeviceSwitch& getDeviceSwitch();
153 [[nodiscard]] CassettePortInterface& getCassettePort();
154 [[nodiscard]] JoystickPortIf& getJoystickPort(unsigned port);
155 [[nodiscard]] RenShaTurbo& getRenShaTurbo();
156 [[nodiscard]] LedStatus& getLedStatus();
157 [[nodiscard]] ReverseManager& getReverseManager() { return *reverseManager; }
158 [[nodiscard]] Reactor& getReactor() { return reactor; }
159 [[nodiscard]] VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
160 [[nodiscard]] BooleanSetting& suppressMessages() { return suppressMessagesSetting; }
161
162 // convenience methods
164 [[nodiscard]] InfoCommand& getMachineInfoCommand();
165
168 [[nodiscard]] EmuTime::param getCurrentTime();
169
172 void addDevice(MSXDevice& device);
173 void removeDevice(MSXDevice& device);
174
181 [[nodiscard]] MSXDevice* findDevice(std::string_view name);
182
191 template<typename T, typename ... Args>
192 [[nodiscard]] std::shared_ptr<T> getSharedStuff(std::string_view name, Args&& ...args)
193 {
194 auto& weak = sharedStuffMap[name];
195 auto shared = std::static_pointer_cast<T>(weak.lock());
196 if (shared) return shared;
197
198 shared = std::make_shared<T>(std::forward<Args>(args)...);
199 weak = shared;
200 return shared;
201 }
202
206 [[nodiscard]] MSXMapperIO& createMapperIO();
207 [[nodiscard]] MSXMapperIO& getMapperIO() const
208 {
209 assert(mapperIOCounter);
210 return *mapperIO;
211 }
212 void destroyMapperIO();
213
221 [[nodiscard]] std::string getUserName(const std::string& hwName);
222 void freeUserName(const std::string& hwName, const std::string& userName);
223
227 void registerMediaInfo(std::string_view name, MediaInfoProvider& provider);
229
230 template<typename Archive>
231 void serialize(Archive& ar, unsigned version);
232
233private:
234 void powerDown();
235 void deleteMachine();
236
237private:
238 Reactor& reactor;
239 std::string machineID;
240 std::string machineName;
241
242 std::vector<MSXDevice*> availableDevices; // no ownership, no order
243
246
247 std::unique_ptr<MSXMapperIO> mapperIO;
248 unsigned mapperIOCounter = 0;
249
250 // These two should normally be the same, only during savestate loading
251 // machineConfig will already be filled in, but machineConfig2 not yet.
252 // This is important when an exception happens during loading of
253 // machineConfig2 (otherwise machineConfig2 gets deleted twice).
254 // See also HardwareConfig::serialize() and setMachineConfig()
255 std::unique_ptr<HardwareConfig> machineConfig2;
256 HardwareConfig* machineConfig = nullptr;
257
258 Extensions extensions; // order matters: later extension might depend on earlier ones
259
260 // order of unique_ptr's is important!
261 std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
262 std::unique_ptr<MSXCliComm> msxCliComm;
263 std::unique_ptr<MSXEventDistributor> msxEventDistributor;
264 std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
265 std::unique_ptr<MSXCommandController> msxCommandController;
266 std::unique_ptr<Scheduler> scheduler;
267 std::unique_ptr<EventDelay> eventDelay;
268 std::unique_ptr<RealTime> realTime;
269 std::unique_ptr<Debugger> debugger;
270 std::unique_ptr<MSXMixer> msxMixer;
271 // machineMediaInfo must be BEFORE PluggingController!
272 std::unique_ptr<MachineMediaInfo> machineMediaInfo;
273 std::unique_ptr<PluggingController> pluggingController;
274 std::unique_ptr<MSXCPU> msxCpu;
275 std::unique_ptr<MSXCPUInterface> msxCpuInterface;
276 std::unique_ptr<PanasonicMemory> panasonicMemory;
277 std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
278 std::unique_ptr<CassettePortInterface> cassettePort;
279 std::array<std::unique_ptr<JoystickPortIf>, 2> joystickPort;
280 std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
281 std::unique_ptr<RenShaTurbo> renShaTurbo;
282 std::unique_ptr<LedStatus> ledStatus;
283 VideoSourceSetting videoSourceSetting;
284 BooleanSetting suppressMessagesSetting;
285
286 std::unique_ptr<CartridgeSlotManager> slotManager;
287 std::unique_ptr<ReverseManager> reverseManager;
288 std::unique_ptr<ResetCmd> resetCommand;
289 std::unique_ptr<LoadMachineCmd> loadMachineCommand;
290 std::unique_ptr<ListExtCmd> listExtCommand;
291 std::unique_ptr<ExtCmd> extCommand;
292 std::unique_ptr<RemoveExtCmd> removeExtCommand;
293 std::unique_ptr<MachineNameInfo> machineNameInfo;
294 std::unique_ptr<MachineTypeInfo> machineTypeInfo;
295 std::unique_ptr<MachineExtensionInfo> machineExtensionInfo;
296 std::unique_ptr<DeviceInfo> deviceInfo;
297 friend class DeviceInfo;
298
299 std::unique_ptr<FastForwardHelper> fastForwardHelper;
300
301 std::unique_ptr<SettingObserver> settingObserver;
302 friend class SettingObserver;
303 BooleanSetting& powerSetting;
304
305 bool powered = false;
306 bool active = false;
307 bool fastForwarding = false;
308};
310
311class ExtCmd final : public RecordedCommand
312{
313public:
314 ExtCmd(MSXMotherBoard& motherBoard, std::string commandName);
315 void execute(std::span<const TclObject> tokens, TclObject& result,
316 EmuTime::param time) override;
317 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
318 void tabCompletion(std::vector<std::string>& tokens) const override;
319private:
320 MSXMotherBoard& motherBoard;
321 std::string commandName;
322};
323
324} // namespace openmsx
325
326#endif
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
ExtCmd(MSXMotherBoard &motherBoard, std::string commandName)
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.
const HardwareConfig * getMachineConfig() const
MSXCPUInterface & getCPUInterface()
std::string getUserName(const std::string &hwName)
Keep track of which 'usernames' are in use.
MSXEventDistributor & getMSXEventDistributor()
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
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()
MSXDeviceSwitch & getDeviceSwitch()
void serialize(Archive &ar, unsigned version)
CartridgeSlotManager & getSlotManager()
void removeDevice(MSXDevice &device)
std::string_view getMachineID() const
MSXMotherBoard & operator=(const MSXMotherBoard &)=delete
std::string loadExtension(std::string_view extensionName, std::string_view slotName)
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
Central administration of Connectors and Pluggables.
Contains the main loop of openMSX.
Definition: Reactor.hh:68
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.
Definition: RenShaTurbo.hh:21
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)