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 "hash_map.hh"
7#include "serialize_meta.hh"
8#include "xxhash.hh"
9#include "openmsx.hh"
10#include "RecordedCommand.hh"
11#include <cassert>
12#include <memory>
13#include <string_view>
14#include <vector>
15
16namespace openmsx {
17
18class AddRemoveUpdate;
19class BooleanSetting;
20class CartridgeSlotManager;
21class CassettePortInterface;
22class CliComm;
23class CommandController;
24class Debugger;
25class DeviceInfo;
26class EventDelay;
27class ExtCmd;
28class FastForwardHelper;
29class HardwareConfig;
30class InfoCommand;
31class JoyPortDebuggable;
32class JoystickPortIf;
33class LedStatus;
34class ListExtCmd;
35class LoadMachineCmd;
36class MachineExtensionInfo;
37class MachineMediaInfo;
38class MachineNameInfo;
39class MachineTypeInfo;
40class MSXCliComm;
41class MSXCommandController;
42class MSXCPU;
43class MSXCPUInterface;
44class MSXDevice;
45class MSXDeviceSwitch;
46class MSXEventDistributor;
47class MSXMapperIO;
48class MSXMixer;
49class PanasonicMemory;
50class PluggingController;
51class Reactor;
52class RealTime;
53class RemoveExtCmd;
54class RenShaTurbo;
55class ResetCmd;
56class ReverseManager;
57class SettingObserver;
58class Scheduler;
59class StateChangeDistributor;
60
62{
63public:
66
71 virtual void getMediaInfo(TclObject& result) = 0;
72
73protected:
74 MediaInfoProvider() = default;
75 ~MediaInfoProvider() = default;
76};
77
78
79class MSXMotherBoard final
80{
81public:
84
85 explicit MSXMotherBoard(Reactor& reactor);
87
88 [[nodiscard]] std::string_view getMachineID() const { return machineID; }
89 [[nodiscard]] std::string_view getMachineName() const { return machineName; }
90
95 [[nodiscard]] bool execute();
96
99 void fastForward(EmuTime::param time, bool fast);
100
102 void exitCPULoopAsync();
103 void exitCPULoopSync();
104
108 void pause();
109 void unpause();
110
111 void powerUp();
112
113 void doReset();
114 void activate(bool active);
115 [[nodiscard]] bool isActive() const { return active; }
116 [[nodiscard]] bool isFastForwarding() const { return fastForwarding; }
117
118 [[nodiscard]] byte readIRQVector();
119
120 [[nodiscard]] const HardwareConfig* getMachineConfig() const { return machineConfig; }
121 [[nodiscard]] HardwareConfig* getMachineConfig() { return machineConfig; }
122 void setMachineConfig(HardwareConfig* machineConfig);
123 [[nodiscard]] std::string_view getMachineType() const;
124 [[nodiscard]] bool isTurboR() const;
125 [[nodiscard]] bool hasToshibaEngine() const;
126
127 std::string loadMachine(const std::string& machine);
128
129 using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
130 [[nodiscard]] const Extensions& getExtensions() const { return extensions; }
131 [[nodiscard]] HardwareConfig* findExtension(std::string_view extensionName);
132 std::string loadExtension(std::string_view extensionName, std::string_view slotname);
133 std::string insertExtension(std::string_view name,
134 std::unique_ptr<HardwareConfig> extension);
135 void removeExtension(const HardwareConfig& extension);
136
137 // The following classes are unique per MSX machine
138 [[nodiscard]] CliComm& getMSXCliComm();
139 [[nodiscard]] MSXCommandController& getMSXCommandController() { return *msxCommandController; }
140 [[nodiscard]] Scheduler& getScheduler() { return *scheduler; }
141 [[nodiscard]] MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
142 [[nodiscard]] StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
143 [[nodiscard]] CartridgeSlotManager& getSlotManager() { return *slotManager; }
144 [[nodiscard]] RealTime& getRealTime() { return *realTime; }
145 [[nodiscard]] Debugger& getDebugger() { return *debugger; }
146 [[nodiscard]] MSXMixer& getMSXMixer() { return *msxMixer; }
148 [[nodiscard]] MSXCPU& getCPU();
149 [[nodiscard]] MSXCPUInterface& getCPUInterface();
150 [[nodiscard]] PanasonicMemory& getPanasonicMemory();
151 [[nodiscard]] MSXDeviceSwitch& getDeviceSwitch();
152 [[nodiscard]] CassettePortInterface& getCassettePort();
153 [[nodiscard]] JoystickPortIf& getJoystickPort(unsigned port);
154 [[nodiscard]] RenShaTurbo& getRenShaTurbo();
155 [[nodiscard]] LedStatus& getLedStatus();
156 [[nodiscard]] ReverseManager& getReverseManager() { return *reverseManager; }
157 [[nodiscard]] Reactor& getReactor() { return reactor; }
158 [[nodiscard]] VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
159
160 // convenience methods
162 [[nodiscard]] InfoCommand& getMachineInfoCommand();
163
166 [[nodiscard]] EmuTime::param getCurrentTime();
167
170 void addDevice(MSXDevice& device);
171 void removeDevice(MSXDevice& device);
172
179 [[nodiscard]] MSXDevice* findDevice(std::string_view name);
180
189 template<typename T, typename ... Args>
190 [[nodiscard]] std::shared_ptr<T> getSharedStuff(std::string_view name, Args&& ...args)
191 {
192 auto& weak = sharedStuffMap[name];
193 auto shared = std::static_pointer_cast<T>(weak.lock());
194 if (shared) return shared;
195
196 shared = std::make_shared<T>(std::forward<Args>(args)...);
197 weak = shared;
198 return shared;
199 }
200
204 [[nodiscard]] MSXMapperIO& createMapperIO();
205 [[nodiscard]] MSXMapperIO& getMapperIO() const
206 {
207 assert(mapperIOCounter);
208 return *mapperIO;
209 }
210 void destroyMapperIO();
211
219 [[nodiscard]] std::string getUserName(const std::string& hwName);
220 void freeUserName(const std::string& hwName, const std::string& userName);
221
225 void registerMediaInfoProvider(const std::string& slot, MediaInfoProvider& infoProvider);
226 void unregisterMediaInfoProvider(const std::string& slot);
227
228 template<typename Archive>
229 void serialize(Archive& ar, unsigned version);
230
231private:
232 void powerDown();
233 void deleteMachine();
234
235private:
236 Reactor& reactor;
237 std::string machineID;
238 std::string machineName;
239
240 std::vector<MSXDevice*> availableDevices; // no ownership, no order
241
244
245 std::unique_ptr<MSXMapperIO> mapperIO;
246 unsigned mapperIOCounter;
247
248 // These two should normally be the same, only during savestate loading
249 // machineConfig will already be filled in, but machineConfig2 not yet.
250 // This is important when an exception happens during loading of
251 // machineConfig2 (otherwise machineConfig2 gets deleted twice).
252 // See also HardwareConfig::serialize() and setMachineConfig()
253 std::unique_ptr<HardwareConfig> machineConfig2;
254 HardwareConfig* machineConfig;
255
256 Extensions extensions; // order matters: later extension might depend on earlier ones
257
258 // order of unique_ptr's is important!
259 std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
260 std::unique_ptr<MSXCliComm> msxCliComm;
261 std::unique_ptr<MSXEventDistributor> msxEventDistributor;
262 std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
263 std::unique_ptr<MSXCommandController> msxCommandController;
264 std::unique_ptr<Scheduler> scheduler;
265 std::unique_ptr<EventDelay> eventDelay;
266 std::unique_ptr<RealTime> realTime;
267 std::unique_ptr<Debugger> debugger;
268 std::unique_ptr<MSXMixer> msxMixer;
269 // machineMediaInfo must be BEFORE PluggingController!
270 std::unique_ptr<MachineMediaInfo> machineMediaInfo;
271 std::unique_ptr<PluggingController> pluggingController;
272 std::unique_ptr<MSXCPU> msxCpu;
273 std::unique_ptr<MSXCPUInterface> msxCpuInterface;
274 std::unique_ptr<PanasonicMemory> panasonicMemory;
275 std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
276 std::unique_ptr<CassettePortInterface> cassettePort;
277 std::unique_ptr<JoystickPortIf> joystickPort[2];
278 std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
279 std::unique_ptr<RenShaTurbo> renShaTurbo;
280 std::unique_ptr<LedStatus> ledStatus;
281 VideoSourceSetting videoSourceSetting;
282
283 std::unique_ptr<CartridgeSlotManager> slotManager;
284 std::unique_ptr<ReverseManager> reverseManager;
285 std::unique_ptr<ResetCmd> resetCommand;
286 std::unique_ptr<LoadMachineCmd> loadMachineCommand;
287 std::unique_ptr<ListExtCmd> listExtCommand;
288 std::unique_ptr<ExtCmd> extCommand;
289 std::unique_ptr<RemoveExtCmd> removeExtCommand;
290 std::unique_ptr<MachineNameInfo> machineNameInfo;
291 std::unique_ptr<MachineTypeInfo> machineTypeInfo;
292 std::unique_ptr<MachineExtensionInfo> machineExtensionInfo;
293 std::unique_ptr<DeviceInfo> deviceInfo;
294 friend class DeviceInfo;
295
296 std::unique_ptr<FastForwardHelper> fastForwardHelper;
297
298 std::unique_ptr<SettingObserver> settingObserver;
299 friend class SettingObserver;
300 BooleanSetting& powerSetting;
301
302 bool powered;
303 bool active;
304 bool fastForwarding;
305};
307
308class ExtCmd final : public RecordedCommand
309{
310public:
311 ExtCmd(MSXMotherBoard& motherBoard, std::string commandName);
312 void execute(std::span<const TclObject> tokens, TclObject& result,
313 EmuTime::param time) override;
314 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
315 void tabCompletion(std::vector<std::string>& tokens) const override;
316private:
317 MSXMotherBoard& motherBoard;
318 std::string commandName;
319};
320
321} // namespace openmsx
322
323#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:33
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()
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
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 unregisterMediaInfoProvider(const std::string &slot)
void removeExtension(const HardwareConfig &extension)
ReverseManager & getReverseManager()
JoystickPortIf & getJoystickPort(unsigned port)
std::string loadExtension(std::string_view extensionName, std::string_view slotname)
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.
void registerMediaInfoProvider(const std::string &slot, MediaInfoProvider &infoProvider)
Register and unregister providers of media info, for the media info topic.
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)