--- nono/vm/sram.h 2026/04/29 17:04:53 1.1.1.6 +++ nono/vm/sram.h 2026/04/29 17:05:24 1.1.1.11 @@ -4,16 +4,20 @@ // Licensed under nono-license.txt // +// +// SRAM +// + #pragma once #include "device.h" #include "mappedfile.h" +#include -class SRAMDevice - : public IODevice +class SRAMDevice : public IODevice { using inherited = IODevice; - private: + static const uint32 baseaddr = 0xed0000; // Pluto-X によるホストファイル起動アドレス @@ -21,22 +25,41 @@ class SRAMDevice public: SRAMDevice(); - virtual ~SRAMDevice() override; + ~SRAMDevice() override; bool Init() override; - void ResetHard() 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 Read8(uint32 addr) override; + busdata Read16(uint32 addr) override; + busdata Write8(uint32 addr, uint32 data) override; + busdata Write16(uint32 addr, uint32 data) override; + busdata Peek8(uint32 addr) override; + bool Poke8(uint32 addr, uint32 data) override; + + void WriteEnable(bool value); + bool IsWriteable() const { return writeable; } + + // SRAM の指定の位置の値を副作用なく読み出す + uint32 Get8(uint32 offset) const; + uint32 Get16(uint32 offset) const; + uint32 Get32(uint32 offset) const; - void write_enable(bool value); + // SRAM $ed0008.L RAM 容量を返す (ホストファイル起動用) + uint32 GetRAMSize() const { return Get32(0x0008); } + + // SRAM $ed000c.L ROM 起動アドレスを返す (romemu 用) + uint32 GetROMAddr() const { return Get32(0x000c); } + + // SRAM の初期値 + static std::array InitialData; private: + // RAM 容量欄を設定値に同期させる。 + void SyncRAMSize(); + // アドレスデコーダ - uint64 Decoder(uint32 addr) const; + uint32 Decoder(uint32 addr) const; // ファイル std::string filename {}; @@ -44,9 +67,8 @@ class SRAMDevice uint8 *mem {}; bool writeable {}; - - // ホストファイル起動用の読み出し値を返す - uint32 PeekHostBoot(uint32 offset) const; }; -extern std::unique_ptr gSRAM; +static inline SRAMDevice *GetSRAMDevice() { + return Object::GetObject(OBJ_SRAM); +}