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 MachineTypeInfo;
37 class MSXCliComm;
38 class MSXCommandController;
39 class MSXCPU;
40 class MSXCPUInterface;
41 class MSXDevice;
42 class MSXDeviceSwitch;
43 class MSXEventDistributor;
44 class MSXMapperIO;
45 class MSXMixer;
46 class PanasonicMemory;
47 class PluggingController;
48 class Reactor;
49 class RealTime;
50 class RemoveExtCmd;
51 class RenShaTurbo;
52 class ResetCmd;
53 class ReverseManager;
54 class SettingObserver;
55 class Scheduler;
56 class Setting;
57 class StateChangeDistributor;
58 
59 class MSXMotherBoard final
60 {
61 public:
62  MSXMotherBoard(const MSXMotherBoard&) = delete;
63  MSXMotherBoard& operator=(const MSXMotherBoard&) = delete;
64 
65  explicit MSXMotherBoard(Reactor& reactor);
67 
68  const std::string& getMachineID() const { return machineID; }
69  const std::string& getMachineName() const { return machineName; }
70 
75  bool execute();
76 
79  void fastForward(EmuTime::param time, bool fast);
80 
82  void exitCPULoopAsync();
83  void exitCPULoopSync();
84 
88  void pause();
89  void unpause();
90 
91  void powerUp();
92 
93  void doReset();
94  void activate(bool active);
95  bool isActive() const { return active; }
96  bool isFastForwarding() const { return fastForwarding; }
97 
99 
100  const HardwareConfig* getMachineConfig() const { return machineConfig; }
101  void setMachineConfig(HardwareConfig* machineConfig);
102  bool isTurboR() const;
103 
104  std::string loadMachine(const std::string& machine);
105 
106  using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
107  const Extensions& getExtensions() const { return extensions; }
108  HardwareConfig* findExtension(string_ref extensionName);
109  std::string loadExtension(string_ref extensionName, string_ref slotname);
110  std::string insertExtension(string_ref name,
111  std::unique_ptr<HardwareConfig> extension);
112  void removeExtension(const HardwareConfig& extension);
113 
114  // The following classes are unique per MSX machine
116  MSXCommandController& getMSXCommandController() { return *msxCommandController; }
117  Scheduler& getScheduler() { return *scheduler; }
118  MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
119  StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
120  CartridgeSlotManager& getSlotManager() { return *slotManager; }
121  RealTime& getRealTime() { return *realTime; }
122  Debugger& getDebugger() { return *debugger; }
123  MSXMixer& getMSXMixer() { return *msxMixer; }
125  MSXCPU& getCPU();
130  JoystickPortIf& getJoystickPort(unsigned port);
133  ReverseManager& getReverseManager() { return *reverseManager; }
134  Reactor& getReactor() { return reactor; }
135  VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
136 
137  // convenience methods
140 
144 
147  void addDevice(MSXDevice& device);
148  void removeDevice(MSXDevice& device);
149 
157 
166  template<typename T, typename ... Args>
167  std::shared_ptr<T> getSharedStuff(string_ref name, Args&& ...args)
168  {
169  auto& weak = sharedStuffMap[name];
170  auto shared = std::static_pointer_cast<T>(weak.lock());
171  if (shared) return shared;
172 
173  shared = std::make_shared<T>(std::forward<Args>(args)...);
174  weak = shared;
175  return shared;
176  }
177 
182  void destroyMapperIO();
183 
191  std::string getUserName(const std::string& hwName);
192  void freeUserName(const std::string& hwName, const std::string& userName);
193 
194  template<typename Archive>
195  void serialize(Archive& ar, unsigned version);
196 
197 private:
198  void powerDown();
199  void deleteMachine();
200 
201  Reactor& reactor;
202  std::string machineID;
203  std::string machineName;
204 
205  std::vector<MSXDevice*> availableDevices; // no ownership, no order
206 
209 
210  std::unique_ptr<MSXMapperIO> mapperIO;
211  unsigned mapperIOCounter;
212 
213  // These two should normally be the same, only during savestate loading
214  // machineConfig will already be filled in, but machineConfig2 not yet.
215  // This is important when an exception happens during loading of
216  // machineConfig2 (otherwise machineConfig2 gets deleted twice).
217  // See also HardwareConfig::serialize() and setMachineConfig()
218  std::unique_ptr<HardwareConfig> machineConfig2;
219  HardwareConfig* machineConfig;
220 
221  Extensions extensions; // order matters: later extension might depend on earlier ones
222 
223  // order of unique_ptr's is important!
224  std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
225  std::unique_ptr<MSXCliComm> msxCliComm;
226  std::unique_ptr<MSXEventDistributor> msxEventDistributor;
227  std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
228  std::unique_ptr<MSXCommandController> msxCommandController;
229  std::unique_ptr<Scheduler> scheduler;
230  std::unique_ptr<EventDelay> eventDelay;
231  std::unique_ptr<RealTime> realTime;
232  std::unique_ptr<Debugger> debugger;
233  std::unique_ptr<MSXMixer> msxMixer;
234  std::unique_ptr<PluggingController> pluggingController;
235  std::unique_ptr<MSXCPU> msxCpu;
236  std::unique_ptr<MSXCPUInterface> msxCpuInterface;
237  std::unique_ptr<PanasonicMemory> panasonicMemory;
238  std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
239  std::unique_ptr<CassettePortInterface> cassettePort;
240  std::unique_ptr<JoystickPortIf> joystickPort[2];
241  std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
242  std::unique_ptr<RenShaTurbo> renShaTurbo;
243  std::unique_ptr<LedStatus> ledStatus;
244  VideoSourceSetting videoSourceSetting;
245 
246  std::unique_ptr<CartridgeSlotManager> slotManager;
247  std::unique_ptr<ReverseManager> reverseManager;
248  std::unique_ptr<ResetCmd> resetCommand;
249  std::unique_ptr<LoadMachineCmd> loadMachineCommand;
250  std::unique_ptr<ListExtCmd> listExtCommand;
251  std::unique_ptr<ExtCmd> extCommand;
252  std::unique_ptr<RemoveExtCmd> removeExtCommand;
253  std::unique_ptr<MachineNameInfo> machineNameInfo;
254  std::unique_ptr<MachineTypeInfo> machineTypeInfo;
255  std::unique_ptr<DeviceInfo> deviceInfo;
256  friend class DeviceInfo;
257 
258  std::unique_ptr<FastForwardHelper> fastForwardHelper;
259 
260  std::unique_ptr<SettingObserver> settingObserver;
261  friend class SettingObserver;
262  BooleanSetting& powerSetting;
263 
264  bool powered;
265  bool active;
266  bool fastForwarding;
267 };
269 
270 class ExtCmd final : public RecordedCommand
271 {
272 public:
273  ExtCmd(MSXMotherBoard& motherBoard, string_ref commandName);
274  void execute(array_ref<TclObject> tokens, TclObject& result,
275  EmuTime::param time) override;
276  std::string help(const std::vector<std::string>& tokens) const override;
277  void tabCompletion(std::vector<std::string>& tokens) const override;
278 private:
279  MSXMotherBoard& motherBoard;
280  std::string commandName;
281 };
282 
283 } // namespace openmsx
284 
285 #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().