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  [[nodiscard]] virtual byte readIO(word port, EmuTime::param time) = 0;
14  [[nodiscard]] virtual byte peekIO(word port, EmuTime::param time) const = 0;
15  virtual void writeIO(word port, byte value, EmuTime::param time) = 0;
16  [[nodiscard]] virtual byte getSelectedSegment(byte page) const = 0;
17 protected:
19 };
20 
21 
22 class MSXMapperIO final : public MSXDevice
23 {
24 public:
25  enum class Mode { INTERNAL, EXTERNAL };
26 
27 public:
28  explicit MSXMapperIO(const DeviceConfig& config);
29 
30  void setMode(Mode mode, byte mask, byte baseValue);
31 
32  [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
33  [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
34  void writeIO(word port, byte value, EmuTime::param time) override;
35 
38 
39  template<typename Archive>
40  void serialize(Archive& ar, unsigned version);
41 
42 private:
43  struct Debuggable final : SimpleDebuggable {
44  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
45  [[nodiscard]] byte read(unsigned address) override;
46  void write(unsigned address, byte value, EmuTime::param time) override;
47  } debuggable;
48 
49  std::vector<MSXMemoryMapperInterface*> mappers;
50 
51  byte registers[4]; // (copy of) the mapper register state
52  byte mask; // bitmask: 1-bit -> take mapper register, 0-bit -> take baseValue
53  byte baseValue = 0xff;
54  Mode mode = Mode::EXTERNAL; // use the internal or the external mapper state
55 };
57 
58 
60 {
61 protected:
63  : motherBoard(motherBoard_)
64  {
65  auto& mapperIO = motherBoard.createMapperIO();
66  mapperIO.registerMapper(this);
67  }
68 
70  {
71  auto& mapperIO = motherBoard.getMapperIO();
72  mapperIO.unregisterMapper(this);
73  motherBoard.destroyMapperIO();
74  }
75 
76 private:
77  MSXMotherBoard& motherBoard;
78 };
79 
80 } // namespace openmsx
81 
82 #endif
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:33
MSXMapperIOClient(MSXMotherBoard &motherBoard_)
Definition: MSXMapperIO.hh:62
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMapperIO.cc:73
void registerMapper(MSXMemoryMapperInterface *mapper)
Definition: MSXMapperIO.cc:47
MSXMapperIO(const DeviceConfig &config)
Definition: MSXMapperIO.cc:32
void serialize(Archive &ar, unsigned version)
Definition: MSXMapperIO.cc:127
void unregisterMapper(MSXMemoryMapperInterface *mapper)
Definition: MSXMapperIO.cc:52
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: MSXMapperIO.cc:89
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXMapperIO.cc:57
void setMode(Mode mode, byte mask, byte baseValue)
Definition: MSXMapperIO.cc:40
MSXMapperIO & getMapperIO() const
MSXMapperIO & createMapperIO()
All memory mappers in one MSX machine share the same four (logical) memory mapper registers.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
virtual byte readIO(word port, EmuTime::param time)=0
virtual byte getSelectedSegment(byte page) const =0
virtual void writeIO(word port, byte value, EmuTime::param time)=0
virtual byte peekIO(word port, EmuTime::param time) const =0