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{
62protected:
64 : motherBoard(motherBoard_)
65 {
66 auto& mapperIO = motherBoard.createMapperIO();
67 mapperIO.registerMapper(this);
68 }
69
71 {
72 auto& mapperIO = motherBoard.getMapperIO();
73 mapperIO.unregisterMapper(this);
74 motherBoard.destroyMapperIO();
75 }
76
77private:
78 MSXMotherBoard& motherBoard;
79};
80
81} // namespace openmsx
82
83#endif
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:36
MSXMapperIOClient(MSXMotherBoard &motherBoard_)
Definition: MSXMapperIO.hh:63
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