openMSX
RomBlockDebuggable.hh
Go to the documentation of this file.
1 #ifndef ROMBLOCKDEBUGGABLE_HH
2 #define ROMBLOCKDEBUGGABLE_HH
3 
4 #include "SimpleDebuggable.hh"
5 #include "MSXDevice.hh"
6 #include <string>
7 
8 namespace openmsx {
9 
11 {
12 public:
13  explicit RomBlockDebuggableBase(const MSXDevice& device)
15  device.getMotherBoard(),
16  device.getName() + " romblocks",
17  "Shows for each byte of the mapper which memory block is selected.",
18  0x10000)
19  {
20  }
21 protected:
22  ~RomBlockDebuggableBase() = default;
23 };
24 
26 {
27 public:
28  RomBlockDebuggable(const MSXDevice& device, const byte* blockNr_,
29  unsigned startAddress_, unsigned mappedSize_,
30  unsigned bankSizeShift_, unsigned debugShift_ = 0)
31  : RomBlockDebuggableBase(device)
32  , blockNr(blockNr_), startAddress(startAddress_)
33  , mappedSize(mappedSize_), bankSizeShift(bankSizeShift_)
34  , debugShift(debugShift_), debugMask(~((1 << debugShift) - 1))
35  {
36  }
37  RomBlockDebuggable(const MSXDevice& device, const byte* blockNr_,
38  unsigned startAddress_, unsigned mappedSize_,
39  unsigned bankSizeShift_, unsigned debugShift_,
40  unsigned debugMask_)
41  : RomBlockDebuggableBase(device)
42  , blockNr(blockNr_), startAddress(startAddress_)
43  , mappedSize(mappedSize_), bankSizeShift(bankSizeShift_)
44  , debugShift(debugShift_), debugMask(debugMask_)
45  {
46  }
47 
48  byte read(unsigned address) override
49  {
50  unsigned addr = address - startAddress;
51  if (addr < mappedSize) {
52  byte tmp = blockNr[(addr >> bankSizeShift) & debugMask];
53  return (tmp != 255) ? (tmp >> debugShift) : tmp;
54  } else {
55  return 255; // outside mapped address space
56  }
57  }
58 
59 private:
60  const byte* blockNr;
61  const unsigned startAddress;
62  const unsigned mappedSize;
63  const unsigned bankSizeShift;
64  const unsigned debugShift;
65  const unsigned debugMask;
66 };
67 
68 } // namespace openmsx
69 
70 #endif
RomBlockDebuggable(const MSXDevice &device, const byte *blockNr_, unsigned startAddress_, unsigned mappedSize_, unsigned bankSizeShift_, unsigned debugShift_=0)
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
byte read(unsigned address) override
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
MSXMotherBoard & getMotherBoard() const
const std::string & getName() const
RomBlockDebuggableBase(const MSXDevice &device)
RomBlockDebuggable(const MSXDevice &device, const byte *blockNr_, unsigned startAddress_, unsigned mappedSize_, unsigned bankSizeShift_, unsigned debugShift_, unsigned debugMask_)