--- nono/vm/planevram.h 2026/04/29 17:05:18 1.1.1.2 +++ nono/vm/planevram.h 2026/04/29 17:05:51 1.1.1.7 @@ -12,33 +12,45 @@ #pragma once #include "device.h" -#include "renderer.h" -#include +#include "bitmap.h" +#include +#include class PlaneVRAMDevice : public IODevice { using inherited = IODevice; + using bitset1024 = std::bitset<1024>; + + // 更新情報。 + struct ModifyInfo + { + // 1ライン単位の更新フラグ。 + // 仮想 Y 座標に対応するので Lunafb も TVRAM も 1024個。 + bitset1024 line {}; + + // パレットを更新した場合やスクロールした場合のように、 + // composite に変更がなくても bitmap を更新する必要がある場合は true。 + bool invalidate2 {}; + }; + public: PlaneVRAMDevice(int width_, int height_); - virtual ~PlaneVRAMDevice() override; + ~PlaneVRAMDevice() override; + bool Init() override; void ResetHard(bool poweron) override; - // レンダリング時に使うテーブルを事前に計算する。 - void InitDeptable(); - // プレーン数を取得 - int GetPlaneCount() const { return nplane; } + uint GetPlaneCount() const { return nplane; } - // 更新情報を取得 - ModifyInfo GetModify() const; - - // 更新フラグをクリア - void ClearDirty(); + bool Snap(); // 画面を合成する - bool Render(BitmapRGB& dst, const ModifyInfo& modify); + bool Render(BitmapRGBX& dst); + + // VRAM には更新がないが再レンダリングが必要。(パレット変更、スクロール等) + void Invalidate2(); // 合成ビットマップを取得する const BitmapI8& GetComposite() const { return composite; } @@ -51,10 +63,11 @@ class PlaneVRAMDevice : public IODevice void Invalidate(); // 垂直 VRAM から BitmapI8 バッファを作成する - void RenderVRAMToComposite(const ModifyInfo& modify); + void RenderVRAMToComposite(const bitset1024& modified); - // BitmapI8 バッファから BitmapRGB を作成する。 - void RenderCompositeToRGB(BitmapRGB& dst, const ModifyInfo& modify); + // BitmapI8 バッファから BitmapRGBX を作成する。 + void RenderCompositeToRGBX(BitmapRGBX& dst, + const ModifyInfo& modified); // X 方向にはみ出したときに対応する仮想画面の Y 座標を返す。 virtual int GetWrapY(int) const = 0; @@ -66,20 +79,24 @@ class PlaneVRAMDevice : public IODevice std::unique_ptr mem {}; // プレーン数 (TVRAM なら 4 固定、LUNA は設定による) - int nplane {}; + uint nplane {}; // テキスト画面の合成ビットマップ BitmapI8 composite {}; - // 仮想画面の更新フラグ。仮想 Y 座標に対応するので - // Lunafb も TVRAM も 1024個。 - std::vector dirty {}; + // VM スレッド内での仮想画面の更新フラグ。 + ModifyInfo dirty {}; + + // レンダラスレッドで未処理の行。 + // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。 + ModifyInfo pending {}; + std::mutex mtx {}; // レンダリング時に使う変換テーブル std::unique_ptr deptable {}; // ホストパレット - const ColorXBGR *palette {}; + const Color *palette {}; // スクロール int xscroll {};