--- nono/vm/gvram.cpp 2026/04/29 17:05:25 1.1.1.8 +++ nono/vm/gvram.cpp 2026/04/29 17:05:43 1.1.1.10 @@ -12,7 +12,6 @@ // バイトアクセス時は HB() マクロを使用のこと。 #include "gvram.h" -#include "mpu.h" #include "videoctlr.h" // InsideOut p.135 @@ -22,9 +21,6 @@ static const busdata wait = busdata::Wai GVRAMDevice::GVRAMDevice() : inherited(OBJ_GVRAM) { - uint devlen = 0x20'0000; // XXX とりあえず - - mem.reset(new uint8[devlen]); } // デストラクタ @@ -32,44 +28,60 @@ GVRAMDevice::~GVRAMDevice() { } -busdata -GVRAMDevice::Read8(uint32 addr) +// 初期化 +bool +GVRAMDevice::Init() { - busdata data; - uint32 offset = addr - baseaddr; - data = mem[HB(offset)]; - data |= wait; - return data; + uint devlen = 0x20'0000; // XXX とりあえず + mem.reset(new(std::nothrow) uint8[devlen]); + if ((bool)mem == false) { + warnx("Cannot allocate %u bytes at %s", devlen, __method__); + return false; + } + + return true; } -busdata -GVRAMDevice::Read16(uint32 addr) +inline uint32 +GVRAMDevice::Decoder(uint32 addr) const { - busdata data; - uint32 offset = addr - baseaddr; - data = *(uint16 *)&mem[offset]; - data |= wait; - return data; + return addr - baseaddr; } busdata -GVRAMDevice::Write8(uint32 addr, uint32 data) +GVRAMDevice::Read(busaddr addr) { - uint32 offset = addr - baseaddr; - mem[HB(offset)] = data; - return wait; + uint32 offset = Decoder(addr.Addr()); + busdata data; + + data = *(uint16 *)&mem[offset & ~1U]; + data |= wait; + data |= BusData::Size2; + return data; } busdata -GVRAMDevice::Write16(uint32 addr, uint32 data) +GVRAMDevice::Write(busaddr addr, uint32 data) { - uint32 offset = addr - baseaddr; - *(uint16 *)&mem[offset] = data; - return wait; + uint32 offset = Decoder(addr.Addr()); + uint32 reqsize = addr.GetSize(); + uint32 datasize = std::min(2 - (offset & 1U), reqsize); + data >>= (reqsize - datasize) * 8; + + if (datasize == 1) { + mem[HB(offset)] = data; + } else { + *(uint16 *)&mem[offset] = data; + } + + busdata r = wait; + r |= busdata::Size(datasize); + return r; } busdata -GVRAMDevice::Peek8(uint32 addr) +GVRAMDevice::Peek1(uint32 addr) { - return mem[HB(addr - baseaddr)]; + uint32 offset = Decoder(addr); + return mem[HB(offset)]; }