--- nono/vm/bankram.cpp 2026/04/29 17:05:21 1.1 +++ nono/vm/bankram.cpp 2026/04/29 17:05:25 1.1.1.2 @@ -13,6 +13,7 @@ #include "bankram.h" #include "config.h" +#include "mainbus.h" // コンストラクタ BankRAMDevice::BankRAMDevice(int objid_, int ram_size_MB) @@ -54,6 +55,9 @@ BankRAMDevice::ResetHard(bool poweron) // リセットでクリアされる。 SetPage(0); + + std::fill(accstat_read.begin(), accstat_read.end(), 0); + std::fill(accstat_write.begin(), accstat_write.end(), 0); } inline uint32 @@ -62,75 +66,81 @@ BankRAMDevice::Decoder(uint32 addr) cons return pageaddr + (addr & 0xffff); } -uint64 +busdata BankRAMDevice::Read8(uint32 addr) { uint32 offset = Decoder(addr); + accstat_read[offset >> 20] = MainbusDevice::ACC_READ; uint32 data = ram[HLB(offset)]; putlog(4, "$%08x.B -> $%02x", addr, data); return data; } -uint64 +busdata BankRAMDevice::Read16(uint32 addr) { uint32 offset = Decoder(addr); + accstat_read[offset >> 20] = MainbusDevice::ACC_READ; uint32 data = *(uint16 *)&ram[HLW(offset)]; putlog(4, "$%08x.W -> $%04x", addr, data); return data; } -uint64 +busdata BankRAMDevice::Read32(uint32 addr) { uint32 offset = Decoder(addr); + accstat_read[offset >> 20] = MainbusDevice::ACC_READ; uint32 data = *(uint32 *)&ram[offset]; putlog(4, "$%08x.L -> $%08x", addr, data); return data; } -uint64 +busdata BankRAMDevice::Write8(uint32 addr, uint32 data) { uint32 offset = Decoder(addr); + accstat_write[offset >> 20] = MainbusDevice::ACC_WRITE; ram[HLB(offset)] = data; putlog(3, "$%08x.B <- $%02x", addr, data); return 0; } -uint64 +busdata BankRAMDevice::Write16(uint32 addr, uint32 data) { uint32 offset = Decoder(addr); + accstat_write[offset >> 20] = MainbusDevice::ACC_WRITE; *(uint16 *)&ram[HLW(offset)] = data; putlog(3, "$%08x.W <- $%04x", addr, data); return 0; } -uint64 +busdata BankRAMDevice::Write32(uint32 addr, uint32 data) { uint32 offset = Decoder(addr); + accstat_write[offset >> 20] = MainbusDevice::ACC_WRITE; *(uint32 *)&ram[offset] = data; putlog(3, "$%08x.L <- $%08x", addr, data); return 0; } -uint64 +busdata BankRAMDevice::Peek8(uint32 addr) { uint32 offset = Decoder(addr); return ram[HLB(offset)]; } -uint64 +bool BankRAMDevice::Poke8(uint32 addr, uint32 data) { if ((int32)data >= 0) { uint32 offset = Decoder(addr); ram[HLB(offset)] = data; } - return 0; + return true; } void @@ -142,3 +152,19 @@ BankRAMDevice::SetPage(uint32 page_) putlog(2, "Page <- $%02x", page); } + +void +BankRAMDevice::FetchAccStat(uint8 *acc) +{ + // R|W をマージしながらコピー。 + for (int i = 0; i < accstat_read.size(); i += 4) { + uint32 tmp = 0; + tmp |= *(uint32 *)&accstat_read[i]; + tmp |= *(uint32 *)&accstat_write[i]; + *(uint32 *)&acc[i] = tmp; + } + + // 読んだのでリセット。 + std::fill(accstat_read.begin(), accstat_read.end(), 0); + std::fill(accstat_write.begin(), accstat_write.end(), 0); +}