--- nono/vm/tvram.cpp 2026/04/29 17:04:28 1.1 +++ nono/vm/tvram.cpp 2026/04/29 17:04:32 1.1.1.2 @@ -14,7 +14,7 @@ // バイトアクセス時は HB() マクロを使用のこと。 // -TVRAMDevice *gTVRAM; +std::unique_ptr gTVRAM; TVRAMDevice::TVRAMDevice() { @@ -23,14 +23,11 @@ TVRAMDevice::TVRAMDevice() devaddr = baseaddr; devlen = 512 * 1024; - mem = new uint8[devlen](); + mem.reset(new uint8[devlen]); } TVRAMDevice::~TVRAMDevice() { - if (mem) { - delete[] mem; - } } void @@ -40,24 +37,30 @@ TVRAMDevice::ResetHard() Invalidate(); } +inline uint64 +TVRAMDevice::Decoder(uint32 addr) const +{ + return addr - baseaddr; +} + uint64 TVRAMDevice::Read8(uint32 addr) { - uint32 offset = addr - baseaddr; + uint32 offset = Decoder(addr); return mem[HB(offset)]; } uint64 TVRAMDevice::Read16(uint32 addr) { - uint32 offset = addr - baseaddr; + uint32 offset = Decoder(addr); return *(uint16 *)&mem[offset]; } uint64 TVRAMDevice::Write8(uint32 addr, uint32 data) { - uint32 offset = addr - baseaddr; + uint32 offset = Decoder(addr); // XXX とりあえずね putlog(3, "Write $%06x <- $%02x", addr, data); @@ -81,7 +84,7 @@ TVRAMDevice::Write8(uint32 addr, uint32 uint64 TVRAMDevice::Write16(uint32 addr, uint32 data) { - uint32 offset = addr - baseaddr; + uint32 offset = Decoder(addr); // XXX とりあえずね putlog(3, "Write $%06x <- $%04x", addr, data); @@ -105,7 +108,8 @@ TVRAMDevice::Write16(uint32 addr, uint32 uint64 TVRAMDevice::Peek8(uint32 addr) { - return mem[HB(addr - baseaddr)]; + uint32 offset = Decoder(addr); + return mem[HB(offset)]; } // 全画面の更新フラグを立てる @@ -182,10 +186,10 @@ TVRAMDevice::Render(uint8 *imagebuf) // XXX スクロールは未実装 // テキスト画面 - plane0 = (uint16 *)mem; - plane1 = (uint16 *)(mem + 0x20000); - plane2 = (uint16 *)(mem + 0x40000); - plane3 = (uint16 *)(mem + 0x60000); + plane0 = (uint16 *)&mem[0x00000]; + plane1 = (uint16 *)&mem[0x20000]; + plane2 = (uint16 *)&mem[0x40000]; + plane3 = (uint16 *)&mem[0x60000]; int sy = 0; for (int dy = 0; dy < 512; dst0 += 768 * Renderer::BPP, dy++, sy++) { sy &= 0x3ff;