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
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
SRAM(int size, const XMLElement &xml, DontLoadTag)
Definition: SRAM.cc:23
void write(unsigned addr, byte value)
Definition: SRAM.cc:67
void memset(unsigned addr, byte c, unsigned size)
Definition: SRAM.cc:76
size_t size(std::string_view utf8)
const std::string & getLoadedFilename() const
Definition: SRAM.hh:36
void serialize(Archive &ar, unsigned version)
Definition: SRAM.cc:146
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
unsigned getSize() const
Definition: SRAM.hh:33
const byte & operator[](unsigned addr) const
Definition: SRAM.hh:26