openMSX
RomBlocks.hh
Go to the documentation of this file.
1 #ifndef ROMBLOCKS_HH
2 #define ROMBLOCKS_HH
3 
4 #include "MSXRom.hh"
5 #include "RomBlockDebuggable.hh"
6 #include "serialize_meta.hh"
7 
8 namespace openmsx {
9 
10 class SRAM;
11 
12 template<unsigned BANK_SIZE_>
13 class RomBlocks : public MSXRom
14 {
15 public:
16  static constexpr unsigned BANK_SIZE = BANK_SIZE_;
17  static constexpr unsigned NUM_BANKS = 0x10000 / BANK_SIZE;
18  static constexpr unsigned BANK_MASK = BANK_SIZE - 1;
19 
20  [[nodiscard]] unsigned getBaseSizeAlignment() const override;
21  [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
22  [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
23  [[nodiscard]] const byte* getReadCacheLine(word address) const override;
24 
25  template<typename Archive>
26  void serialize(Archive& ar, unsigned version);
27 
28 protected:
41  RomBlocks(const DeviceConfig& config, Rom&& rom,
42  unsigned debugBankSizeShift = 0);
43  ~RomBlocks() override;
44 
48  void setUnmapped(byte region);
49 
56  void setBank(byte region, const byte* adr, int block);
57 
64  void setRom(byte region, unsigned block);
65 
73  void setBlockMask(int mask) { blockMask = mask; }
74 
80  void setExtraMemory(const byte* mem, unsigned size);
81 
82 protected:
83  const byte* bankPtr[NUM_BANKS];
84  std::unique_ptr<SRAM> sram; // can be nullptr
86 
87 private:
88  RomBlockDebuggable romBlockDebug;
89  const byte* extraMem;
90  unsigned extraSize;
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
byte blockNr[NUM_BANKS]
Definition: RomBlocks.hh:85
void setExtraMemory(const byte *mem, unsigned size)
Inform this base class of extra mapable memory block.
Definition: RomBlocks.cc:98
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:60
void setBank(byte region, const byte *adr, int block)
Sets the memory visible for reading in a certain region.
Definition: RomBlocks.cc:78
static constexpr unsigned NUM_BANKS
Definition: RomBlocks.hh:17
std::unique_ptr< SRAM > sram
Definition: RomBlocks.hh:84
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:73
static constexpr unsigned BANK_MASK
Definition: RomBlocks.hh:18
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
Definition: RomBlocks.cc:54
void serialize(Archive &ar, unsigned version)
Definition: RomBlocks.cc:121
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:105
~RomBlocks() override
const byte * bankPtr[NUM_BANKS]
Definition: RomBlocks.hh:83
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:16
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:92
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
constexpr nibble mask[4][13]
Definition: RP5C01.cc:34
SRAM
Definition: SRAM.cc:147
REGISTER_BASE_CLASS(Connector, "Connector")
size_t size(std::string_view utf8)