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