openMSX
TrackedRam.hh
Go to the documentation of this file.
1#ifndef TRACKED_RAM_HH
2#define TRACKED_RAM_HH
3
4#include "Ram.hh"
5
6namespace openmsx {
7
8// Ram with dirty tracking
10{
11public:
12 // Most methods simply delegate to the internal 'ram' object.
13 TrackedRam(const DeviceConfig& config, const std::string& name,
14 static_string_view description, size_t size)
15 : ram(config, name, description, size) {}
16
17 TrackedRam(const XMLElement& xml, size_t size)
18 : ram(xml, size) {}
19
20 [[nodiscard]] size_t size() const {
21 return ram.size();
22 }
23
24 [[nodiscard]] const std::string& getName() const {
25 return ram.getName();
26 }
27
28 // Allow read via an explicit read() method or via backdoor access.
29 [[nodiscard]] byte read(size_t addr) const {
30 return ram[addr];
31 }
32
33 [[nodiscard]] const byte& operator[](size_t addr) const {
34 return ram[addr];
35 }
36
37 [[nodiscard]] auto begin() const { return ram.begin(); }
38 [[nodiscard]] auto end() const { return ram.end(); }
39
40 // Only allow write/clear via an explicit method.
41 void write(size_t addr, byte value) {
42 writeSinceLastReverseSnapshot = true;
43 ram[addr] = value;
44 }
45
46 void clear(byte c = 0xff) {
47 writeSinceLastReverseSnapshot = true;
48 ram.clear(c);
49 }
50
51 // Some write operations are more efficient in bulk. For those this
52 // method can be used. It will mark the ram as dirty on each
53 // invocation, so the resulting pointer (although the same each time)
54 // should not be reused for multiple (distinct) bulk write operations.
55 [[nodiscard]] std::span<byte> getWriteBackdoor() {
56 writeSinceLastReverseSnapshot = true;
57 return {ram.data(), size()};
58 }
59
60 template<typename Archive>
61 void serialize(Archive& ar, unsigned version);
62
63private:
64 Ram ram;
65 bool writeSinceLastReverseSnapshot = true;
66};
67
68} // namespace openmsx
69
70#endif
auto size() const
Definition Ram.hh:44
auto end()
Definition Ram.hh:49
auto data()
Definition Ram.hh:45
auto begin()
Definition Ram.hh:47
void clear(byte c=0xff)
Definition Ram.cc:35
const std::string & getName() const
Definition Ram.cc:78
byte read(size_t addr) const
Definition TrackedRam.hh:29
const std::string & getName() const
Definition TrackedRam.hh:24
auto end() const
Definition TrackedRam.hh:38
void clear(byte c=0xff)
Definition TrackedRam.hh:46
const byte & operator[](size_t addr) const
Definition TrackedRam.hh:33
TrackedRam(const DeviceConfig &config, const std::string &name, static_string_view description, size_t size)
Definition TrackedRam.hh:13
void write(size_t addr, byte value)
Definition TrackedRam.hh:41
TrackedRam(const XMLElement &xml, size_t size)
Definition TrackedRam.hh:17
std::span< byte > getWriteBackdoor()
Definition TrackedRam.hh:55
auto begin() const
Definition TrackedRam.hh:37
void serialize(Archive &ar, unsigned version)
Definition TrackedRam.cc:7
size_t size() const
Definition TrackedRam.hh:20
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:9