--- nono/vm/sram.h 2026/04/29 17:04:36 1.1.1.3 +++ nono/vm/sram.h 2026/04/29 17:05:50 1.1.1.13 @@ -4,18 +4,25 @@ // 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; + // サイズは (今のところ?) 16KB 固定。 + static const uint sramsize = 16 * 1024; + // Pluto-X によるホストファイル起動アドレス static const uint32 plutoaddr = 0xeac000; @@ -24,28 +31,44 @@ class SRAMDevice ~SRAMDevice() override; bool Init() override; + void ResetHard(bool poweron) 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; } - 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; + // SRAM $ed0008.L RAM 容量を返す (ホストファイル起動用) + uint32 GetRAMSize() const { return Get32(0x0008); } - void write_enable(bool value); + // SRAM $ed000c.L ROM 起動アドレスを返す (romemu 用) + 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 Decoder(uint32 addr) const; // ファイル std::string filename {}; - MappedFile file {}; + std::unique_ptr file {}; uint8 *mem {}; - bool writeable = false; + bool writeable {}; - // ホストファイル起動用の読み出し値を返す - uint32 PeekHostBoot(uint32 offset) const; + // SRAM の初期値 + static std::array initialdata; }; -extern std::unique_ptr gSRAM; +static inline SRAMDevice *GetSRAMDevice() { + return Object::GetObject(OBJ_SRAM); +}