| 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 <cstdint> |
| 10 |
#include <optional> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class SRAM final |
| 15 |
{ |
| 16 |
public: |
| 17 |
struct DontLoadTag {}; |
| 18 |
SRAM(size_t size, const XMLElement& xml, DontLoadTag); |
| 19 |
SRAM(const std::string& name, static_string_view description, |
| 20 |
size_t size, const DeviceConfig& config, DontLoadTag); |
| 21 |
SRAM(const std::string& name, |
| 22 |
size_t size, const DeviceConfig& config, const char* header = nullptr, |
| 23 |
bool* loaded = nullptr); |
| 24 |
SRAM(const std::string& name, static_string_view description, |
| 25 |
size_t size, const DeviceConfig& config, const char* header = nullptr, |
| 26 |
bool* loaded = nullptr); |
| 27 |
~SRAM(); |
| 28 |
|
| 29 |
[[nodiscard]] const uint8_t& operator[](size_t addr) const { |
| 30 |
assert(addr < size()); |
| 31 |
return ram[addr]; |
| 32 |
} |
| 33 |
|
| 34 |
void write(size_t addr, uint8_t value); |
| 35 |
void memset(size_t addr, uint8_t c, size_t size); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
[[nodiscard]] std::span<uint8_t> getWriteBackdoor() { |
| 41 |
return ram.getWriteBackdoor(); |
| 42 |
} |
| 43 |
|
| 44 |
[[nodiscard]] size_t size() const { |
| 45 |
return ram.size(); |
| 46 |
} |
| 47 |
|
| 48 |
template<typename Archive> |
| 49 |
void serialize(Archive& ar, unsigned version); |
| 50 |
|
| 51 |
private: |
| 52 |
struct SRAMSchedulable final : public RTSchedulable { |
| 53 |
explicit SRAMSchedulable(RTScheduler& scheduler_, SRAM& sram_) |
| 54 |
: RTSchedulable(scheduler_), sram(sram_) {} |
| 55 |
void executeRT() override; |
| 56 |
private: |
| 57 |
SRAM& sram; |
| 58 |
}; |
| 59 |
std::optional<SRAMSchedulable> schedulable; |
| 60 |
|
| 61 |
void load(bool* loaded); |
| 62 |
void save() const; |
| 63 |
|
| 64 |
const DeviceConfig config; |
| 65 |
TrackedRam ram; |
| 66 |
const char* const header = nullptr; |
| 67 |
}; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
#endif |