--- nono/vm/tvram.cpp 2026/04/29 17:04:28 1.1 +++ nono/vm/tvram.cpp 2026/04/29 17:04:36 1.1.1.3 @@ -1,20 +1,24 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + // // TVRAM // -#include "renderer.h" #include "tvram.h" -#include "vicon.h" +#include "crtc.h" +#include "renderer.h" +#include "videoctlr.h" // // TVRAM はワード単位でホストバイトオーダ配置なので、 // バイトアクセス時は HB() マクロを使用のこと。 // -TVRAMDevice *gTVRAM; +std::unique_ptr gTVRAM; TVRAMDevice::TVRAMDevice() { @@ -23,14 +27,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 +41,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 +88,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 +112,8 @@ TVRAMDevice::Write16(uint32 addr, uint32 uint64 TVRAMDevice::Peek8(uint32 addr) { - return mem[HB(addr - baseaddr)]; + uint32 offset = Decoder(addr); + return mem[HB(offset)]; } // 全画面の更新フラグを立てる @@ -117,6 +125,20 @@ TVRAMDevice::Invalidate() } } +void +TVRAMDevice::SetScrollX(int x) +{ + tvram.xscroll = x; +} + +void +TVRAMDevice::SetScrollY(int y) +{ + tvram.yscroll = y; + // 全ラインを無効にする XXX とりあえずね + Invalidate(); +} + // CRTC R21 での同時アクセス設定を反映する // CRTC から呼ばれる void @@ -157,7 +179,7 @@ TVRAMDevice::Render(uint8 *imagebuf) dst0 = imagebuf; // パレット取得 - palette_w = gVicon->GetPalette(); + palette_w = gVideoCtlr->GetPalette(); // パレット前半 256 ワードはグラフィックパレット、 // テキストパレットは後半。 palette_w += 0x100; @@ -182,11 +204,11 @@ TVRAMDevice::Render(uint8 *imagebuf) // XXX スクロールは未実装 // テキスト画面 - plane0 = (uint16 *)mem; - plane1 = (uint16 *)(mem + 0x20000); - plane2 = (uint16 *)(mem + 0x40000); - plane3 = (uint16 *)(mem + 0x60000); - int sy = 0; + plane0 = (uint16 *)&mem[0x00000]; + plane1 = (uint16 *)&mem[0x20000]; + plane2 = (uint16 *)&mem[0x40000]; + plane3 = (uint16 *)&mem[0x60000]; + int sy = tvram.yscroll; for (int dy = 0; dy < 512; dst0 += 768 * Renderer::BPP, dy++, sy++) { sy &= 0x3ff;