--- nono/vm/console.h 2026/04/29 17:05:33 1.1.1.1 +++ nono/vm/console.h 2026/04/29 17:05:55 1.1.1.4 @@ -11,14 +11,14 @@ #pragma once #include "device.h" -#include "event.h" #include "keyboard.h" #include "renderer.h" +#include #include class BitmapRGBX; class COMDriver; -class COMDriverCons; +class COMDriverConsole; class ConsoleDevice : public Device { @@ -29,6 +29,8 @@ class ConsoleDevice : public Device static const uint font_width = 8; static const uint font_height = 16; + using bitsetH = std::bitset; + // 1文字 32ビットのうち下位8ビットが文字コード、上位24ビットが各種属性。 // // @@ -63,12 +65,15 @@ class ConsoleDevice : public Device void ResetHard(bool poweron) override; void Attach(COMDriver *); + void Detach() { Attach(NULL); } + void Putchar(uint32); bool Render(BitmapRGBX& dst); private: - void VSyncCallback(Event&); + void VSyncCallback(Event *); + void SetPalette(bool console_is_active); void ResetTerminal(); void ResetState(); void PutcharPlain(uint32); @@ -116,10 +121,10 @@ class ConsoleDevice : public Device int cur_y {}; // VM スレッド内での行ごとの更新情報。 - std::vector dirty {}; + bitsetH dirty {}; // レンダラスレッドで未処理の行。 // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。 - std::vector pending {}; + bitsetH pending {}; std::mutex mtx {}; // 画面初期化。 @@ -130,6 +135,10 @@ class ConsoleDevice : public Device // 現在の属性。 uint32 cur_attr {}; + // パレット。 + // [0..1] だと通常色、[1..2] だと反転色になる。 + Color palette[3] {}; + // 現在の1文字前までのエスケープシーケンス。(現在の文字は ch) std::vector seq {}; // パラメータ部分。 @@ -147,13 +156,12 @@ class ConsoleDevice : public Device FILE *log {}; bool log_newline {}; - Event vsync_event { this }; + Event *vsync_event {}; - Renderer *renderer {}; + VideoRenderer *renderer {}; COMDriver *comdriver {}; static const uint8 decsg8x16[15 * font_height]; - static const Color palette[3]; }; // 入力担当デバイス @@ -164,12 +172,13 @@ class ConsoleKeyboard : public DumbKeybo ConsoleKeyboard(); ~ConsoleKeyboard() override; - void Attach(COMDriverCons *); + void Attach(COMDriverConsole *); + void Detach() { Attach(NULL); } void CharInput(uint charcode) override; private: - COMDriverCons *comdriver {}; + COMDriverConsole *comdriver {}; }; static inline ConsoleDevice *GetConsoleDevice() {