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 const unsigned BANK_SIZE = BANK_SIZE_;
17  static const unsigned NUM_BANKS = 0x10000 / BANK_SIZE;
18  static const unsigned BANK_MASK = BANK_SIZE - 1;
19 
20  byte readMem(word address, EmuTime::param time) override;
21  byte peekMem(word address, EmuTime::param time) const override;
22  const byte* getReadCacheLine(word address) const override;
23 
24  template<typename Archive>
25  void serialize(Archive& ar, unsigned version);
26 
27 protected:
40  RomBlocks(const DeviceConfig& config, Rom&& rom,
41  unsigned debugBankSizeShift = 0);
42  ~RomBlocks() override;
43 
47  void setUnmapped(byte region);
48 
55  void setBank(byte region, const byte* adr, int block);
56 
63  void setRom(byte region, unsigned block);
64 
72  void setBlockMask(int mask) { blockMask = mask; }
73 
79  void setExtraMemory(const byte* mem, unsigned size);
80 
82  std::unique_ptr<SRAM> sram; // can be nullptr
84 
85 private:
86  RomBlockDebuggable romBlockDebug;
87  const byte* extraMem;
88  unsigned extraSize;
89  /*const*/ unsigned nrBlocks;
90  int blockMask;
91 };
92 
96 
97 REGISTER_BASE_CLASS(Rom4kBBlocks, "Rom4kBBlocks");
98 REGISTER_BASE_CLASS(Rom8kBBlocks, "Rom8kBBlocks");
99 REGISTER_BASE_CLASS(Rom16kBBlocks, "Rom16kBBlocks");
100 
101 // TODO see comment in .cc
102 //SERIALIZE_CLASS_VERSION(Rom4kBBlocks, 2);
103 //SERIALIZE_CLASS_VERSION(Rom8kBBlocks, 2);
104 //SERIALIZE_CLASS_VERSION(Rom16kBBlocks, 2);
105 
106 } // namespace openmsx
107 
108 #endif
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:98
REGISTER_BASE_CLASS(Connector, "Connector")
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void setBank(byte region, const byte *adr, int block)
Sets the memory visible for reading in a certain region.
Definition: RomBlocks.cc:71
SRAM
Definition: SRAM.cc:150
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:53
static const unsigned NUM_BANKS
Definition: RomBlocks.hh:17
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomBlocks.cc:59
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const byte * bankPtr[NUM_BANKS]
Definition: RomBlocks.hh:81
byte blockNr[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:65
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
~RomBlocks() override
static const unsigned BANK_SIZE
Definition: RomBlocks.hh:16
void setUnmapped(byte region)
Select &#39;unmapped&#39; memory for this region.
Definition: RomBlocks.cc:85
void serialize(Archive &ar, unsigned version)
Definition: RomBlocks.cc:114
std::unique_ptr< SRAM > sram
Definition: RomBlocks.hh:82
static const unsigned BANK_MASK
Definition: RomBlocks.hh:18
void setExtraMemory(const byte *mem, unsigned size)
Inform this base class of extra mapable memory block.
Definition: RomBlocks.cc:91
RomBlocks(const DeviceConfig &config, Rom &&rom, unsigned debugBankSizeShift=0)
Constructor.
Definition: RomBlocks.cc:14
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hh:62
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition: RomBlocks.hh:72