openMSX
Ram.hh
Go to the documentation of this file.
1 #ifndef RAM_HH
2 #define RAM_HH
3 
4 #include "SimpleDebuggable.hh"
5 #include "MemBuffer.hh"
6 #include "openmsx.hh"
7 #include "static_string_view.hh"
8 #include <optional>
9 #include <string>
10 
11 namespace openmsx {
12 
13 class XMLElement;
14 class DeviceConfig;
15 class Ram;
16 
17 class RamDebuggable final : public SimpleDebuggable
18 {
19 public:
20  RamDebuggable(MSXMotherBoard& motherBoard, const std::string& name,
21  static_string_view description, Ram& ram);
22  byte read(unsigned address) override;
23  void write(unsigned address, byte value) override;
24 private:
25  Ram& ram;
26 };
27 
28 class Ram
29 {
30 public:
32  Ram(const DeviceConfig& config, const std::string& name,
33  static_string_view description, unsigned size);
34 
36  Ram(const XMLElement& xml, unsigned size);
37 
38  [[nodiscard]] const byte& operator[](unsigned addr) const {
39  return ram[addr];
40  }
41  [[nodiscard]] byte& operator[](unsigned addr) {
42  return ram[addr];
43  }
44  [[nodiscard]] unsigned getSize() const {
45  return size;
46  }
47 
48  [[nodiscard]] const std::string& getName() const;
49  void clear(byte c = 0xff);
50 
51  template<typename Archive>
52  void serialize(Archive& ar, unsigned version);
53 
54 private:
55  const XMLElement& xml;
56  MemBuffer<byte> ram;
57  unsigned size; // must come before debuggable
58  const std::optional<RamDebuggable> debuggable; // can be nullopt
59 };
60 
61 } // namespace openmsx
62 
63 #endif
byte read(unsigned address) override
Definition: Ram.cc:92
void write(unsigned address, byte value) override
Definition: Ram.cc:97
RamDebuggable(MSXMotherBoard &motherBoard, const std::string &name, static_string_view description, Ram &ram)
Definition: Ram.cc:84
Ram(const DeviceConfig &config, const std::string &name, static_string_view description, unsigned size)
Create Ram object with an associated debuggable.
Definition: Ram.cc:16
const byte & operator[](unsigned addr) const
Definition: Ram.hh:38
unsigned getSize() const
Definition: Ram.hh:44
void serialize(Archive &ar, unsigned version)
Definition: Ram.cc:104
byte & operator[](unsigned addr)
Definition: Ram.hh:41
void clear(byte c=0xff)
Definition: Ram.cc:35
const std::string & getName() const
Definition: Ram.cc:79
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
Ram
Definition: Ram.cc:108