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, unsigned size)
15 : ram(config, name, description, size) {}
16
17 TrackedRam(const XMLElement& xml, unsigned size)
18 : ram(xml, size) {}
19
20 [[nodiscard]] unsigned getSize() const {
21 return ram.getSize();
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(unsigned addr) const {
30 return ram[addr];
31 }
32
33 [[nodiscard]] const byte& operator[](unsigned addr) const {
34 return ram[addr];
35 }
36
37 // Only allow write/clear via an explicit method.
38 void write(unsigned addr, byte value) {
39 writeSinceLastReverseSnapshot = true;
40 ram[addr] = value;
41 }
42
43 void clear(byte c = 0xff) {
44 writeSinceLastReverseSnapshot = true;
45 ram.clear(c);
46 }
47
48 // Some write operations are more efficient in bulk. For those this
49 // method can be used. It will mark the ram as dirty on each
50 // invocation, so the resulting pointer (although the same each time)
51 // should not be reused for multiple (distinct) bulk write operations.
52 [[nodiscard]] byte* getWriteBackdoor() {
53 writeSinceLastReverseSnapshot = true;
54 return &ram[0];
55 }
56
57 template<typename Archive>
58 void serialize(Archive& ar, unsigned version);
59
60private:
61 Ram ram;
62 bool writeSinceLastReverseSnapshot = true;
63};
64
65} // namespace openmsx
66
67#endif
unsigned getSize() const
Definition: Ram.hh:44
void clear(byte c=0xff)
Definition: Ram.cc:35
const std::string & getName() const
Definition: Ram.cc:79
byte read(unsigned addr) const
Definition: TrackedRam.hh:29
const std::string & getName() const
Definition: TrackedRam.hh:24
void clear(byte c=0xff)
Definition: TrackedRam.hh:43
TrackedRam(const DeviceConfig &config, const std::string &name, static_string_view description, unsigned size)
Definition: TrackedRam.hh:13
void write(unsigned addr, byte value)
Definition: TrackedRam.hh:38
byte * getWriteBackdoor()
Definition: TrackedRam.hh:52
unsigned getSize() const
Definition: TrackedRam.hh:20
TrackedRam(const XMLElement &xml, unsigned size)
Definition: TrackedRam.hh:17
void serialize(Archive &ar, unsigned version)
Definition: TrackedRam.cc:7
const byte & operator[](unsigned addr) const
Definition: TrackedRam.hh:33
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)