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