--- nono/vm/ram.h 2026/04/29 17:04:45 1.1.1.5 +++ nono/vm/ram.h 2026/04/29 17:05:09 1.1.1.9 @@ -4,12 +4,15 @@ // Licensed under nono-license.txt // +// +// メインメモリ +// + #pragma once #include "device.h" -class RAMDevice - : public IODevice +class RAMDevice : public IODevice { using inherited = IODevice; public: @@ -17,7 +20,7 @@ class RAMDevice virtual ~RAMDevice() override; bool Init() override; - void ResetHard() override; + void ResetHard(bool poweron) override; uint64 Read8(uint32 addr) override; uint64 Read16(uint32 addr) override; @@ -27,26 +30,32 @@ class RAMDevice uint64 Write32(uint32 addr, uint32 data) override; uint64 Peek8(uint32 addr) override; + // RAM 容量(バイト単位)を取得 + int GetSize() const { return ram_size; } + // RAM 容量(MB単位)を取得 + int GetSizeMB() const { return (uint)ram_size / 1024 / 1024; } + // アクセスウェイトを設定 void SetWait(uint32 wait); // ホストの filepath をロードする - uint32 LoadFile(const char *filepath, uint32 mid); + uint32 LoadFile(const char *filepath); // file, filesize で示されるバッファをロードする - uint32 LoadFile(const char *name, const uint8 *file, size_t filesize, - uint32 mid); + uint32 LoadFile(const char *name, const uint8 *file, size_t filesize); + private: - uint32 LoadGzFile(const char *filepath, const uint8 *file, size_t filesize, - uint32 mid); - uint32 Load_aout(const char *name, const uint8 *file, size_t filesize, - uint32 mid); - uint32 Load_elf32(const char *name, const uint8 *file, size_t filesize, - uint32 mid); + uint32 LoadGzFile(const char *filepath, const uint8 *file, size_t filesize); + uint32 Load_aout(const char *name, const uint8 *file, size_t filesize); + uint32 Load_elf32(const char *name, const uint8 *file, size_t filesize); + bool Load_elf32_exec(const char *name, const uint8 *file, size_t filesize); + uint32 Load_elf32_rel(const char *name, const uint8 *file, size_t filesize); + + // RAM 容量(バイト単位)。ram[] の確保したバイト数 + int ram_size {}; uint32 read_wait {}; uint32 write_wait {}; }; -extern std::unique_ptr ram; -extern int ram_size; -extern std::unique_ptr gRAM; +extern std::unique_ptr mainram; +extern RAMDevice *gRAM;