--- nono/vm/videoctlr.h 2026/04/29 17:05:32 1.1.1.11 +++ nono/vm/videoctlr.h 2026/04/29 17:05:54 1.1.1.13 @@ -13,19 +13,71 @@ #include "device.h" #include "bitmap.h" #include "color.h" -#include "event.h" #include #include +class GVRAMDevice; class PlaneVRAMDevice; -class Renderer; +class VideoRenderer; +class UIMessage; -class VideoCtlrDevice : public IODevice +class VideoCtlr +{ + public: + // f e d c b a 9 8 7 6 5 4 3 2 1 0 + // +--------------------------------------+--+-----+ + // R0 | |SZ| COL | + // +--------------------------------------+--+-----+ + static constexpr uint32 R0_SIZ = 0x0004; + static constexpr uint32 R0_COL = 0x0003; + + // f e d c b a 9 8 7 6 5 4 3 2 1 0 + // +-----+-----+-----+-----+-----+-----+-----+-----+ + // R1 | %00 | SP | TX | GR | GP3 | GP2 | GP1 | GP0 | + // +-----+-----+-----+-----+-----+-----+-----+-----+ + static constexpr uint32 R1_SP = 0x3000; // スプライト優先度 + static constexpr uint32 R1_TX = 0x0c00; // テキスト画面優先度 + static constexpr uint32 R1_GR = 0x0300; // グラフィック画面優先度 + static constexpr uint32 R1_G3 = 0x00c0; // GP3 優先度 + static constexpr uint32 R1_G2 = 0x0030; // GP2 優先度 + static constexpr uint32 R1_G1 = 0x000c; // GP1 優先度 + static constexpr uint32 R1_G0 = 0x0003; // GP0 優先度 + + // f e d c b a 9 8 7 6 5 4 3 2 1 0 + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // R2 |YS|AH|VH|EX|HP|BP|GG|GT| |SO|TO|GO|G3|G2|G1|G0| + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + static constexpr uint32 R2_YS = 0x8000; + static constexpr uint32 R2_AH = 0x4000; + static constexpr uint32 R2_VH = 0x2000; + static constexpr uint32 R2_EX = 0x1000; + static constexpr uint32 R2_HP = 0x0800; + static constexpr uint32 R2_BP = 0x0400; + static constexpr uint32 R2_GG = 0x0200; + static constexpr uint32 R2_GT = 0x0100; + static constexpr uint32 R2_SP_ON = 0x0040; // スプライトオン + static constexpr uint32 R2_TX_ON = 0x0020; // テキスト画面オン + static constexpr uint32 R2_GR_ON = 0x0010; // グラフィック画面オン + static constexpr uint32 R2_G3_ON = 0x0008; // グラフィック(P3)オン + static constexpr uint32 R2_G2_ON = 0x0004; // グラフィック(P2)オン + static constexpr uint32 R2_G1_ON = 0x0002; // グラフィック(P1)オン + static constexpr uint32 R2_G0_ON = 0x0001; // グラフィック(P0)オン +}; + +class VideoCtlrDevice : public IODevice, public VideoCtlr { using inherited = IODevice; static const uint32 baseaddr = 0xe82000; + // 描画順のための描画フラグ + static constexpr uint32 SORDER_NONE = 0x0; + static constexpr uint32 SORDER_SP = 0x1; + static constexpr uint32 SORDER_TX = 0x2; + static constexpr uint32 SORDER_GR = 0x3; + static constexpr uint32 SORDER_BG = 0x4; + static constexpr uint32 SORDER_BLACK = 0x5; // 仮想的な背景 + public: VideoCtlrDevice(); ~VideoCtlrDevice() override; @@ -49,12 +101,24 @@ class VideoCtlrDevice : public IODevice // 画面合成 bool Render(BitmapRGBX& dst); - // 加工済みテキストパレットの先頭アドレスを取得 - // レンダラとかからの参照用 + // モニタ更新(下請け) + int MonitorUpdate(TextScreen&, int y, uint32 crtc_r20); + + // グラフィック画面を取得。(モニタ用) + const BitmapRGBX& GetGraphicBitmap() const { return grbmp; } + + // ホストパレットを取得。(レンダラとかからの参照用) const std::vector& GetHostPalette() const { return hostcolor; } - // 生パレットを uint32 形式にしたものを返す (GUI 用) - const std::vector GetIntPalette() const; + // ホストパレットのアドレスを取得。 + const Color *GetHostPalettePtr(int idx) const { return &hostcolor[idx]; } + + // ゲストパレットを取得。(GUI 情報表示用) + const std::vector& GetGuestPalette() const { return palette; } + + // モニタ用。CRTC からも使う。 + static const char * const siz_str[2]; + static const char * const col_str[4]; private: static inline uint32 Decoder(uint32 addr); @@ -76,20 +140,29 @@ class VideoCtlrDevice : public IODevice bool enable_neon {}; #endif - void ContrastCallback(Event& ev); + void ContrastCallback(Event *); // ワードレジスタ R0, R1, R2 std::array reg {}; + uint16 prev_reg1 {}; + uint16 prev_reg2 {}; - // テキスト画面 - BitmapRGBX textbmp {}; + // 各画面 + BitmapRGBX txbmp {}; + BitmapRGBX grbmp {}; + + // 合成画面 (コントラスト適用前) + BitmapRGBX mixbmp {}; // パレット (ホストバイトオーダー) - std::array palette {}; + std::vector palette {}; // ホスト形式のテキストパレット (レンダラ用に加工したもの) std::vector hostcolor {}; + // 描画順 (SORDER_* を LSB 側から4ビットずつ並べる) + uint32 screen_order {}; + // 設定したコントラスト値 (0-255) uint32 target_contrast {}; // 現在の (遷移中かもしれない) コントラスト値 (0-255) @@ -105,10 +178,12 @@ class VideoCtlrDevice : public IODevice // レンダリングに使っているコントラスト値 (0-255) uint32 rendering_contrast {}; - Event contrast_event { this }; + Event *contrast_event {}; + GVRAMDevice *gvram {}; PlaneVRAMDevice *planevram {}; - Renderer *renderer {}; + UIMessage *uimessage {}; + VideoRenderer *renderer {}; }; static inline VideoCtlrDevice *GetVideoCtlrDevice() {