--- nono/vm/planevram.h 2026/04/29 17:05:11 1.1.1.1 +++ nono/vm/planevram.h 2026/04/29 17:05:51 1.1.1.7 @@ -12,56 +12,65 @@ #pragma once #include "device.h" -#include "renderer.h" -#include +#include "bitmap.h" +#include +#include class PlaneVRAMDevice : public IODevice { using inherited = IODevice; - protected: - // ショートカット - static const int BLKX = Renderer::BLKX; - static const int BLKY = Renderer::BLKY; + using bitset1024 = std::bitset<1024>; + + // 更新情報。 + struct ModifyInfo + { + // 1ライン単位の更新フラグ。 + // 仮想 Y 座標に対応するので Lunafb も TVRAM も 1024個。 + bitset1024 line {}; + + // パレットを更新した場合やスクロールした場合のように、 + // composite に変更がなくても bitmap を更新する必要がある場合は true。 + bool invalidate2 {}; + }; public: - PlaneVRAMDevice(const std::string& objname_, int width_, int height_); - virtual ~PlaneVRAMDevice() override; + PlaneVRAMDevice(int width_, int height_); + ~PlaneVRAMDevice() override; + bool Init() override; void ResetHard(bool poweron) override; - // レンダリング時に使うテーブルを事前に計算する。 - void InitDeptable(); - // プレーン数を取得 - int GetPlaneCount() const { return nplane; } - - // 更新情報を取得 - ModifyInfo GetModify() const; + uint GetPlaneCount() const { return nplane; } - // 更新フラグをクリア - void ClearDirty(); + bool Snap(); // 画面を合成する - bool Render(BitmapRGB& dst, const ModifyInfo& modify); + bool Render(BitmapRGBX& dst); + + // VRAM には更新がないが再レンダリングが必要。(パレット変更、スクロール等) + void Invalidate2(); // 合成ビットマップを取得する const BitmapI8& GetComposite() const { return composite; } -#if defined(PERF_HIT) - // ブロックのヒット効率(?)を調べる - std::array dirty_word {}; -#endif + // 座標位置の情報を出力 (GUI 用) + virtual void UpdateInfo(TextScreen&, int x, int y) const = 0; protected: // 全画面の更新フラグを立てる void Invalidate(); // 垂直 VRAM から BitmapI8 バッファを作成する - void RenderVRAMToComposite(const ModifyInfo& modify); + void RenderVRAMToComposite(const bitset1024& modified); + + // BitmapI8 バッファから BitmapRGBX を作成する。 + void RenderCompositeToRGBX(BitmapRGBX& dst, + const ModifyInfo& modified); - // BitmapI8 バッファから BitmapRGB を作成する。 - void RenderCompositeToRGB(BitmapRGB& dst, const ModifyInfo& modify); + // X 方向にはみ出したときに対応する仮想画面の Y 座標を返す。 + virtual int GetWrapY(int) const = 0; // ビットマッププレーン。 // メモリを確保する時のサイズ計算のため型を uint8 にしているが、 @@ -70,28 +79,30 @@ class PlaneVRAMDevice : public IODevice std::unique_ptr mem {}; // プレーン数 (TVRAM なら 4 固定、LUNA は設定による) - int nplane {}; + uint nplane {}; // テキスト画面の合成ビットマップ BitmapI8 composite {}; - // 更新フラグ。 - // Lunafb では 1024、TVRAM では 512個。 - std::vector dirty {}; - - // ModifyInfo.bits に対するマスク。横方向のブロック数によって決まり、 - // Lunafb では 0xffff、TVRAM では 0xff00。 - uint16 modify_mask {}; + // VM スレッド内での仮想画面の更新フラグ。 + ModifyInfo dirty {}; + + // レンダラスレッドで未処理の行。 + // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。 + ModifyInfo pending {}; + std::mutex mtx {}; // レンダリング時に使う変換テーブル std::unique_ptr deptable {}; // ホストパレット - const ColorXBGR *palette {}; + const Color *palette {}; // スクロール int xscroll {}; int yscroll {}; }; -extern PlaneVRAMDevice *gPlaneVRAM; +static inline PlaneVRAMDevice *GetPlaneVRAMDevice() { + return Object::GetObject(OBJ_PLANEVRAM); +}