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(byte region);
50
57 void setBank(byte region, const byte* adr, byte block);
58
65 void setRom(byte 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 setExtraMemory(std::span< const byte > mem)
Inform this base class of extra mappable memory block.
Definition: RomBlocks.cc:97
RomBlocks(const DeviceConfig &config, Rom &&rom, unsigned debugBankSizeShift=0)
Constructor.
Definition: RomBlocks.cc:15
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
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:65
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:53
void serialize(Archive &ar, unsigned version)
Definition: RomBlocks.cc:119
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:103
void setBank(byte region, const byte *adr, byte block)
Sets the memory visible for reading in a certain region.
Definition: RomBlocks.cc:77
~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:71
static constexpr unsigned BANK_SIZE
Definition: RomBlocks.hh:17
std::array< byte, NUM_BANKS > blockNr
Definition: RomBlocks.hh:86
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
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
SRAM
Definition: SRAM.cc:145
REGISTER_BASE_CLASS(Connector, "Connector")