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 "string_ref.hh"
9 #include "xxhash.hh"
10 #include "openmsx.hh"
11 #include "RecordedCommand.hh"
12 #include <memory>
13 #include <vector>
14 
15 namespace openmsx {
16 
17 class AddRemoveUpdate;
18 class BooleanSetting;
19 class CartridgeSlotManager;
20 class CassettePortInterface;
21 class CliComm;
22 class CommandController;
23 class Debugger;
24 class DeviceInfo;
25 class EventDelay;
26 class ExtCmd;
27 class FastForwardHelper;
28 class HardwareConfig;
29 class InfoCommand;
30 class JoyPortDebuggable;
31 class JoystickPortIf;
32 class LedStatus;
33 class ListExtCmd;
34 class LoadMachineCmd;
35 class MachineNameInfo;
36 class MSXCliComm;
37 class MSXCommandController;
38 class MSXCPU;
39 class MSXCPUInterface;
40 class MSXDevice;
41 class MSXDeviceSwitch;
42 class MSXEventDistributor;
43 class MSXMapperIO;
44 class MSXMixer;
45 class PanasonicMemory;
46 class PluggingController;
47 class Reactor;
48 class RealTime;
49 class RemoveExtCmd;
50 class RenShaTurbo;
51 class ResetCmd;
52 class ReverseManager;
53 class SettingObserver;
54 class Scheduler;
55 class Setting;
56 class StateChangeDistributor;
57 
58 class MSXMotherBoard final
59 {
60 public:
61  MSXMotherBoard(const MSXMotherBoard&) = delete;
62  MSXMotherBoard& operator=(const MSXMotherBoard&) = delete;
63 
64  explicit MSXMotherBoard(Reactor& reactor);
66 
67  const std::string& getMachineID() const { return machineID; }
68  const std::string& getMachineName() const { return machineName; }
69 
74  bool execute();
75 
78  void fastForward(EmuTime::param time, bool fast);
79 
81  void exitCPULoopAsync();
82  void exitCPULoopSync();
83 
87  void pause();
88  void unpause();
89 
90  void powerUp();
91 
92  void doReset();
93  void activate(bool active);
94  bool isActive() const { return active; }
95  bool isFastForwarding() const { return fastForwarding; }
96 
98 
99  const HardwareConfig* getMachineConfig() const { return machineConfig; }
100  void setMachineConfig(HardwareConfig* machineConfig);
101  bool isTurboR() const;
102 
103  std::string loadMachine(const std::string& machine);
104 
105  using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
106  const Extensions& getExtensions() const { return extensions; }
107  HardwareConfig* findExtension(string_ref extensionName);
108  std::string loadExtension(string_ref extensionName, string_ref slotname);
109  std::string insertExtension(string_ref name,
110  std::unique_ptr<HardwareConfig> extension);
111  void removeExtension(const HardwareConfig& extension);
112 
113  // The following classes are unique per MSX machine
115  MSXCommandController& getMSXCommandController() { return *msxCommandController; }
116  Scheduler& getScheduler() { return *scheduler; }
117  MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
118  StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
119  CartridgeSlotManager& getSlotManager() { return *slotManager; }
120  RealTime& getRealTime() { return *realTime; }
121  Debugger& getDebugger() { return *debugger; }
122  MSXMixer& getMSXMixer() { return *msxMixer; }
124  MSXCPU& getCPU();
129  JoystickPortIf& getJoystickPort(unsigned port);
132  ReverseManager& getReverseManager() { return *reverseManager; }
133  Reactor& getReactor() { return reactor; }
134  VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
135 
136  // convenience methods
139 
143 
146  void addDevice(MSXDevice& device);
147  void removeDevice(MSXDevice& device);
148 
156 
165  template<typename T, typename ... Args>
166  std::shared_ptr<T> getSharedStuff(string_ref name, Args&& ...args)
167  {
168  auto& weak = sharedStuffMap[name];
169  auto shared = std::static_pointer_cast<T>(weak.lock());
170  if (shared) return shared;
171 
172  shared = std::make_shared<T>(std::forward<Args>(args)...);
173  weak = shared;
174  return shared;
175  }
176 
181  void destroyMapperIO();
182 
190  std::string getUserName(const std::string& hwName);
191  void freeUserName(const std::string& hwName, const std::string& userName);
192 
193  template<typename Archive>
194  void serialize(Archive& ar, unsigned version);
195 
196 private:
197  void powerDown();
198  void deleteMachine();
199 
200  Reactor& reactor;
201  std::string machineID;
202  std::string machineName;
203 
204  std::vector<MSXDevice*> availableDevices; // no ownership, no order
205 
208 
209  std::unique_ptr<MSXMapperIO> mapperIO;
210  unsigned mapperIOCounter;
211 
212  // These two should normally be the same, only during savestate loading
213  // machineConfig will already be filled in, but machineConfig2 not yet.
214  // This is important when an exception happens during loading of
215  // machineConfig2 (otherwise machineConfig2 gets deleted twice).
216  // See also HardwareConfig::serialize() and setMachineConfig()
217  std::unique_ptr<HardwareConfig> machineConfig2;
218  HardwareConfig* machineConfig;
219 
220  Extensions extensions; // order matters: later extension might depend on earlier ones
221 
222  // order of unique_ptr's is important!
223  std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
224  std::unique_ptr<MSXCliComm> msxCliComm;
225  std::unique_ptr<MSXEventDistributor> msxEventDistributor;
226  std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
227  std::unique_ptr<MSXCommandController> msxCommandController;
228  std::unique_ptr<Scheduler> scheduler;
229  std::unique_ptr<EventDelay> eventDelay;
230  std::unique_ptr<RealTime> realTime;
231  std::unique_ptr<Debugger> debugger;
232  std::unique_ptr<MSXMixer> msxMixer;
233  std::unique_ptr<PluggingController> pluggingController;
234  std::unique_ptr<MSXCPU> msxCpu;
235  std::unique_ptr<MSXCPUInterface> msxCpuInterface;
236  std::unique_ptr<PanasonicMemory> panasonicMemory;
237  std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
238  std::unique_ptr<CassettePortInterface> cassettePort;
239  std::unique_ptr<JoystickPortIf> joystickPort[2];
240  std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
241  std::unique_ptr<RenShaTurbo> renShaTurbo;
242  std::unique_ptr<LedStatus> ledStatus;
243  VideoSourceSetting videoSourceSetting;
244 
245  std::unique_ptr<CartridgeSlotManager> slotManager;
246  std::unique_ptr<ReverseManager> reverseManager;
247  std::unique_ptr<ResetCmd> resetCommand;
248  std::unique_ptr<LoadMachineCmd> loadMachineCommand;
249  std::unique_ptr<ListExtCmd> listExtCommand;
250  std::unique_ptr<ExtCmd> extCommand;
251  std::unique_ptr<RemoveExtCmd> removeExtCommand;
252  std::unique_ptr<MachineNameInfo> machineNameInfo;
253  std::unique_ptr<DeviceInfo> deviceInfo;
254  friend class DeviceInfo;
255 
256  std::unique_ptr<FastForwardHelper> fastForwardHelper;
257 
258  std::unique_ptr<SettingObserver> settingObserver;
259  friend class SettingObserver;
260  BooleanSetting& powerSetting;
261 
262  bool powered;
263  bool active;
264  bool fastForwarding;
265 };
267 
268 class ExtCmd final : public RecordedCommand
269 {
270 public:
271  ExtCmd(MSXMotherBoard& motherBoard, string_ref commandName);
272  void execute(array_ref<TclObject> tokens, TclObject& result,
273  EmuTime::param time) override;
274  std::string help(const std::vector<std::string>& tokens) const override;
275  void tabCompletion(std::vector<std::string>& tokens) const override;
276 private:
277  MSXMotherBoard& motherBoard;
278  std::string commandName;
279 };
280 
281 } // namespace openmsx
282 
283 #endif
MSXCommandController & getMSXCommandController()
Contains the main loop of openMSX.
Definition: Reactor.hh:61
PluggingController & getPluggingController()
MSXCPUInterface & getCPUInterface()
bool isFastForwarding() const
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void pause()
Pause MSX machine.
void removeDevice(MSXDevice &device)
const std::string & getMachineName() const
Commands that directly influence the MSX state should send and events so that they can be recorded by...
void freeUserName(const std::string &hwName, const std::string &userName)
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
Central administration of Connectors and Pluggables.
void fastForward(EmuTime::param time, bool fast)
Run emulation until a certain time in fast forward mode.
CassettePortInterface & getCassettePort()
const Extensions & getExtensions() const
MSXDevice * findDevice(string_ref name)
Find a MSXDevice by name.
bool execute()
Run emulation.
InfoCommand & getMachineInfoCommand()
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
const std::string & getMachineID() const
const HardwareConfig * getMachineConfig() const
std::string loadMachine(const std::string &machine)
void setMachineConfig(HardwareConfig *machineConfig)
HardwareConfig * findExtension(string_ref extensionName)
PanasonicMemory & getPanasonicMemory()
CartridgeSlotManager & getSlotManager()
std::string insertExtension(string_ref name, std::unique_ptr< HardwareConfig > extension)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
ReverseManager & getReverseManager()
CommandController & getCommandController()
std::string getUserName(const std::string &hwName)
Keep track of which &#39;usernames&#39; are in use.
JoystickPortIf & getJoystickPort(unsigned port)
void removeExtension(const HardwareConfig &extension)
std::vector< std::unique_ptr< HardwareConfig >> Extensions
void activate(bool active)
std::shared_ptr< T > getSharedStuff(string_ref name, Args &&...args)
Some MSX device parts are shared between several MSX devices (e.g.
MSXMapperIO * createMapperIO()
All memory mappers in one MSX machine share the same four (logical) memory mapper registers...
void serialize(Archive &ar, unsigned version)
std::string loadExtension(string_ref extensionName, string_ref slotname)
MSXEventDistributor & getMSXEventDistributor()
Ren-Sha Turbo is the autofire in several MSX 2+ models and in the MSX turbo R.
Definition: RenShaTurbo.hh:20
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
VideoSourceSetting & getVideoSource()
MSXMotherBoard & operator=(const MSXMotherBoard &)=delete
void addDevice(MSXDevice &device)
All MSXDevices should be registered by the MotherBoard.
MSXDeviceSwitch & getDeviceSwitch()
MSXMotherBoard(const MSXMotherBoard &)=delete
RenShaTurbo & getRenShaTurbo()
StateChangeDistributor & getStateChangeDistributor()
void exitCPULoopAsync()
See CPU::exitCPULoopAsync().