openMSX
RomBlocks.hh
Go to the documentation of this file.
1#ifndef ROMBLOCKS_HH
2#define ROMBLOCKS_HH
3
4#include "MSXRom.hh"
6#include "serialize_meta.hh"
7#include <array>
8
9namespace openmsx {
10
11class SRAM;
12
13template<unsigned BANK_SIZE_>
14class RomBlocks : public MSXRom
15{
16public:
17 static constexpr unsigned BANK_SIZE = BANK_SIZE_;
18 static constexpr unsigned NUM_BANKS = 0x10000 / BANK_SIZE;
19 static constexpr unsigned BANK_MASK = BANK_SIZE - 1;
20
21 [[nodiscard]] unsigned getBaseSizeAlignment() const override;
22 [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
23 [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
24 [[nodiscard]] const byte* getReadCacheLine(word address) const override;
25
26 template<typename Archive>
27 void serialize(Archive& ar, unsigned version);
28
29protected:
42 RomBlocks(const DeviceConfig& config, Rom&& rom,
43 unsigned debugBankSizeShift = 0);
44 ~RomBlocks() override;
45
49 void setUnmapped(unsigned region);
50
57 void setBank(unsigned region, const byte* adr, byte block);
58
65 void setRom(unsigned region, unsigned block);
66
74 void setBlockMask(int mask) { blockMask = mask; }
75
81 void setExtraMemory(std::span<const byte> mem);
82
83protected:
84 std::array<const byte*, NUM_BANKS> bankPtr;
85 std::unique_ptr<SRAM> sram; // can be nullptr
86 std::array<byte, NUM_BANKS> blockNr;
87
88private:
89 RomBlockDebuggable romBlockDebug;
90 std::span<const byte> extraMem;
91 /*const*/ unsigned nrBlocks;
92 int blockMask;
93};
94
98
102
103// TODO see comment in .cc
104//SERIALIZE_CLASS_VERSION(Rom4kBBlocks, 2);
105//SERIALIZE_CLASS_VERSION(Rom8kBBlocks, 2);
106//SERIALIZE_CLASS_VERSION(Rom16kBBlocks, 2);
107
108} // namespace openmsx
109
110#endif
void setBank(unsigned region, const byte *adr, byte block)
Sets the memory visible for reading in a certain region.
Definition RomBlocks.cc:78
void setUnmapped(unsigned region)
Select 'unmapped' memory for this region.
Definition RomBlocks.cc:92
void setExtraMemory(std::span< const byte > mem)
Inform this base class of extra mappable memory block.
Definition RomBlocks.cc:98
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition RomBlocks.cc:60
static constexpr unsigned NUM_BANKS
Definition RomBlocks.hh:18
std::unique_ptr< SRAM > sram
Definition RomBlocks.hh:85
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition RomBlocks.cc:66
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition RomBlocks.hh:74
static constexpr unsigned BANK_MASK
Definition RomBlocks.hh:19
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
Definition RomBlocks.cc:54
void setRom(unsigned region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition RomBlocks.cc:104
void serialize(Archive &ar, unsigned version)
Definition RomBlocks.cc:121
~RomBlocks() override
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition RomBlocks.cc:72
static constexpr unsigned BANK_SIZE
Definition RomBlocks.hh:17
std::array< byte, NUM_BANKS > blockNr
Definition RomBlocks.hh:86
std::array< const byte *, NUM_BANKS > bankPtr
Definition RomBlocks.hh:84
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define REGISTER_BASE_CLASS(CLASS, NAME)