| e8555c89 Andy McCall |
1 |
#ifndef MSXMEMORYMAPPERBASE_HH |
| 2 |
#define MSXMEMORYMAPPERBASE_HH |
| 3 |
|
| 4 |
#include "CheckedRam.hh" |
| 5 |
|
| 6 |
#include "MSXDevice.hh" |
| 7 |
#include "MSXMapperIO.hh" |
| 8 |
#include "SimpleDebuggable.hh" |
| 9 |
|
| 10 |
#include "narrow.hh" |
| 11 |
|
| 12 |
#include <array> |
| 13 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
class MSXMemoryMapperBase : public MSXDevice, public MSXMapperIOClient |
| 17 |
{ |
| 18 |
public: |
| 19 |
explicit MSXMemoryMapperBase(const DeviceConfig& config); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
[[nodiscard]] byte getSelectedSegment(byte page) const override { return registers[page]; } |
| 26 |
|
| 27 |
[[nodiscard]] unsigned getSizeInBlocks() const { |
| 28 |
return narrow<unsigned>(checkedRam.size() / 0x4000); |
| 29 |
} |
| 30 |
|
| 31 |
void reset(EmuTime time) override; |
| 32 |
void powerUp(EmuTime time) override; |
| 33 |
[[nodiscard]] byte readIO(uint16_t port, EmuTime time) override; |
| 34 |
[[nodiscard]] byte peekIO(uint16_t port, EmuTime time) const override; |
| 35 |
[[nodiscard]] byte readMem(uint16_t address, EmuTime time) override; |
| 36 |
void writeMem(uint16_t address, byte value, EmuTime time) override; |
| 37 |
[[nodiscard]] const byte* getReadCacheLine(uint16_t start) const override; |
| 38 |
[[nodiscard]] byte* getWriteCacheLine(uint16_t start) override; |
| 39 |
[[nodiscard]] byte peekMem(uint16_t address, EmuTime time) const override; |
| 40 |
[[nodiscard]] unsigned getBaseSizeAlignment() const override; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
void writeIO(uint16_t port, byte value, EmuTime time) override = 0; |
| 46 |
|
| 47 |
template<typename Archive> |
| 48 |
void serialize(Archive& ar, unsigned version); |
| 49 |
|
| 50 |
protected: |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
[[nodiscard]] unsigned calcAddress(uint16_t address) const; |
| 56 |
[[nodiscard]] unsigned segmentOffset(byte page) const; |
| 57 |
|
| 58 |
void writeIOImpl(uint16_t port, byte value, EmuTime time); |
| 59 |
|
| 60 |
CheckedRam checkedRam; |
| 61 |
std::array<byte, 4> registers; |
| 62 |
|
| 63 |
private: |
| 64 |
struct Debuggable final : SimpleDebuggable { |
| 65 |
Debuggable(MSXMotherBoard& motherBoard, const std::string& name); |
| 66 |
[[nodiscard]] byte read(unsigned address) override; |
| 67 |
void write(unsigned address, byte value) override; |
| 68 |
void readBlock(unsigned start, std::span<byte> output) override; |
| 69 |
} debuggable; |
| 70 |
}; |
| 71 |
SERIALIZE_CLASS_VERSION(MSXMemoryMapperBase, 2); |
| 72 |
|
| 73 |
REGISTER_BASE_NAME_HELPER(MSXMemoryMapperBase, "MemoryMapper"); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
#endif |