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  void invalidateMemCache(word start, unsigned size);
204 
208 
212  const XMLElement& getDeviceConfig() const {
213  return *deviceConfig.getXML();
214  }
215  const DeviceConfig& getDeviceConfig2() const { // TODO
216  return deviceConfig;
217  }
218 
221  const Devices& getReferences() const;
222 
223  // convenience functions, these delegate to MSXMotherBoard
225  MSXCPU& getCPU() const;
227  Scheduler& getScheduler() const;
228  CliComm& getCliComm() const;
229  Reactor& getReactor() const;
232  LedStatus& getLedStatus() const;
233 
234  template<typename Archive>
235  void serialize(Archive& ar, unsigned version);
236 
237 protected:
243  MSXDevice(const DeviceConfig& config, const std::string& name);
244  explicit MSXDevice(const DeviceConfig& config);
245 
257  friend class DeviceFactory;
258  virtual void init();
259 
264  virtual void getExtraDeviceInfo(TclObject& result) const;
265 
266 public:
267  // public to allow non-MSXDevices to use these same arrays
268  static byte unmappedRead [0x10000]; // Read only
269  static byte unmappedWrite[0x10000]; // Write only
270 
271 private:
272  void initName(const std::string& name);
273  void staticInit();
274 
275  void lockDevices();
276  void unlockDevices();
277 
278  void registerSlots();
279  void unregisterSlots();
280 
281  void registerPorts();
282  void unregisterPorts();
283 
284  using MemRegions = std::vector<std::pair<unsigned, unsigned>>;
285  MemRegions memRegions;
286  std::vector<byte> inPorts;
287  std::vector<byte> outPorts;
288 
289  DeviceConfig deviceConfig;
290  std::string deviceName;
291 
292  Devices references;
293  Devices referencedBy;
294 
295  int ps;
296  int ss;
297 };
298 
300 
301 #define REGISTER_MSXDEVICE(CLASS, NAME) \
302 REGISTER_POLYMORPHIC_INITIALIZER(MSXDevice, CLASS, NAME);
303 
304 } // namespace openmsx
305 
306 #endif
virtual void init()
Definition: MSXDevice.cc:51
const DeviceConfig & getDeviceConfig2() const
Definition: MSXDevice.hh:215
Contains the main loop of openMSX.
Definition: Reactor.hh:61
virtual byte * getWriteCacheLine(word start) const
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
Definition: MSXDevice.cc:447
CliComm & getCliComm() const
Definition: MSXDevice.cc:151
REGISTER_BASE_NAME_HELPER(MSXFDC, "FDC")
const Devices & getReferences() const
Get the device references that are specified for this device.
Definition: MSXDevice.cc:129
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:412
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:423
virtual void globalWrite(word address, byte value, EmuTime::param time)
Global writes.
Definition: MSXDevice.cc:441
virtual byte readIRQVector()
Gets IRQ vector used in IM2.
Definition: MSXDevice.cc:358
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:373
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:395
Central administration of Connectors and Pluggables.
MSXDevice & operator=(const MSXDevice &)=delete
void serialize(Archive &ar, unsigned version)
Definition: MSXDevice.cc:458
void getDeviceInfo(TclObject &result) const
Get device info.
Definition: MSXDevice.cc:383
virtual void powerUp(EmuTime::param time)
This method is called when MSX is powered up.
Definition: MSXDevice.cc:368
virtual byte peekMem(word address, EmuTime::param time) const
Read a byte from a given memory location.
Definition: MSXDevice.cc:429
virtual void getExtraDeviceInfo(TclObject &result) const
Definition: MSXDevice.cc:389
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:135
LedStatus & getLedStatus() const
Definition: MSXDevice.cc:163
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:418
virtual void powerDown(EmuTime::param time)
This method is called when MSX is powered down.
Definition: MSXDevice.cc:363
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:77
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:401
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:49
size_t size() const
MSXCPU & getCPU() const
Definition: MSXDevice.cc:139
Scheduler & getScheduler() const
Definition: MSXDevice.cc:147
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:268
CommandController & getCommandController() const
Definition: MSXDevice.cc:159
std::vector< MSXDevice * > Devices
Definition: MSXDevice.hh:37
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:269
const HardwareConfig & getHardwareConfig() const
Returns the hardwareconfig this device belongs to.
Definition: MSXDevice.hh:43
PluggingController & getPluggingController() const
Definition: MSXDevice.cc:167
MSXCPUInterface & getCPUInterface() const
Definition: MSXDevice.cc:143
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:406
virtual void reset(EmuTime::param time)
This method is called on reset.
Definition: MSXDevice.cc:353
virtual void getNameList(TclObject &result) const
Returns list of name(s) of this device.
Definition: MSXDevice.cc:378
const XMLElement & getDeviceConfig() const
Get the configuration section for this device.
Definition: MSXDevice.hh:212
void getVisibleMemRegion(unsigned &base, unsigned &size) const
Returns the range where this device is visible in memory.
Definition: MSXDevice.cc:299
void testRemove(Devices alreadyRemoved) const
Checks whether this device can be removed (no other device has a reference to it).
Definition: MSXDevice.cc:82
MSXDevice(const MSXDevice &)=delete
void invalidateMemCache(word start, unsigned size)
Invalidate CPU memory-mapping cache.
Definition: MSXDevice.cc:452
virtual ~MSXDevice()=0
Definition: MSXDevice.cc:60
Reactor & getReactor() const
Definition: MSXDevice.cc:155