| e8555c89 Andy McCall |
1 |
#ifndef RAM_HH |
| 2 |
#define RAM_HH |
| 3 |
|
| 4 |
#include "SimpleDebuggable.hh" |
| 5 |
|
| 6 |
#include "MemBuffer.hh" |
| 7 |
#include "static_string_view.hh" |
| 8 |
|
| 9 |
#include <cstdint> |
| 10 |
#include <optional> |
| 11 |
#include <string> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
class XMLElement; |
| 16 |
class DeviceConfig; |
| 17 |
class Ram; |
| 18 |
|
| 19 |
class RamDebuggable final : public SimpleDebuggable |
| 20 |
{ |
| 21 |
public: |
| 22 |
RamDebuggable(MSXMotherBoard& motherBoard, const std::string& name, |
| 23 |
static_string_view description, Ram& ram, bool* debugWrite); |
| 24 |
uint8_t read(unsigned address) override; |
| 25 |
void write(unsigned address, uint8_t value) override; |
| 26 |
void readBlock(unsigned start, std::span<uint8_t> output) override; |
| 27 |
private: |
| 28 |
Ram& ram; |
| 29 |
bool* debugWrite; |
| 30 |
}; |
| 31 |
|
| 32 |
class Ram |
| 33 |
{ |
| 34 |
public: |
| 35 |
|
| 36 |
Ram(const DeviceConfig& config, const std::string& name, |
| 37 |
static_string_view description, size_t size, bool* debugWrite = nullptr); |
| 38 |
|
| 39 |
|
| 40 |
Ram(const XMLElement& xml, size_t size); |
| 41 |
|
| 42 |
[[nodiscard]] const uint8_t& operator[](size_t addr) const { |
| 43 |
return ram[addr]; |
| 44 |
} |
| 45 |
[[nodiscard]] uint8_t& operator[](size_t addr) { |
| 46 |
return ram[addr]; |
| 47 |
} |
| 48 |
[[nodiscard]] auto size() const { return ram.size(); } |
| 49 |
[[nodiscard]] auto data() { return ram.data(); } |
| 50 |
[[nodiscard]] auto data() const { return ram.data(); } |
| 51 |
[[nodiscard]] auto begin() { return ram.begin(); } |
| 52 |
[[nodiscard]] auto begin() const { return ram.begin(); } |
| 53 |
[[nodiscard]] auto end() { return ram.end(); } |
| 54 |
[[nodiscard]] auto end() const { return ram.end(); } |
| 55 |
|
| 56 |
[[nodiscard]] const std::string& getName() const; |
| 57 |
void clear(uint8_t c = 0xff); |
| 58 |
|
| 59 |
template<typename Archive> |
| 60 |
void serialize(Archive& ar, unsigned version); |
| 61 |
|
| 62 |
private: |
| 63 |
const XMLElement& xml; |
| 64 |
MemBuffer<uint8_t> ram; |
| 65 |
const std::optional<RamDebuggable> debuggable; |
| 66 |
bool dummyDebugWrite = false; |
| 67 |
}; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
#endif |