--- nono/vm/gvram.cpp 2026/04/29 17:05:18 1.1.1.7 +++ nono/vm/gvram.cpp 2026/04/29 17:05:29 1.1.1.9 @@ -12,9 +12,11 @@ // バイトアクセス時は HB() マクロを使用のこと。 #include "gvram.h" -#include "mpu.h" #include "videoctlr.h" +// InsideOut p.135 +static const busdata wait = busdata::Wait(9 * 40_nsec); + // コンストラクタ GVRAMDevice::GVRAMDevice() : inherited(OBJ_GVRAM) @@ -29,42 +31,46 @@ GVRAMDevice::~GVRAMDevice() { } -uint64 -GVRAMDevice::Read8(uint32 addr) +inline uint32 +GVRAMDevice::Decoder(uint32 addr) const { - mpu->AddCycle(9); // Inside/Out p.135 - uint32 offset = addr - baseaddr; - return mem[HB(offset)]; + return addr - baseaddr; } -uint64 -GVRAMDevice::Read16(uint32 addr) +busdata +GVRAMDevice::Read(busaddr addr) { - mpu->AddCycle(9); // Inside/Out p.135 - uint32 offset = addr - baseaddr; - return *(uint16 *)&mem[offset]; -} + uint32 offset = Decoder(addr.Addr()); + busdata data; -uint64 -GVRAMDevice::Write8(uint32 addr, uint32 data) -{ - mpu->AddCycle(9); // Inside/Out p.135 - uint32 offset = addr - baseaddr; - mem[HB(offset)] = data; - return 0; + data = *(uint16 *)&mem[offset & ~1U]; + data |= wait; + data |= BusData::Size2; + return data; } -uint64 -GVRAMDevice::Write16(uint32 addr, uint32 data) +busdata +GVRAMDevice::Write(busaddr addr, uint32 data) { - mpu->AddCycle(9); // Inside/Out p.135 - uint32 offset = addr - baseaddr; - *(uint16 *)&mem[offset] = data; - return 0; + 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; } -uint64 -GVRAMDevice::Peek8(uint32 addr) +busdata +GVRAMDevice::Peek1(uint32 addr) { - return mem[HB(addr - baseaddr)]; + uint32 offset = Decoder(addr); + return mem[HB(offset)]; }