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  unsigned getBaseSizeAlignment() const override;
21  byte readMem(word address, EmuTime::param time) override;
22  byte peekMem(word address, EmuTime::param time) const override;
23  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  const byte* bankPtr[NUM_BANKS];
83  std::unique_ptr<SRAM> sram; // can be nullptr
85 
86 private:
87  RomBlockDebuggable romBlockDebug;
88  const byte* extraMem;
89  unsigned extraSize;
90  /*const*/ unsigned nrBlocks;
91  int blockMask;
92 };
93 
97 
98 REGISTER_BASE_CLASS(Rom4kBBlocks, "Rom4kBBlocks");
99 REGISTER_BASE_CLASS(Rom8kBBlocks, "Rom8kBBlocks");
100 REGISTER_BASE_CLASS(Rom16kBBlocks, "Rom16kBBlocks");
101 
102 // TODO see comment in .cc
103 //SERIALIZE_CLASS_VERSION(Rom4kBBlocks, 2);
104 //SERIALIZE_CLASS_VERSION(Rom8kBBlocks, 2);
105 //SERIALIZE_CLASS_VERSION(Rom16kBBlocks, 2);
106 
107 } // namespace openmsx
108 
109 #endif
openmsx::RomBlocks::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
serialize_meta.hh
openmsx::RomBlocks::setBank
void setBank(byte region, const byte *adr, int block)
Sets the memory visible for reading in a certain region.
Definition: RomBlocks.cc:77
openmsx::RomBlocks::setExtraMemory
void setExtraMemory(const byte *mem, unsigned size)
Inform this base class of extra mapable memory block.
Definition: RomBlocks.cc:97
openmsx::RomBlocks::sram
std::unique_ptr< SRAM > sram
Definition: RomBlocks.hh:83
openmsx::REGISTER_BASE_CLASS
REGISTER_BASE_CLASS(Connector, "Connector")
openmsx::RomBlocks::bankPtr
const byte * bankPtr[NUM_BANKS]
Definition: RomBlocks.hh:82
openmsx::RomBlocks::~RomBlocks
~RomBlocks() override
openmsx::MSXRom
Definition: MSXRom.hh:9
openmsx::SRAM
SRAM
Definition: SRAM.cc:150
openmsx::RomBlocks::NUM_BANKS
static constexpr unsigned NUM_BANKS
Definition: RomBlocks.hh:17
openmsx::RomBlocks::getReadCacheLine
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
MSXRom.hh
openmsx::RomBlocks::setRom
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
openmsx::RomBlocks::setUnmapped
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
openmsx::RomBlocks
Definition: RomBlocks.hh:13
openmsx::MSXRom::rom
Rom rom
Definition: MSXRom.hh:20
openmsx::Rom
Definition: Rom.hh:20
openmsx::RomBlocks::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomBlocks.cc:120
openmsx::RomBlocks::readMem
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
openmsx::RomBlockDebuggable
Definition: RomBlockDebuggable.hh:25
RomBlockDebuggable.hh
openmsx::RomBlocks::BANK_SIZE
static constexpr unsigned BANK_SIZE
Definition: RomBlocks.hh:16
openmsx::RomBlocks::BANK_MASK
static constexpr unsigned BANK_MASK
Definition: RomBlocks.hh:18
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomBlocks::setBlockMask
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition: RomBlocks.hh:73
openmsx::mask
constexpr nibble mask[4][13]
Definition: RP5C01.cc:33
openmsx::RomBlocks::getBaseSizeAlignment
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
Definition: RomBlocks.cc:53
openmsx::RomBlocks::RomBlocks
RomBlocks(const DeviceConfig &config, Rom &&rom, unsigned debugBankSizeShift=0)
Constructor.
Definition: RomBlocks.cc:14
openmsx::RomBlocks::blockNr
byte blockNr[NUM_BANKS]
Definition: RomBlocks.hh:84
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5