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 <span>
7#include <string>
8
9namespace openmsx {
10
12{
13public:
14 explicit RomBlockDebuggableBase(const MSXDevice& device)
16 device.getMotherBoard(),
17 device.getName() + " romblocks",
18 "Shows for each byte of the mapper which memory block is selected.",
19 0x10000)
20 {
21 }
22
23 // For the 'Debuggable' interface we need to have an 8-bit read(). For most mappers that's sufficient.
24 [[nodiscard]] byte read(unsigned address) override {
25 return narrow_cast<byte>(readExt(address));
26 }
27
28 // To support larger than 8 bit segment numbers.
29 [[nodiscard]] virtual unsigned readExt(unsigned address) = 0;
30
31protected:
33};
34
35// Generic implementation. This (only) works when the segment numbers are stored
36// in some byte-array (so limited to 8-bit segment numbers).
38{
39public:
40 RomBlockDebuggable(const MSXDevice& device, std::span<const byte> blockNr_,
41 unsigned startAddress_, unsigned mappedSize_,
42 unsigned bankSizeShift_, unsigned debugShift_ = 0)
44 , blockNr(blockNr_.data()), startAddress(startAddress_)
45 , mappedSize(mappedSize_), bankSizeShift(bankSizeShift_)
46 , debugShift(debugShift_), debugMask(~((1 << debugShift) - 1))
47 {
48 assert((mappedSize >> bankSizeShift) == blockNr_.size()); // no need to include 'debugMask' here
49 }
50 RomBlockDebuggable(const MSXDevice& device, std::span<const byte> blockNr_,
51 unsigned startAddress_, unsigned mappedSize_,
52 unsigned bankSizeShift_, unsigned debugShift_,
53 unsigned debugMask_)
55 , blockNr(blockNr_.data()), startAddress(startAddress_)
56 , mappedSize(mappedSize_), bankSizeShift(bankSizeShift_)
57 , debugShift(debugShift_), debugMask(debugMask_)
58 {
59 assert(((mappedSize >> bankSizeShift) & debugMask) < blockNr_.size()); // here we do need 'debugMask'
60 }
61
62 [[nodiscard]] unsigned readExt(unsigned address) override
63 {
64 unsigned addr = address - startAddress;
65 if (addr < mappedSize) {
66 byte tmp = blockNr[(addr >> bankSizeShift) & debugMask];
67 return (tmp != 255) ? (tmp >> debugShift) : tmp;
68 } else {
69 return unsigned(-1); // outside mapped address space
70 }
71 }
72
73private:
74 const byte* blockNr;
75 const unsigned startAddress;
76 const unsigned mappedSize;
77 const unsigned bankSizeShift;
78 const unsigned debugShift;
79 const unsigned debugMask;
80};
81
82} // namespace openmsx
83
84#endif
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
byte read(unsigned address) override
RomBlockDebuggableBase(const MSXDevice &device)
virtual unsigned readExt(unsigned address)=0
unsigned readExt(unsigned address) override
RomBlockDebuggable(const MSXDevice &device, std::span< const byte > blockNr_, unsigned startAddress_, unsigned mappedSize_, unsigned bankSizeShift_, unsigned debugShift_=0)
RomBlockDebuggable(const MSXDevice &device, std::span< const byte > blockNr_, unsigned startAddress_, unsigned mappedSize_, unsigned bankSizeShift_, unsigned debugShift_, unsigned debugMask_)
const std::string & getName() const
MSXMotherBoard & getMotherBoard() const
This file implemented 3 utility functions:
Definition Autofire.cc:11