openMSX
MSXMapperIO.hh
Go to the documentation of this file.
1 #ifndef MSXMAPPERIO_HH
2 #define MSXMAPPERIO_HH
3 
4 #include "MSXDevice.hh"
5 #include "MSXMotherBoard.hh"
6 #include "SimpleDebuggable.hh"
7 #include <vector>
8 
9 namespace openmsx {
10 
12 {
13  virtual byte readIO(word port, EmuTime::param time) = 0;
14  virtual byte peekIO(word port, EmuTime::param time) const = 0;
15  virtual void writeIO(word port, byte value, EmuTime::param time) = 0;
16  virtual byte getSelectedSegment(byte page) const = 0;
17 protected:
18  ~MSXMemoryMapperInterface() = default;
19 };
20 
21 
22 class MSXMapperIO final : public MSXDevice
23 {
24 public:
25  explicit MSXMapperIO(const DeviceConfig& config);
26 
27  byte readIO(word port, EmuTime::param time) override;
28  byte peekIO(word port, EmuTime::param time) const override;
29  void writeIO(word port, byte value, EmuTime::param time) override;
30 
31  void registerMapper(MSXMemoryMapperInterface* mapper);
32  void unregisterMapper(MSXMemoryMapperInterface* mapper);
33 
34  template<typename Archive>
35  void serialize(Archive& ar, unsigned version);
36 
37 private:
38  struct Debuggable final : SimpleDebuggable {
39  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
40  byte read(unsigned address) override;
41  void write(unsigned address, byte value, EmuTime::param time) override;
42  } debuggable;
43 
44  std::vector<MSXMemoryMapperInterface*> mappers;
45 
50  byte mask;
51 };
53 
54 
56 {
57 protected:
59  : motherBoard(motherBoard_)
60  {
61  auto& mapperIO = motherBoard.createMapperIO();
62  mapperIO.registerMapper(this);
63  }
64 
66  {
67  auto& mapperIO = motherBoard.getMapperIO();
68  mapperIO.unregisterMapper(this);
69  motherBoard.destroyMapperIO();
70  }
71 
72 private:
73  MSXMotherBoard& motherBoard;
74 };
75 
76 } // namespace openmsx
77 
78 #endif
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
virtual void writeIO(word port, byte value, EmuTime::param time)=0
virtual byte readIO(word port, EmuTime::param time)=0
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
MSXMapperIOClient(MSXMotherBoard &motherBoard_)
Definition: MSXMapperIO.hh:58
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
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
constexpr nibble mask[4][13]
Definition: RP5C01.cc:33
virtual byte getSelectedSegment(byte page) const =0
void serialize(Archive &ar, T &t, unsigned version)
virtual byte peekIO(word port, EmuTime::param time) const =0