openMSX
CheckedRam.hh
Go to the documentation of this file.
1 #ifndef CHECKEDRAM_HH
2 #define CHECKEDRAM_HH
3 
4 #include "Ram.hh"
5 #include "TclCallback.hh"
6 #include "CacheLine.hh"
7 #include "Observer.hh"
8 #include "openmsx.hh"
9 #include <vector>
10 #include <bitset>
11 
12 namespace openmsx {
13 
14 class DeviceConfig;
15 class MSXCPU;
16 class Setting;
17 
27 class CheckedRam final : private Observer<Setting>
28 {
29 public:
30  CheckedRam(const DeviceConfig& config, const std::string& name,
31  static_string_view description, unsigned size);
32  ~CheckedRam();
33 
34  [[nodiscard]] byte read(unsigned addr);
35  [[nodiscard]] byte peek(unsigned addr) const { return ram[addr]; }
36  void write(unsigned addr, byte value);
37 
38  [[nodiscard]] const byte* getReadCacheLine(unsigned addr) const;
39  [[nodiscard]] byte* getWriteCacheLine(unsigned addr) const;
40  [[nodiscard]] byte* getRWCacheLines(unsigned addr, unsigned size) const;
41 
42  [[nodiscard]] unsigned getSize() const { return ram.getSize(); }
43  void clear();
44 
51  [[nodiscard]] Ram& getUncheckedRam() { return ram; }
52 
53  // TODO
54  //template<typename Archive>
55  //void serialize(Archive& ar, unsigned version);
56 
57 private:
58  void init();
59 
60  // Observer<Setting>
61  void update(const Setting& setting) noexcept override;
62 
63 private:
64  std::vector<bool> completely_initialized_cacheline;
65  std::vector<std::bitset<CacheLine::SIZE>> uninitialized;
66  Ram ram;
67  MSXCPU& msxcpu;
68  TclCallback umrCallback;
69 };
70 
71 } // namespace openmsx
72 
73 #endif
BaseSetting * setting
Definition: Interpreter.cc:27
This class keeps track of which bytes in the Ram have been written to.
Definition: CheckedRam.hh:28
const byte * getReadCacheLine(unsigned addr) const
Definition: CheckedRam.cc:39
byte * getRWCacheLines(unsigned addr, unsigned size) const
Definition: CheckedRam.cc:51
Ram & getUncheckedRam()
Give access to the unchecked Ram.
Definition: CheckedRam.hh:51
byte read(unsigned addr)
Definition: CheckedRam.cc:28
void write(unsigned addr, byte value)
Definition: CheckedRam.cc:64
unsigned getSize() const
Definition: CheckedRam.hh:42
CheckedRam(const DeviceConfig &config, const std::string &name, static_string_view description, unsigned size)
Definition: CheckedRam.cc:13
byte * getWriteCacheLine(unsigned addr) const
Definition: CheckedRam.cc:45
byte peek(unsigned addr) const
Definition: CheckedRam.hh:35
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
unsigned getSize() const
Definition: Ram.hh:44
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)