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 [[nodiscard]] const std::string& getLoadedFilename() const {
39 return loadedFilename;
40 }
41
42 template<typename Archive>
43 void serialize(Archive& ar, unsigned version);
44
45private:
46 struct SRAMSchedulable final : public RTSchedulable {
47 explicit SRAMSchedulable(RTScheduler& scheduler_, SRAM& sram_)
48 : RTSchedulable(scheduler_), sram(sram_) {}
49 void executeRT() override;
50 private:
51 SRAM& sram;
52 };
53 std::optional<SRAMSchedulable> schedulable;
54
55 void load(bool* loaded);
56 void save() const;
57
58 const DeviceConfig config;
59 TrackedRam ram;
60 const char* const header = nullptr;
61
62 std::string loadedFilename;
63};
64
65} // namespace openmsx
66
67#endif
const std::string & getLoadedFilename() const
Definition SRAM.hh:38
void write(size_t addr, byte value)
Definition SRAM.cc:64
void serialize(Archive &ar, unsigned version)
Definition SRAM.cc:140
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