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"
8#include <optional>
9#include <string>
10
11namespace openmsx {
12
13class XMLElement;
14class DeviceConfig;
15class Ram;
16
17class RamDebuggable final : public SimpleDebuggable
18{
19public:
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;
24private:
25 Ram& ram;
26};
27
28class Ram
29{
30public:
32 Ram(const DeviceConfig& config, const std::string& name,
33 static_string_view description, size_t size);
34
36 Ram(const XMLElement& xml, size_t size);
37
38 [[nodiscard]] const byte& operator[](size_t addr) const {
39 return ram[addr];
40 }
41 [[nodiscard]] byte& operator[](size_t addr) {
42 return ram[addr];
43 }
44 [[nodiscard]] auto size() const { return sz; }
45 [[nodiscard]] auto data() { return ram.data(); }
46 [[nodiscard]] auto data() const { return ram.data(); }
47 [[nodiscard]] auto begin() { return ram.data(); }
48 [[nodiscard]] auto begin() const { return ram.data(); }
49 [[nodiscard]] auto end() { return ram.data() + sz; }
50 [[nodiscard]] auto end() const { return ram.data() + sz; }
51
52 [[nodiscard]] const std::string& getName() const;
53 void clear(byte c = 0xff);
54
55 template<typename Archive>
56 void serialize(Archive& ar, unsigned version);
57
58private:
59 const XMLElement& xml;
61 size_t sz; // must come before debuggable
62 const std::optional<RamDebuggable> debuggable; // can be nullopt
63};
64
65} // namespace openmsx
66
67#endif
This class manages the lifetime of a block of memory.
Definition MemBuffer.hh:29
const T * data() const
Returns pointer to the start of the memory buffer.
Definition MemBuffer.hh:81
byte read(unsigned address) override
Definition Ram.cc:96
void write(unsigned address, byte value) override
Definition Ram.cc:101
auto begin() const
Definition Ram.hh:48
auto size() const
Definition Ram.hh:44
auto end()
Definition Ram.hh:49
auto data()
Definition Ram.hh:45
const byte & operator[](size_t addr) const
Definition Ram.hh:38
void serialize(Archive &ar, unsigned version)
Definition Ram.cc:108
auto end() const
Definition Ram.hh:50
auto data() const
Definition Ram.hh:46
auto begin()
Definition Ram.hh:47
void clear(byte c=0xff)
Definition Ram.cc:40
const std::string & getName() const
Definition Ram.cc:83
byte & operator[](size_t addr)
Definition Ram.hh:41
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:11