--- nono/vm/console.h 2026/04/29 17:05:55 1.1.1.4 +++ nono/vm/console.h 2026/04/29 17:06:00 1.1.1.5 @@ -17,15 +17,17 @@ #include class BitmapRGBX; -class COMDriver; class COMDriverConsole; +class ConsoleKeyboard; +class Syncer; class ConsoleDevice : public Device { using inherited = Device; - static const uint width = 80; - static const uint height = 30; + static const uint fullwidth = 132; // 仮想画面幅 + static const uint dispwidth = 80; // 表示画面幅 + static const uint height = 24; static const uint font_width = 8; static const uint font_height = 16; @@ -37,7 +39,7 @@ class ConsoleDevice : public Device // 3 2 1 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // +---------------+---------------+---------------+---------------+ - // | bgcolor | fgcolor |R| |D|O|S|U|I|B| 文字コード | + // | bgcolor | fgcolor |R|L|D|O|S|U|I|B| 文字コード | // +---------------+---------------+---------------+---------------+ // // bgcolor, fgcolor はカラーパレット番号。 @@ -48,6 +50,7 @@ class ConsoleDevice : public Device static const uint32 ATTR_STRIKE = 0x0000'0800; // S: 打ち消し線 static const uint32 ATTR_OVERLINE = 0x0000'1000; // O: 上線 static const uint32 ATTR_DECSG = 0x0000'2000; // D: DEC 特殊文字 + static const uint32 ATTR_BLINK = 0x0000'4000; // L: 低速点滅 static const uint32 ATTR_REVERSE = 0x0000'8000; // R: 反転(暫定) static const uint32 ATTR_LINEMASK = (ATTR_UNDERLINE | @@ -64,23 +67,30 @@ class ConsoleDevice : public Device bool Init() override; void ResetHard(bool poweron) override; - void Attach(COMDriver *); + void Attach(COMDriverConsole *); void Detach() { Attach(NULL); } void Putchar(uint32); + std::string ToString() const; + bool Render(BitmapRGBX& dst); private: void VSyncCallback(Event *); void SetPalette(bool console_is_active); - void ResetTerminal(); + void ResetTerminalSoft(); + void ResetTerminalHard(); + void ResetMargin(); + void ResetScroll(); void ResetState(); void PutcharPlain(uint32); void PutcharDebug(uint32); bool PutcharESC(uint32); bool PutcharCSI(uint32); bool PutcharCSIQ(uint32); + bool PutcharSharp(uint32); + bool PutcharG0(uint32); void Clear(); @@ -90,16 +100,23 @@ class ConsoleDevice : public Device LocateX(x); LocateY(y); } + void LocateXinMargin(int x); + void LocateYinScroll(int y); + + void CopyLineWhole(int dst, int src); + void CopyLineMargin(int dst, int src); + void EraseLineWhole(int y); + void EraseLineMargin(int y); + + // 現在位置に、現在の属性で文字 ch を出力する。出力後カーソルは移動する。 + void PutcharNormal(uint32); + + // (x, y) の位置に chattr を出力する。カーソルは移動しない。 + void Setchar(int x, int y, uint32 chattr); - void Ascend(); + void HT(); void CR(); void LF(); - void CRLF() { - CR(); - LF(); - } - void ScrollUp(); - void ScrollDown(); // 現在位置に、現在の属性で文字 ch を出力する。出力後カーソルは移動する。 void Putc(uint32 ch); @@ -110,18 +127,58 @@ class ConsoleDevice : public Device // 現在の属性を設定する。 void SetAttr(uint32 new_attr); + // 未実装シーケンス。 + bool Unimpl(uint32 ch, const char *name = NULL); + + int GetArgDefault(int defval); + int GetArg() { return GetArgDefault(0); } + int ParseArg(); + + // 送信。 + void SendString(const std::string&); + std::string Dump() const; std::string Dump(uint32 ch) const; static std::string Dump(const std::vector&); - // 画面は 1文字分が uint32 の [width * height] の配列。 + // 画面は 1文字分が uint32 の [fullwidth * height] の配列。 std::vector screen {}; + // 仮想画面幅。(表示は80桁固定) + int width {}; + // カーソル位置。 int cur_x {}; int cur_y {}; + // 左右マージン。両閉区間で表す。 + // 例えばデフォルトの [0, width) なら left=0, right=width-1。 + int margin_left {}; + int margin_right {}; + + // スクロール領域。両閉区間で表す。 + // 例えばデフォルトの [0, height) なら top=0, btm=height-1。 + int scroll_top {}; + int scroll_btm {}; + + // 遅延折り返し。 + bool wrap_pending {}; + + // 拡張オプション。 + bool insert_mode {}; + bool cr_on_lf {}; + bool decom {}; + bool cursor_visible {}; + + // DECSC で保存するパラメータ。 + int save_x {}; + int save_y {}; + uint32 save_attr {}; + bool save_wrap {}; + bool save_decom {}; + // VM スレッド内での行ごとの更新情報。 bitsetH dirty {}; + // レンダラスレッドで未処理の行。 // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。 bitsetH pending {}; @@ -134,6 +191,10 @@ class ConsoleDevice : public Device char state {}; // 現在の属性。 uint32 cur_attr {}; + // 行ごとに点滅文字を持っているか。 + bitsetH has_blink {}; + // 点滅の滅なら true。 + bool blinking {}; // パレット。 // [0..1] だと通常色、[1..2] だと反転色になる。 @@ -143,14 +204,10 @@ class ConsoleDevice : public Device std::vector seq {}; // パラメータ部分。 std::string arg {}; - - // カーソル位置保存。 - int save_curx {}; - int save_cury {}; - - // スクロール範囲。[0, height) の座標系。 - int scroll_top {}; - int scroll_btm {}; + // セミコロンで分解したもの。 + std::vector argv {}; + // 処理中の位置。-1 なら分解前。 + int argv_idx {}; // デバッグログ。 FILE *log {}; @@ -159,9 +216,12 @@ class ConsoleDevice : public Device Event *vsync_event {}; VideoRenderer *renderer {}; - COMDriver *comdriver {}; + COMDriverConsole *comdriver {}; + ConsoleKeyboard *keyboard {}; + Syncer *syncer {}; static const uint8 decsg8x16[15 * font_height]; + static const uint8 tofu8x16[font_height]; }; // 入力担当デバイス @@ -177,10 +237,15 @@ class ConsoleKeyboard : public DumbKeybo void CharInput(uint charcode) override; + void SetCKM(bool val); + private: + // 拡張オプション。 + char ckm_char {}; + COMDriverConsole *comdriver {}; }; -static inline ConsoleDevice *GetConsoleDevice() { +inline ConsoleDevice *GetConsoleDevice() { return Object::GetObject(OBJ_CONSOLE); }