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 "noncopyable.hh"
12 #include "RecordedCommand.hh"
13 #include <memory>
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 MachineNameInfo;
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 : private noncopyable
60 {
61 public:
62  explicit MSXMotherBoard(Reactor& reactor);
64 
65  const std::string& getMachineID() const { return machineID; }
66  const std::string& getMachineName() const { return machineName; }
67 
72  bool execute();
73 
76  void fastForward(EmuTime::param time, bool fast);
77 
79  void exitCPULoopAsync();
80  void exitCPULoopSync();
81 
85  void pause();
86  void unpause();
87 
88  void powerUp();
89 
90  void doReset();
91  void activate(bool active);
92  bool isActive() const { return active; }
93  bool isFastForwarding() const { return fastForwarding; }
94 
96 
97  const HardwareConfig* getMachineConfig() const { return machineConfig; }
98  void setMachineConfig(HardwareConfig* machineConfig);
99  bool isTurboR() const;
100 
101  std::string loadMachine(const std::string& machine);
102 
103  using Extensions = std::vector<std::unique_ptr<HardwareConfig>>;
104  const Extensions& getExtensions() const { return extensions; }
105  HardwareConfig* findExtension(string_ref extensionName);
106  std::string loadExtension(string_ref extensionName, string_ref slotname);
107  std::string insertExtension(string_ref name,
108  std::unique_ptr<HardwareConfig> extension);
109  void removeExtension(const HardwareConfig& extension);
110 
111  // The following classes are unique per MSX machine
113  MSXCommandController& getMSXCommandController() { return *msxCommandController; }
114  Scheduler& getScheduler() { return *scheduler; }
115  MSXEventDistributor& getMSXEventDistributor() { return *msxEventDistributor; }
116  StateChangeDistributor& getStateChangeDistributor() { return *stateChangeDistributor; }
117  CartridgeSlotManager& getSlotManager() { return *slotManager; }
118  RealTime& getRealTime() { return *realTime; }
119  Debugger& getDebugger() { return *debugger; }
120  MSXMixer& getMSXMixer() { return *msxMixer; }
122  MSXCPU& getCPU();
127  JoystickPortIf& getJoystickPort(unsigned port);
130  ReverseManager& getReverseManager() { return *reverseManager; }
131  Reactor& getReactor() { return reactor; }
132  VideoSourceSetting& getVideoSource() { return videoSourceSetting; }
133 
134  // convenience methods
137 
141 
144  void addDevice(MSXDevice& device);
145  void removeDevice(MSXDevice& device);
146 
154 
163  template<typename T, typename ... Args>
164  std::shared_ptr<T> getSharedStuff(string_ref name, Args&& ...args)
165  {
166  auto& weak = sharedStuffMap[name];
167  auto shared = std::static_pointer_cast<T>(weak.lock());
168  if (shared) return shared;
169 
170  shared = std::make_shared<T>(std::forward<Args>(args)...);
171  weak = shared;
172  return shared;
173  }
174 
179  void destroyMapperIO();
180 
188  std::string getUserName(const std::string& hwName);
189  void freeUserName(const std::string& hwName, const std::string& userName);
190 
191  template<typename Archive>
192  void serialize(Archive& ar, unsigned version);
193 
194 private:
195  void powerDown();
196  void deleteMachine();
197 
198  Reactor& reactor;
199  std::string machineID;
200  std::string machineName;
201 
202  std::vector<MSXDevice*> availableDevices; // no ownership
203 
206 
207  std::unique_ptr<MSXMapperIO> mapperIO;
208  unsigned mapperIOCounter;
209 
210  // These two should normally be the same, only during savestate loading
211  // machineConfig will already be filled in, but machineConfig2 not yet.
212  // This is important when an exception happens during loading of
213  // machineConfig2 (otherwise machineConfig2 gets deleted twice).
214  // See also HardwareConfig::serialize() and setMachineConfig()
215  std::unique_ptr<HardwareConfig> machineConfig2;
216  HardwareConfig* machineConfig;
217 
218  Extensions extensions;
219 
220  // order of unique_ptr's is important!
221  std::unique_ptr<AddRemoveUpdate> addRemoveUpdate;
222  std::unique_ptr<MSXCliComm> msxCliComm;
223  std::unique_ptr<MSXEventDistributor> msxEventDistributor;
224  std::unique_ptr<StateChangeDistributor> stateChangeDistributor;
225  std::unique_ptr<MSXCommandController> msxCommandController;
226  std::unique_ptr<Scheduler> scheduler;
227  std::unique_ptr<EventDelay> eventDelay;
228  std::unique_ptr<RealTime> realTime;
229  std::unique_ptr<Debugger> debugger;
230  std::unique_ptr<MSXMixer> msxMixer;
231  std::unique_ptr<PluggingController> pluggingController;
232  std::unique_ptr<MSXCPU> msxCpu;
233  std::unique_ptr<MSXCPUInterface> msxCpuInterface;
234  std::unique_ptr<PanasonicMemory> panasonicMemory;
235  std::unique_ptr<MSXDeviceSwitch> deviceSwitch;
236  std::unique_ptr<CassettePortInterface> cassettePort;
237  std::unique_ptr<JoystickPortIf> joystickPort[2];
238  std::unique_ptr<JoyPortDebuggable> joyPortDebuggable;
239  std::unique_ptr<RenShaTurbo> renShaTurbo;
240  std::unique_ptr<LedStatus> ledStatus;
241  VideoSourceSetting videoSourceSetting;
242 
243  std::unique_ptr<CartridgeSlotManager> slotManager;
244  std::unique_ptr<ReverseManager> reverseManager;
245  std::unique_ptr<ResetCmd> resetCommand;
246  std::unique_ptr<LoadMachineCmd> loadMachineCommand;
247  std::unique_ptr<ListExtCmd> listExtCommand;
248  std::unique_ptr<ExtCmd> extCommand;
249  std::unique_ptr<RemoveExtCmd> removeExtCommand;
250  std::unique_ptr<MachineNameInfo> machineNameInfo;
251  std::unique_ptr<DeviceInfo> deviceInfo;
252  friend class DeviceInfo;
253 
254  std::unique_ptr<FastForwardHelper> fastForwardHelper;
255 
256  std::unique_ptr<SettingObserver> settingObserver;
257  friend class SettingObserver;
258  BooleanSetting& powerSetting;
259 
260  bool powered;
261  bool active;
262  bool fastForwarding;
263 };
265 
266 class ExtCmd final : public RecordedCommand
267 {
268 public:
269  ExtCmd(MSXMotherBoard& motherBoard, string_ref commandName);
270  void execute(array_ref<TclObject> tokens, TclObject& result,
271  EmuTime::param time) override;
272  std::string help(const std::vector<std::string>& tokens) const override;
273  void tabCompletion(std::vector<std::string>& tokens) const override;
274 private:
275  MSXMotherBoard& motherBoard;
276  std::string commandName;
277 };
278 
279 } // namespace openmsx
280 
281 #endif
const std::string & getMachineID() const
MSXCommandController & getMSXCommandController()
Contains the main loop of openMSX.
Definition: Reactor.hh:62
PluggingController & getPluggingController()
ExtCmd(MSXMotherBoard &motherBoard, string_ref commandName)
MSXCPUInterface & getCPUInterface()
void pause()
Pause MSX machine.
void removeDevice(MSXDevice &device)
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)
const HardwareConfig * getMachineConfig() const
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.
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
CassettePortInterface & getCassettePort()
void execute(array_ref< 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...
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)
std::string loadMachine(const std::string &machine)
void setMachineConfig(HardwareConfig *machineConfig)
std::string help(const std::vector< std::string > &tokens) const override
Print help for this command.
HardwareConfig * findExtension(string_ref extensionName)
const std::string & getMachineName() const
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:32
ReverseManager & getReverseManager()
CommandController & getCommandController()
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:25
std::string getUserName(const std::string &hwName)
Keep track of which 'usernames' are in use.
MSXMotherBoard(Reactor &reactor)
bool isFastForwarding() const
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:21
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
VideoSourceSetting & getVideoSource()
Based on boost::noncopyable, see boost documentation: http://www.boost.org/libs/utility.
Definition: noncopyable.hh:12
void addDevice(MSXDevice &device)
All MSXDevices should be registered by the MotherBoard.
MSXDeviceSwitch & getDeviceSwitch()
RenShaTurbo & getRenShaTurbo()
StateChangeDistributor & getStateChangeDistributor()
void exitCPULoopAsync()
See CPU::exitCPULoopAsync().
const Extensions & getExtensions() const