--- nono/vm/sram.h 2026/04/29 17:05:13 1.1.1.9 +++ nono/vm/sram.h 2026/04/29 17:05:50 1.1.1.13 @@ -12,6 +12,7 @@ #include "device.h" #include "mappedfile.h" +#include class SRAMDevice : public IODevice { @@ -19,43 +20,55 @@ class SRAMDevice : public IODevice static const uint32 baseaddr = 0xed0000; + // サイズは (今のところ?) 16KB 固定。 + static const uint sramsize = 16 * 1024; + // Pluto-X によるホストファイル起動アドレス static const uint32 plutoaddr = 0xeac000; public: SRAMDevice(); - virtual ~SRAMDevice() override; + ~SRAMDevice() override; bool Init() override; void ResetHard(bool poweron) override; - uint64 Read8(uint32 addr) override; - uint64 Read16(uint32 addr) override; - uint64 Write8(uint32 addr, uint32 data) override; - uint64 Write16(uint32 addr, uint32 data) override; - uint64 Peek8(uint32 addr) override; + busdata Read(busaddr addr) override; + busdata Write(busaddr addr, uint32 data) override; + busdata Peek1(uint32 addr) override; + bool Poke1(uint32 addr, uint32 data) override; + + void WriteEnable(bool value); + bool IsWriteable() const { return writeable; } - void write_enable(bool value); + // SRAM $ed0008.L RAM 容量を返す (ホストファイル起動用) + uint32 GetRAMSize() const { return Get32(0x0008); } // SRAM $ed000c.L ROM 起動アドレスを返す (romemu 用) - uint32 GetROMAddr() const; + uint32 GetROMAddr() const { return Get32(0x000c); } private: + // SRAM の指定の位置の値を副作用なく読み出す + uint32 Get16(uint32 offset) const; + uint32 Get32(uint32 offset) const; + // RAM 容量欄を設定値に同期させる。 void SyncRAMSize(); // アドレスデコーダ - uint64 Decoder(uint32 addr) const; - - // ホストファイル起動用の読み出し値を返す - uint32 PeekHostBoot(uint32 offset) const; + uint32 Decoder(uint32 addr) const; // ファイル std::string filename {}; - MappedFile file {}; + std::unique_ptr file {}; uint8 *mem {}; bool writeable {}; + + // SRAM の初期値 + static std::array initialdata; }; -extern SRAMDevice *gSRAM; +static inline SRAMDevice *GetSRAMDevice() { + return Object::GetObject(OBJ_SRAM); +}