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  const std::string& description, unsigned size);
32  ~CheckedRam();
33 
34  byte read(unsigned addr);
35  byte peek(unsigned addr) const { return ram[addr]; }
36  void write(unsigned addr, byte value);
37 
38  const byte* getReadCacheLine(unsigned addr) const;
39  byte* getWriteCacheLine(unsigned addr) const;
40 
41  unsigned getSize() const { return ram.getSize(); }
42  void clear();
43 
50  Ram& getUncheckedRam() { return ram; }
51 
52  // TODO
53  //template<typename Archive>
54  //void serialize(Archive& ar, unsigned version);
55 
56 private:
57  void init();
58 
59  // Observer<Setting>
60  void update(const Setting& setting) override;
61 
62  std::vector<bool> completely_initialized_cacheline;
63  std::vector<std::bitset<CacheLine::SIZE>> uninitialized;
64  Ram ram;
65  MSXCPU& msxcpu;
66  TclCallback umrCallback;
67 };
68 
69 } // namespace openmsx
70 
71 #endif
const byte * getReadCacheLine(unsigned addr) const
Definition: CheckedRam.cc:47
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
unsigned getSize() const
Definition: CheckedRam.hh:41
Ram & getUncheckedRam()
Give access to the unchecked Ram.
Definition: CheckedRam.hh:50
void write(unsigned addr, byte value)
Definition: CheckedRam.cc:59
This class keeps track of which bytes in the Ram have been written to.
Definition: CheckedRam.hh:27
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
byte peek(unsigned addr) const
Definition: CheckedRam.hh:35
byte read(unsigned addr)
Definition: CheckedRam.cc:36
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hh:62
CheckedRam(const DeviceConfig &config, const std::string &name, const std::string &description, unsigned size)
Definition: CheckedRam.cc:19
unsigned getSize() const
Definition: Ram.hh:33
byte * getWriteCacheLine(unsigned addr) const
Definition: CheckedRam.cc:53