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 <memory>
8 
9 namespace openmsx {
10 
11 class SRAM final
12 {
13 public:
14  struct DontLoadTag {};
15  SRAM(int size, const XMLElement& xml, DontLoadTag);
16  SRAM(const std::string& name, const std::string& 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, const std::string& description,
22  int size, const DeviceConfig& config, const char* header = nullptr,
23  bool* loaded = nullptr);
24  ~SRAM();
25 
26  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  unsigned getSize() const {
34  return ram.getSize();
35  }
36  const std::string& getLoadedFilename() const {
37  return loadedFilename;
38  }
39 
40  template<typename Archive>
41  void serialize(Archive& ar, unsigned version);
42 
43 private:
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::unique_ptr<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
openmsx::TrackedRam
TrackedRam
Definition: TrackedRam.cc:16
openmsx::RTSchedulable
Definition: RTSchedulable.hh:10
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
RTSchedulable.hh
openmsx::RTScheduler
Definition: RTScheduler.hh:19
openmsx::SRAM
Definition: SRAM.hh:11
openmsx::SRAM::serialize
void serialize(Archive &ar, unsigned version)
Definition: SRAM.cc:146
openmsx::SRAM::SRAM
SRAM(int size, const XMLElement &xml, DontLoadTag)
Definition: SRAM.cc:23
openmsx::SRAM::DontLoadTag
Definition: SRAM.hh:14
openmsx::XMLElement
Definition: XMLElement.hh:15
openmsx::TrackedRam::getSize
unsigned getSize() const
Definition: TrackedRam.hh:20
openmsx::SRAM::operator[]
const byte & operator[](unsigned addr) const
Definition: SRAM.hh:26
openmsx::SRAM::getSize
unsigned getSize() const
Definition: SRAM.hh:33
openmsx::SRAM::write
void write(unsigned addr, byte value)
Definition: SRAM.cc:67
openmsx::SRAM::getLoadedFilename
const std::string & getLoadedFilename() const
Definition: SRAM.hh:36
TrackedRam.hh
openmsx::SRAM::memset
void memset(unsigned addr, byte c, unsigned size)
Definition: SRAM.cc:76
openmsx::SRAM::~SRAM
~SRAM()
Definition: SRAM.cc:60
DeviceConfig.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5