openMSX
SRAM.hh
Go to the documentation of this file.
1#ifndef SRAM_HH
2#define SRAM_HH
3
4#include "TrackedRam.hh"
5
6#include "DeviceConfig.hh"
7#include "RTSchedulable.hh"
8
9#include <optional>
10
11namespace openmsx {
12
13class SRAM final
14{
15public:
16 struct DontLoadTag {};
17 SRAM(size_t size, const XMLElement& xml, DontLoadTag);
18 SRAM(const std::string& name, static_string_view description,
19 size_t size, const DeviceConfig& config, DontLoadTag);
20 SRAM(const std::string& name,
21 size_t size, const DeviceConfig& config, const char* header = nullptr,
22 bool* loaded = nullptr);
23 SRAM(const std::string& name, static_string_view description,
24 size_t size, const DeviceConfig& config, const char* header = nullptr,
25 bool* loaded = nullptr);
26 ~SRAM();
27
28 [[nodiscard]] const byte& operator[](size_t addr) const {
29 assert(addr < size());
30 return ram[addr];
31 }
32 // write() is non-inline because of the auto-sync to disk feature
33 void write(size_t addr, byte value);
34 void memset(size_t addr, byte c, size_t size);
35 [[nodiscard]] size_t size() const {
36 return ram.size();
37 }
38
39 template<typename Archive>
40 void serialize(Archive& ar, unsigned version);
41
42private:
43 struct SRAMSchedulable final : public RTSchedulable {
44 explicit SRAMSchedulable(RTScheduler& scheduler_, SRAM& sram_)
45 : RTSchedulable(scheduler_), sram(sram_) {}
46 void executeRT() override;
47 private:
48 SRAM& sram;
49 };
50 std::optional<SRAMSchedulable> schedulable;
51
52 void load(bool* loaded);
53 void save() const;
54
55 const DeviceConfig config;
56 TrackedRam ram;
57 const char* const header = nullptr;
58};
59
60} // namespace openmsx
61
62#endif
void write(size_t addr, byte value)
Definition SRAM.cc:64
void serialize(Archive &ar, unsigned version)
Definition SRAM.cc:139
size_t size() const
Definition SRAM.hh:35
const byte & operator[](size_t addr) const
Definition SRAM.hh:28
void memset(size_t addr, byte c, size_t size)
Definition SRAM.cc:73
size_t size() const
Definition TrackedRam.hh:20
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:11