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(int size, const XMLElement& xml, DontLoadTag);
16 SRAM(const std::string& name, static_string_view description,
17 int size, const DeviceConfig& config, DontLoadTag);
18 SRAM(const std::string& name,
19 int size, const DeviceConfig& config, const char* header = nullptr,
20 bool* loaded = nullptr);
21 SRAM(const std::string& name, static_string_view description,
22 int size, const DeviceConfig& config, const char* header = nullptr,
23 bool* loaded = nullptr);
24 ~SRAM();
25
26 [[nodiscard]] const byte& operator[](unsigned addr) const {
27 assert(addr < getSize());
28 return ram[addr];
29 }
30 // write() is non-inline because of the auto-sync to disk feature
31 void write(unsigned addr, byte value);
32 void memset(unsigned addr, byte c, unsigned size);
33 [[nodiscard]] unsigned getSize() const {
34 return ram.getSize();
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(unsigned addr, byte value)
Definition: SRAM.cc:64
unsigned getSize() const
Definition: SRAM.hh:33
SRAM(int size, const XMLElement &xml, DontLoadTag)
Definition: SRAM.cc:20
void memset(unsigned addr, byte c, unsigned size)
Definition: SRAM.cc:73
void serialize(Archive &ar, unsigned version)
Definition: SRAM.cc:143
const byte & operator[](unsigned addr) const
Definition: SRAM.hh:26
unsigned getSize() const
Definition: TrackedRam.hh:20
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)