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 <array>
8#include <vector>
9
10namespace openmsx {
11
13{
14 [[nodiscard]] virtual byte readIO(word port, EmuTime::param time) = 0;
15 [[nodiscard]] virtual byte peekIO(word port, EmuTime::param time) const = 0;
16 virtual void writeIO(word port, byte value, EmuTime::param time) = 0;
17 [[nodiscard]] virtual byte getSelectedSegment(byte page) const = 0;
18protected:
20};
21
22
23class MSXMapperIO final : public MSXDevice
24{
25public:
26 enum class Mode { INTERNAL, EXTERNAL };
27
28public:
29 explicit MSXMapperIO(const DeviceConfig& config);
30
31 void setMode(Mode mode, byte mask, byte baseValue);
32
33 [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
34 [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
35 void writeIO(word port, byte value, EmuTime::param time) override;
36
39
40 template<typename Archive>
41 void serialize(Archive& ar, unsigned version);
42
43private:
44 struct Debuggable final : SimpleDebuggable {
45 Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
46 [[nodiscard]] byte read(unsigned address) override;
47 void write(unsigned address, byte value, EmuTime::param time) override;
48 } debuggable;
49
50 std::vector<MSXMemoryMapperInterface*> mappers;
51
52 std::array<byte, 4> registers; // (copy of) the mapper register state
53 byte mask; // bitmask: 1-bit -> take mapper register, 0-bit -> take baseValue
54 byte baseValue = 0xff;
55 Mode mode = Mode::EXTERNAL; // use the internal or the external mapper state
56};
58
59
61{
62public:
67
68protected:
69 explicit MSXMapperIOClient(MSXMotherBoard& motherBoard_)
70 : motherBoard(motherBoard_)
71 {
72 auto& mapperIO = motherBoard.createMapperIO();
73 mapperIO.registerMapper(this);
74 }
75
77 {
78 auto& mapperIO = motherBoard.getMapperIO();
79 mapperIO.unregisterMapper(this);
80 motherBoard.destroyMapperIO();
81 }
82
83private:
84 MSXMotherBoard& motherBoard;
85};
86
87} // namespace openmsx
88
89#endif
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
MSXMapperIOClient(const MSXMapperIOClient &)=delete
MSXMapperIOClient & operator=(const MSXMapperIOClient &)=delete
MSXMapperIOClient & operator=(MSXMapperIOClient &&)=delete
MSXMapperIOClient(MSXMapperIOClient &&)=delete
MSXMapperIOClient(MSXMotherBoard &motherBoard_)
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void registerMapper(MSXMemoryMapperInterface *mapper)
void serialize(Archive &ar, unsigned version)
void unregisterMapper(MSXMemoryMapperInterface *mapper)
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.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void setMode(Mode mode, byte mask, byte baseValue)
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:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)
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