--- nono/vm/gvram.cpp 2026/04/29 17:05:25 1.1.1.8 +++ nono/vm/gvram.cpp 2026/04/29 17:05:29 1.1.1.9 @@ -12,7 +12,6 @@ // バイトアクセス時は HB() マクロを使用のこと。 #include "gvram.h" -#include "mpu.h" #include "videoctlr.h" // InsideOut p.135 @@ -32,44 +31,46 @@ GVRAMDevice::~GVRAMDevice() { } -busdata -GVRAMDevice::Read8(uint32 addr) +inline uint32 +GVRAMDevice::Decoder(uint32 addr) const { - busdata data; - uint32 offset = addr - baseaddr; - data = mem[HB(offset)]; - data |= wait; - return data; + return addr - baseaddr; } busdata -GVRAMDevice::Read16(uint32 addr) +GVRAMDevice::Read(busaddr addr) { + uint32 offset = Decoder(addr.Addr()); busdata data; - uint32 offset = addr - baseaddr; - data = *(uint16 *)&mem[offset]; + + data = *(uint16 *)&mem[offset & ~1U]; data |= wait; + data |= BusData::Size2; return data; } busdata -GVRAMDevice::Write8(uint32 addr, uint32 data) -{ - uint32 offset = addr - baseaddr; - mem[HB(offset)] = data; - return wait; -} - -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)]; }