openMSX
MSXDevice.hh
Go to the documentation of this file.
1 #ifndef MSXDEVICE_HH
2 #define MSXDEVICE_HH
3 
4 #include "DeviceConfig.hh"
5 #include "EmuTime.hh"
6 #include "openmsx.hh"
7 #include "serialize_meta.hh"
8 #include <string>
9 #include <vector>
10 #include <utility> // for pair
11 
12 namespace openmsx {
13 
14 class XMLElement;
15 class MSXMotherBoard;
16 class MSXCPU;
17 class MSXCPUInterface;
18 class Scheduler;
19 class CliComm;
20 class Reactor;
21 class CommandController;
22 class LedStatus;
23 class PluggingController;
24 class HardwareConfig;
25 class TclObject;
26 
31 class MSXDevice
32 {
33 public:
34  MSXDevice(const MSXDevice&) = delete;
35  MSXDevice& operator=(const MSXDevice&) = delete;
36 
37  using Devices = std::vector<MSXDevice*>;
38 
39  virtual ~MSXDevice() = 0;
40 
44  return deviceConfig.getHardwareConfig();
45  }
46 
50  void testRemove(Devices alreadyRemoved) const;
51 
56  virtual void reset(EmuTime::param time);
57 
65  virtual byte readIRQVector();
66 
73  virtual void powerDown(EmuTime::param time);
74 
80  virtual void powerUp(EmuTime::param time);
81 
86  virtual std::string getName() const;
87 
92  virtual void getNameList(TclObject& result) const;
93 
97  void getDeviceInfo(TclObject& result) const;
98 
105  void getVisibleMemRegion(unsigned& base, unsigned& size) const;
106 
107  // IO
108 
113  virtual byte readIO(word port, EmuTime::param time);
114 
120  virtual void writeIO(word port, byte value, EmuTime::param time);
121 
130  virtual byte peekIO(word port, EmuTime::param time) const;
131 
132 
133  // Memory
134 
140  virtual byte readMem(word address, EmuTime::param time);
141 
147  virtual void writeMem(word address, byte value, EmuTime::param time);
148 
160  virtual const byte* getReadCacheLine(word start) const;
161 
173  virtual byte* getWriteCacheLine(word start) const;
174 
187  virtual byte peekMem(word address, EmuTime::param time) const;
188 
197  virtual void globalWrite(word address, byte value, EmuTime::param time);
198 
203  virtual void globalRead(word address, EmuTime::param time);
204 
209  void invalidateMemCache(word start, unsigned size);
210 
214 
218  const XMLElement& getDeviceConfig() const {
219  return *deviceConfig.getXML();
220  }
221  const DeviceConfig& getDeviceConfig2() const { // TODO
222  return deviceConfig;
223  }
224 
227  const Devices& getReferences() const;
228 
229  // convenience functions, these delegate to MSXMotherBoard
230  EmuTime::param getCurrentTime() const;
231  MSXCPU& getCPU() const;
233  Scheduler& getScheduler() const;
234  CliComm& getCliComm() const;
235  Reactor& getReactor() const;
238  LedStatus& getLedStatus() const;
239 
240  template<typename Archive>
241  void serialize(Archive& ar, unsigned version);
242 
243 protected:
249  MSXDevice(const DeviceConfig& config, const std::string& name);
250  explicit MSXDevice(const DeviceConfig& config);
251 
263  friend class DeviceFactory;
264  virtual void init();
265 
270  virtual void getExtraDeviceInfo(TclObject& result) const;
271 
272 public:
273  // public to allow non-MSXDevices to use these same arrays
274  static byte unmappedRead [0x10000]; // Read only
275  static byte unmappedWrite[0x10000]; // Write only
276 
277 private:
278  void initName(const std::string& name);
279  void staticInit();
280 
281  void lockDevices();
282  void unlockDevices();
283 
284  void registerSlots();
285  void unregisterSlots();
286 
287  void registerPorts();
288  void unregisterPorts();
289 
290  using MemRegions = std::vector<std::pair<unsigned, unsigned>>;
291  MemRegions memRegions;
292  std::vector<byte> inPorts;
293  std::vector<byte> outPorts;
294 
295  DeviceConfig deviceConfig;
296  std::string deviceName;
297 
298  Devices references;
299  Devices referencedBy;
300 
301  int ps;
302  int ss;
303 };
304 
306 
307 #define REGISTER_MSXDEVICE(CLASS, NAME) \
308 REGISTER_POLYMORPHIC_INITIALIZER(MSXDevice, CLASS, NAME);
309 
310 } // namespace openmsx
311 
312 #endif
virtual void init()
Definition: MSXDevice.cc:50
const DeviceConfig & getDeviceConfig2() const
Definition: MSXDevice.hh:221
Contains the main loop of openMSX.
Definition: Reactor.hh:63
virtual byte * getWriteCacheLine(word start) const
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
Definition: MSXDevice.cc:455
CliComm & getCliComm() const
Definition: MSXDevice.cc:149
REGISTER_BASE_NAME_HELPER(MSXFDC, "FDC")
const Devices & getReferences() const
Get the device references that are specified for this device.
Definition: MSXDevice.cc:127
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
virtual byte readMem(word address, EmuTime::param time)
Read a byte from a location at a certain time from this device.
Definition: MSXDevice.cc:415
virtual void writeMem(word address, byte value, EmuTime::param time)
Write a given byte to a given location at a certain time to this device.
Definition: MSXDevice.cc:426
virtual void globalWrite(word address, byte value, EmuTime::param time)
Global writes.
Definition: MSXDevice.cc:444
virtual byte readIRQVector()
Gets IRQ vector used in IM2.
Definition: MSXDevice.cc:361
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:376
virtual byte readIO(word port, EmuTime::param time)
Read a byte from an IO port at a certain time from this device.
Definition: MSXDevice.cc:398
Central administration of Connectors and Pluggables.
MSXDevice & operator=(const MSXDevice &)=delete
void serialize(Archive &ar, unsigned version)
Definition: MSXDevice.cc:466
virtual void globalRead(word address, EmuTime::param time)
Global reads.
Definition: MSXDevice.cc:450
void getDeviceInfo(TclObject &result) const
Get device info.
Definition: MSXDevice.cc:386
virtual void powerUp(EmuTime::param time)
This method is called when MSX is powered up.
Definition: MSXDevice.cc:371
virtual byte peekMem(word address, EmuTime::param time) const
Read a byte from a given memory location.
Definition: MSXDevice.cc:432
virtual void getExtraDeviceInfo(TclObject &result) const
Definition: MSXDevice.cc:392
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:133
LedStatus & getLedStatus() const
Definition: MSXDevice.cc:161
virtual const byte * getReadCacheLine(word start) const
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading...
Definition: MSXDevice.cc:421
virtual void powerDown(EmuTime::param time)
This method is called when MSX is powered down.
Definition: MSXDevice.cc:366
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
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:76
virtual void writeIO(word port, byte value, EmuTime::param time)
Write a byte to a given IO port at a certain time to this device.
Definition: MSXDevice.cc:404
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:49
size_t size() const
MSXCPU & getCPU() const
Definition: MSXDevice.cc:137
Scheduler & getScheduler() const
Definition: MSXDevice.cc:145
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:274
CommandController & getCommandController() const
Definition: MSXDevice.cc:157
std::vector< MSXDevice * > Devices
Definition: MSXDevice.hh:37
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:275
const HardwareConfig & getHardwareConfig() const
Returns the hardwareconfig this device belongs to.
Definition: MSXDevice.hh:43
PluggingController & getPluggingController() const
Definition: MSXDevice.cc:165
MSXCPUInterface & getCPUInterface() const
Definition: MSXDevice.cc:141
const XMLElement * getXML() const
Definition: DeviceConfig.hh:54
virtual byte peekIO(word port, EmuTime::param time) const
Read a byte from a given IO port.
Definition: MSXDevice.cc:409
virtual void reset(EmuTime::param time)
This method is called on reset.
Definition: MSXDevice.cc:356
virtual void getNameList(TclObject &result) const
Returns list of name(s) of this device.
Definition: MSXDevice.cc:381
const XMLElement & getDeviceConfig() const
Get the configuration section for this device.
Definition: MSXDevice.hh:218
void getVisibleMemRegion(unsigned &base, unsigned &size) const
Returns the range where this device is visible in memory.
Definition: MSXDevice.cc:302
void testRemove(Devices alreadyRemoved) const
Checks whether this device can be removed (no other device has a reference to it).
Definition: MSXDevice.cc:81
MSXDevice(const MSXDevice &)=delete
void invalidateMemCache(word start, unsigned size)
Invalidate CPU memory-mapping cache.
Definition: MSXDevice.cc:460
virtual ~MSXDevice()=0
Definition: MSXDevice.cc:59
Reactor & getReactor() const
Definition: MSXDevice.cc:153