openMSX
MSXMotherBoard.hh
Go to the documentation of this file.
1 #ifndef MSXMOTHERBOARD_HH
2 #define MSXMOTHERBOARD_HH
3 
4 #include "EmuTime.hh"
5 #include "VideoSourceSetting.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 
16 namespace openmsx {
17 
18 class AddRemoveUpdate;
19 class BooleanSetting;
20 class CartridgeSlotManager;
21 class CassettePortInterface;
22 class CliComm;
23 class CommandController;
24 class Debugger;
25 class DeviceInfo;
26 class EventDelay;
27 class ExtCmd;
28 class FastForwardHelper;
29 class HardwareConfig;
30 class InfoCommand;
31 class JoyPortDebuggable;
32 class JoystickPortIf;
33 class LedStatus;
34 class ListExtCmd;
35 class LoadMachineCmd;
36 class MachineExtensionInfo;
37 class MachineNameInfo;
38 class MachineTypeInfo;
39 class MSXCliComm;
40 class MSXCommandController;
41 class MSXCPU;
42 class MSXCPUInterface;
43 class MSXDevice;
44 class MSXDeviceSwitch;
45 class MSXEventDistributor;
46 class MSXMapperIO;
47 class MSXMixer;
48 class PanasonicMemory;
49 class PluggingController;
50 class Reactor;
51 class RealTime;
52 class RemoveExtCmd;
53 class RenShaTurbo;
54 class ResetCmd;
55 class ReverseManager;
56 class SettingObserver;
57 class Scheduler;
58 class StateChangeDistributor;
59 
60 class MSXMotherBoard final
61 {
62 public:
63  MSXMotherBoard(const MSXMotherBoard&) = delete;
65 
66  explicit MSXMotherBoard(Reactor& reactor);
68 
69  [[nodiscard]] std::string_view getMachineID() const { return machineID; }
70  [[nodiscard]] std::string_view getMachineName() const { return machineName; }
71 
76  [[nodiscard]] bool execute();
77 
80  void fastForward(EmuTime::param time, bool fast);
81 
83  void exitCPULoopAsync();
84  void exitCPULoopSync();
85 
89  void pause();
90  void unpause();
91 
92  void powerUp();
93 
94  void doReset();
95  void activate(bool active);
96  [[nodiscard]] bool isActive() const { return active; }
97  [[nodiscard]] bool isFastForwarding() const { return fastForwarding; }
98 
99  [[nodiscard]] byte readIRQVector();
100 
101  [[nodiscard]] const HardwareConfig* getMachineConfig() const { return machineConfig; }
102  void setMachineConfig(HardwareConfig* machineConfig);
103  [[nodiscard]] std::string getMachineType() const;
104  [[nodiscard]] bool isTurboR() const;
105 
106  std::string loadMachine(const std::string& machine);
107 
108  using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
109  [[nodiscard]] const Extensions& getExtensions() const { return extensions; }
110  [[nodiscard]] HardwareConfig* findExtension(std::string_view extensionName);
111  std::string loadExtension(std::string_view extensionName, std::string_view slotname);
112  std::string insertExtension(std::string_view name,
113  std::unique_ptr<HardwareConfig> extension);
114  void removeExtension(const HardwareConfig& extension);
115 
116  // The following classes are unique per MSX machine
117  [[nodiscard]] CliComm& getMSXCliComm();
118  [[nodiscard]] MSXCommandController& getMSXCommandController() { return *msxCommandController; }
119  [[nodiscard]] Scheduler& getScheduler() { return *scheduler; }
120  [[nodiscard]] MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
121  [[nodiscard]] StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
122  [[nodiscard]] CartridgeSlotManager& getSlotManager() { return *slotManager; }
123  [[nodiscard]] RealTime& getRealTime() { return *realTime; }
124  [[nodiscard]] Debugger& getDebugger() { return *debugger; }
125  [[nodiscard]] MSXMixer& getMSXMixer() { return *msxMixer; }
126  [[nodiscard]] PluggingController& getPluggingController();
127  [[nodiscard]] MSXCPU& getCPU();
128  [[nodiscard]] MSXCPUInterface& getCPUInterface();
129  [[nodiscard]] PanasonicMemory& getPanasonicMemory();
130  [[nodiscard]] MSXDeviceSwitch& getDeviceSwitch();
131  [[nodiscard]] CassettePortInterface& getCassettePort();
132  [[nodiscard]] JoystickPortIf& getJoystickPort(unsigned port);
133  [[nodiscard]] RenShaTurbo& getRenShaTurbo();
134  [[nodiscard]] LedStatus& getLedStatus();
135  [[nodiscard]] ReverseManager& getReverseManager() { return *reverseManager; }
136  [[nodiscard]] Reactor& getReactor() { return reactor; }
137  [[nodiscard]] VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
138 
139  // convenience methods
140  [[nodiscard]] CommandController& getCommandController();
141  [[nodiscard]] InfoCommand& getMachineInfoCommand();
142 
145  [[nodiscard]] EmuTime::param getCurrentTime();
146 
149  void addDevice(MSXDevice& device);
150  void removeDevice(MSXDevice& device);
151 
158  [[nodiscard]] MSXDevice* findDevice(std::string_view name);
159 
168  template<typename T, typename ... Args>
169  [[nodiscard]] std::shared_ptr<T> getSharedStuff(std::string_view name, Args&& ...args)
170  {
171  auto& weak = sharedStuffMap[name];
172  auto shared = std::static_pointer_cast<T>(weak.lock());
173  if (shared) return shared;
174 
175  shared = std::make_shared<T>(std::forward<Args>(args)...);
176  weak = shared;
177  return shared;
178  }
179 
183  [[nodiscard]] MSXMapperIO& createMapperIO();
184  [[nodiscard]] MSXMapperIO& getMapperIO() const
185  {
186  assert(mapperIOCounter);
187  return *mapperIO;
188  }
189  void destroyMapperIO();
190 
198  [[nodiscard]] std::string getUserName(const std::string& hwName);
199  void freeUserName(const std::string& hwName, const std::string& userName);
200 
201  template<typename Archive>
202  void serialize(Archive& ar, unsigned version);
203 
204 private:
205  void powerDown();
206  void deleteMachine();
207 
208 private:
209  Reactor& reactor;
210  std::string machineID;
211  std::string machineName;
212 
213  std::vector<MSXDevice*> availableDevices; // no ownership, no order
214 
217 
218  std::unique_ptr<MSXMapperIO> mapperIO;
219  unsigned mapperIOCounter;
220 
221  // These two should normally be the same, only during savestate loading
222  // machineConfig will already be filled in, but machineConfig2 not yet.
223  // This is important when an exception happens during loading of
224  // machineConfig2 (otherwise machineConfig2 gets deleted twice).
225  // See also HardwareConfig::serialize() and setMachineConfig()
226  std::unique_ptr<HardwareConfig> machineConfig2;
227  HardwareConfig* machineConfig;
228 
229  Extensions extensions; // order matters: later extension might depend on earlier ones
230 
231  // order of unique_ptr's is important!
232  std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
233  std::unique_ptr<MSXCliComm> msxCliComm;
234  std::unique_ptr<MSXEventDistributor> msxEventDistributor;
235  std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
236  std::unique_ptr<MSXCommandController> msxCommandController;
237  std::unique_ptr<Scheduler> scheduler;
238  std::unique_ptr<EventDelay> eventDelay;
239  std::unique_ptr<RealTime> realTime;
240  std::unique_ptr<Debugger> debugger;
241  std::unique_ptr<MSXMixer> msxMixer;
242  std::unique_ptr<PluggingController> pluggingController;
243  std::unique_ptr<MSXCPU> msxCpu;
244  std::unique_ptr<MSXCPUInterface> msxCpuInterface;
245  std::unique_ptr<PanasonicMemory> panasonicMemory;
246  std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
247  std::unique_ptr<CassettePortInterface> cassettePort;
248  std::unique_ptr<JoystickPortIf> joystickPort[2];
249  std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
250  std::unique_ptr<RenShaTurbo> renShaTurbo;
251  std::unique_ptr<LedStatus> ledStatus;
252  VideoSourceSetting videoSourceSetting;
253 
254  std::unique_ptr<CartridgeSlotManager> slotManager;
255  std::unique_ptr<ReverseManager> reverseManager;
256  std::unique_ptr<ResetCmd> resetCommand;
257  std::unique_ptr<LoadMachineCmd> loadMachineCommand;
258  std::unique_ptr<ListExtCmd> listExtCommand;
259  std::unique_ptr<ExtCmd> extCommand;
260  std::unique_ptr<RemoveExtCmd> removeExtCommand;
261  std::unique_ptr<MachineNameInfo> machineNameInfo;
262  std::unique_ptr<MachineTypeInfo> machineTypeInfo;
263  std::unique_ptr<MachineExtensionInfo> machineExtensionInfo;
264  std::unique_ptr<DeviceInfo> deviceInfo;
265  friend class DeviceInfo;
266 
267  std::unique_ptr<FastForwardHelper> fastForwardHelper;
268 
269  std::unique_ptr<SettingObserver> settingObserver;
270  friend class SettingObserver;
271  BooleanSetting& powerSetting;
272 
273  bool powered;
274  bool active;
275  bool fastForwarding;
276 };
278 
279 class ExtCmd final : public RecordedCommand
280 {
281 public:
282  ExtCmd(MSXMotherBoard& motherBoard, std::string commandName);
283  void execute(span<const TclObject> tokens, TclObject& result,
284  EmuTime::param time) override;
285  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
286  void tabCompletion(std::vector<std::string>& tokens) const override;
287 private:
288  MSXMotherBoard& motherBoard;
289  std::string commandName;
290 };
291 
292 } // namespace openmsx
293 
294 #endif
openmsx::HardwareConfig
HardwareConfig
Definition: HardwareConfig.cc:476
openmsx::MSXMixer
Definition: MSXMixer.hh:30
openmsx::MSXMotherBoard::findExtension
HardwareConfig * findExtension(std::string_view extensionName)
Definition: MSXMotherBoard.cc:368
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::MSXMotherBoard::getReactor
Reactor & getReactor()
Definition: MSXMotherBoard.hh:136
openmsx::MSXMotherBoard::removeExtension
void removeExtension(const HardwareConfig &extension)
Definition: MSXMotherBoard.cc:376
openmsx::MSXMotherBoard::createMapperIO
MSXMapperIO & createMapperIO()
All memory mappers in one MSX machine share the same four (logical) memory mapper registers.
Definition: MSXMotherBoard.cc:671
openmsx::ExtCmd
Definition: MSXMotherBoard.hh:280
openmsx::VideoSourceSetting
Definition: VideoSourceSetting.hh:11
openmsx.hh
openmsx::MSXMotherBoard::getSlotManager
CartridgeSlotManager & getSlotManager()
Definition: MSXMotherBoard.hh:122
openmsx::MSXMotherBoard::getExtensions
const Extensions & getExtensions() const
Definition: MSXMotherBoard.hh:109
openmsx::SettingObserver
Definition: MSXMotherBoard.cc:181
openmsx::MSXMotherBoard::activate
void activate(bool active)
Definition: MSXMotherBoard.cc:641
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::MSXMotherBoard::getSharedStuff
std::shared_ptr< T > getSharedStuff(std::string_view name, Args &&...args)
Some MSX device parts are shared between several MSX devices (e.g.
Definition: MSXMotherBoard.hh:169
openmsx::MSXMotherBoard::getVideoSource
VideoSourceSetting & getVideoSource()
Definition: MSXMotherBoard.hh:137
openmsx::MSXMotherBoard::getCurrentTime
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
Definition: MSXMotherBoard.cc:505
xxhash.hh
openmsx::CommandController
Definition: CommandController.hh:18
openmsx::MSXMotherBoard::fastForward
void fastForward(EmuTime::param time, bool fast)
Run emulation until a certain time in fast forward mode.
Definition: MSXMotherBoard.cc:521
openmsx::MSXMotherBoard::doReset
void doReset()
Definition: MSXMotherBoard.cc:566
openmsx::ExtCmd::execute
void execute(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.
Definition: MSXMotherBoard.cc:850
openmsx::MSXEventDistributor
Definition: MSXEventDistributor.hh:14
openmsx::DeviceInfo
Definition: MSXMotherBoard.cc:151
openmsx::MSXMapperIO
MSXMapperIO
Definition: MSXMapperIO.cc:119
openmsx::Debugger
Definition: Debugger.hh:23
serialize_meta.hh
openmsx::MSXMotherBoard::loadMachine
std::string loadMachine(const std::string &machine)
Definition: MSXMotherBoard.cc:305
openmsx::MSXMotherBoard::insertExtension
std::string insertExtension(std::string_view name, std::unique_ptr< HardwareConfig > extension)
Definition: MSXMotherBoard.cc:352
openmsx::MSXDeviceSwitch
Definition: MSXDeviceSwitch.hh:56
openmsx::MSXMotherBoard::getJoystickPort
JoystickPortIf & getJoystickPort(unsigned port)
Definition: MSXMotherBoard.cc:441
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:15
VideoSourceSetting.hh
openmsx::MSXMotherBoard::addDevice
void addDevice(MSXDevice &device)
All MSXDevices should be registered by the MotherBoard.
Definition: MSXMotherBoard.cc:556
XXHasher
Definition: xxhash.hh:153
openmsx::MSXMotherBoard::getStateChangeDistributor
StateChangeDistributor & getStateChangeDistributor()
Definition: MSXMotherBoard.hh:121
openmsx::MSXMotherBoard::getPanasonicMemory
PanasonicMemory & getPanasonicMemory()
Definition: MSXMotherBoard.cc:412
openmsx::ExtCmd::tabCompletion
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: MSXMotherBoard.cc:870
openmsx::MSXMotherBoard::removeDevice
void removeDevice(MSXDevice &device)
Definition: MSXMotherBoard.cc:561
openmsx::MSXMotherBoard::exitCPULoopAsync
void exitCPULoopAsync()
See CPU::exitCPULoopAsync().
Definition: MSXMotherBoard.cc:652
openmsx::MSXCPU
MSXCPU
Definition: MSXCPU.cc:561
openmsx::MSXMotherBoard::findDevice
MSXDevice * findDevice(std::string_view name)
Find a MSXDevice by name.
Definition: MSXMotherBoard.cc:664
openmsx::MSXMotherBoard::getCommandController
CommandController & getCommandController()
Definition: MSXMotherBoard.cc:495
openmsx::MSXCPUInterface
Definition: MSXCPUInterface.hh:64
openmsx::MSXMotherBoard::getMSXEventDistributor
MSXEventDistributor & getMSXEventDistributor()
Definition: MSXMotherBoard.hh:120
openmsx::JoystickPortIf
Definition: JoystickPort.hh:13
openmsx::MSXMotherBoard::getDeviceSwitch
MSXDeviceSwitch & getDeviceSwitch()
Definition: MSXMotherBoard.cc:420
openmsx::MSXMotherBoard::setMachineConfig
void setMachineConfig(HardwareConfig *machineConfig)
Definition: MSXMotherBoard.cc:277
openmsx::MSXMotherBoard::operator=
MSXMotherBoard & operator=(const MSXMotherBoard &)=delete
openmsx::MSXMotherBoard::isFastForwarding
bool isFastForwarding() const
Definition: MSXMotherBoard.hh:97
span
Definition: span.hh:126
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:67
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::MSXMotherBoard::getRenShaTurbo
RenShaTurbo & getRenShaTurbo()
Definition: MSXMotherBoard.cc:472
openmsx::MSXMotherBoard::getPluggingController
PluggingController & getPluggingController()
Definition: MSXMotherBoard.cc:390
openmsx::MSXMotherBoard::Extensions
std::vector< std::unique_ptr< HardwareConfig > > Extensions
Definition: MSXMotherBoard.hh:108
openmsx::MSXMotherBoard::getMachineType
std::string getMachineType() const
Definition: MSXMotherBoard.cc:288
RecordedCommand.hh
openmsx::MSXMotherBoard::unpause
void unpause()
Definition: MSXMotherBoard.cc:548
openmsx::MSXMotherBoard::getMapperIO
MSXMapperIO & getMapperIO() const
Definition: MSXMotherBoard.hh:184
openmsx::MSXMotherBoard::powerUp
void powerUp()
Definition: MSXMotherBoard.cc:592
openmsx::LedStatus
Definition: LedStatus.hh:17
openmsx::ExtCmd::help
std::string help(const std::vector< std::string > &tokens) const override
Print help for this command.
Definition: MSXMotherBoard.cc:865
openmsx::MSXMotherBoard::getMachineID
std::string_view getMachineID() const
Definition: MSXMotherBoard.hh:69
openmsx::MSXMotherBoard::getMachineInfoCommand
InfoCommand & getMachineInfoCommand()
Definition: MSXMotherBoard.cc:500
openmsx::MSXMotherBoard::getReverseManager
ReverseManager & getReverseManager()
Definition: MSXMotherBoard.hh:135
openmsx::InfoCommand
Definition: InfoCommand.hh:12
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:61
openmsx::MSXCPU
Definition: MSXCPU.hh:29
openmsx::MSXMotherBoard::getMSXCommandController
MSXCommandController & getMSXCommandController()
Definition: MSXMotherBoard.hh:118
openmsx::MSXMotherBoard::execute
bool execute()
Run emulation.
Definition: MSXMotherBoard.cc:510
openmsx::PanasonicMemory
Definition: PanasonicMemory.hh:15
openmsx::CassettePortInterface
Definition: CassettePort.hh:19
openmsx::MSXMotherBoard::getMSXMixer
MSXMixer & getMSXMixer()
Definition: MSXMotherBoard.hh:125
openmsx::MSXMotherBoard::loadExtension
std::string loadExtension(std::string_view extensionName, std::string_view slotname)
Definition: MSXMotherBoard.cc:336
openmsx::MSXMotherBoard::getScheduler
Scheduler & getScheduler()
Definition: MSXMotherBoard.hh:119
openmsx::MSXMotherBoard::readIRQVector
byte readIRQVector()
Definition: MSXMotherBoard.cc:583
openmsx::RealTime
Definition: RealTime.hh:25
openmsx::MSXMotherBoard::destroyMapperIO
void destroyMapperIO()
Definition: MSXMotherBoard.cc:690
openmsx::MSXCPUInterface
MSXCPUInterface
Definition: MSXCPUInterface.cc:1273
hash_map.hh
openmsx::MSXMotherBoard::getUserName
std::string getUserName(const std::string &hwName)
Keep track of which 'usernames' are in use.
Definition: MSXMotherBoard.cc:710
openmsx::MSXMotherBoard::getLedStatus
LedStatus & getLedStatus()
Definition: MSXMotherBoard.cc:483
openmsx::MSXMotherBoard::getCPUInterface
MSXCPUInterface & getCPUInterface()
Definition: MSXMotherBoard.cc:406
EmuTime.hh
openmsx::MSXMotherBoard::isActive
bool isActive() const
Definition: MSXMotherBoard.hh:96
openmsx::MSXMotherBoard::MSXMotherBoard
MSXMotherBoard(const MSXMotherBoard &)=delete
openmsx::BooleanSetting
Definition: BooleanSetting.hh:9
openmsx::RecordedCommand
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: RecordedCommand.hh:46
openmsx::ReverseManager
Definition: ReverseManager.hh:28
openmsx::MSXDevice
MSXDevice
Definition: MSXDevice.cc:538
openmsx::MSXMapperIO
Definition: MSXMapperIO.hh:23
openmsx::CliComm
Definition: CliComm.hh:11
openmsx::MSXMotherBoard::getMachineConfig
const HardwareConfig * getMachineConfig() const
Definition: MSXMotherBoard.hh:101
openmsx::MSXMotherBoard::isTurboR
bool isTurboR() const
Definition: MSXMotherBoard.cc:298
openmsx::HardwareConfig
Definition: HardwareConfig.hh:22
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::ExtCmd::ExtCmd
ExtCmd(MSXMotherBoard &motherBoard, std::string commandName)
Definition: MSXMotherBoard.cc:840
openmsx::TclObject
Definition: TclObject.hh:22
openmsx::RenShaTurbo
Ren-Sha Turbo is the autofire in several MSX 2+ models and in the MSX turbo R.
Definition: RenShaTurbo.hh:21
openmsx::MSXCommandController
Definition: MSXCommandController.hh:22
openmsx::MSXMotherBoard::getCassettePort
CassettePortInterface & getCassettePort()
Definition: MSXMotherBoard.cc:428
openmsx::MSXMotherBoard::getDebugger
Debugger & getDebugger()
Definition: MSXMotherBoard.hh:124
openmsx::MSXMotherBoard::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXMotherBoard.cc:1127
openmsx::PluggingController
Central administration of Connectors and Pluggables.
Definition: PluggingController.hh:22
openmsx::MSXMotherBoard::~MSXMotherBoard
~MSXMotherBoard()
Definition: MSXMotherBoard.cc:248
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MSXMotherBoard::getMSXCliComm
CliComm & getMSXCliComm()
Definition: MSXMotherBoard.cc:385
openmsx::CartridgeSlotManager
Definition: CartridgeSlotManager.hh:16
openmsx::MSXMotherBoard::freeUserName
void freeUserName(const std::string &hwName, const std::string &userName)
Definition: MSXMotherBoard.cc:722
openmsx::MSXMotherBoard::getRealTime
RealTime & getRealTime()
Definition: MSXMotherBoard.hh:123
openmsx::MSXMotherBoard::getMachineName
std::string_view getMachineName() const
Definition: MSXMotherBoard.hh:70
openmsx::MSXMotherBoard::getCPU
MSXCPU & getCPU()
Definition: MSXMotherBoard.cc:399
hash_map
Definition: hash_map.hh:32
openmsx::MSXDeviceSwitch
MSXDeviceSwitch
Definition: MSXDeviceSwitch.cc:97
openmsx::MSXMotherBoard::exitCPULoopSync
void exitCPULoopSync()
Definition: MSXMotherBoard.cc:659
openmsx::MSXMotherBoard::pause
void pause()
Pause MSX machine.
Definition: MSXMotherBoard.cc:540