Annotation of nono/vm/console.h, revision 1.1.1.5

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2024 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
                      8: // メイン画面をコンソールにする
                      9: //
                     10: 
                     11: #pragma once
                     12: 
                     13: #include "device.h"
                     14: #include "keyboard.h"
                     15: #include "renderer.h"
1.1.1.3   root       16: #include <bitset>
1.1       root       17: #include <vector>
                     18: 
                     19: class BitmapRGBX;
1.1.1.2   root       20: class COMDriverConsole;
1.1.1.5 ! root       21: class ConsoleKeyboard;
        !            22: class Syncer;
1.1       root       23: 
                     24: class ConsoleDevice : public Device
                     25: {
                     26:        using inherited = Device;
                     27: 
1.1.1.5 ! root       28:        static const uint fullwidth = 132;      // 仮想画面幅
        !            29:        static const uint dispwidth = 80;       // 表示画面幅
        !            30:        static const uint height = 24;
1.1       root       31:        static const uint font_width  = 8;
                     32:        static const uint font_height = 16;
                     33: 
1.1.1.3   root       34:        using bitsetH = std::bitset<height>;
                     35: 
1.1       root       36:        // 1文字 32ビットのうち下位8ビットが文字コード、上位24ビットが各種属性。
                     37:        //
                     38:        //
                     39:        //    3                   2                   1
                     40:        //  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
                     41:        // +---------------+---------------+---------------+---------------+
1.1.1.5 ! root       42:        // |    bgcolor    |    fgcolor    |R|L|D|O|S|U|I|B|   文字コード  |
1.1       root       43:        // +---------------+---------------+---------------+---------------+
                     44:        //
                     45:        // bgcolor, fgcolor はカラーパレット番号。
                     46: 
                     47:        static const uint32 ATTR_BOLD           = 0x0000'0100;  // B: ボールド
                     48:        static const uint32 ATTR_ITALIC         = 0x0000'0200;  // I: イタリック
                     49:        static const uint32 ATTR_UNDERLINE      = 0x0000'0400;  // U: 下線
                     50:        static const uint32 ATTR_STRIKE         = 0x0000'0800;  // S: 打ち消し線
                     51:        static const uint32 ATTR_OVERLINE       = 0x0000'1000;  // O: 上線
                     52:        static const uint32 ATTR_DECSG          = 0x0000'2000;  // D: DEC 特殊文字
1.1.1.5 ! root       53:        static const uint32 ATTR_BLINK          = 0x0000'4000;  // L: 低速点滅
1.1       root       54:        static const uint32 ATTR_REVERSE        = 0x0000'8000;  // R: 反転(暫定)
                     55: 
                     56:        static const uint32 ATTR_LINEMASK       = (ATTR_UNDERLINE |
                     57:                                                                                   ATTR_STRIKE |
                     58:                                                                                   ATTR_OVERLINE);
                     59: 
                     60:        // フチ [pixel]
                     61:        static const uint Padding = ConsoleRenderer::Padding;
                     62: 
                     63:  public:
                     64:        ConsoleDevice();
                     65:        ~ConsoleDevice() override;
                     66: 
                     67:        bool Init() override;
                     68:        void ResetHard(bool poweron) override;
                     69: 
1.1.1.5 ! root       70:        void Attach(COMDriverConsole *);
1.1.1.2   root       71:        void Detach() { Attach(NULL); }
                     72: 
1.1       root       73:        void Putchar(uint32);
                     74: 
1.1.1.5 ! root       75:        std::string ToString() const;
        !            76: 
1.1       root       77:        bool Render(BitmapRGBX& dst);
                     78: 
                     79:  private:
1.1.1.3   root       80:        void VSyncCallback(Event *);
1.1.1.2   root       81:        void SetPalette(bool console_is_active);
1.1.1.5 ! root       82:        void ResetTerminalSoft();
        !            83:        void ResetTerminalHard();
        !            84:        void ResetMargin();
        !            85:        void ResetScroll();
1.1       root       86:        void ResetState();
                     87:        void PutcharPlain(uint32);
                     88:        void PutcharDebug(uint32);
                     89:        bool PutcharESC(uint32);
                     90:        bool PutcharCSI(uint32);
                     91:        bool PutcharCSIQ(uint32);
1.1.1.5 ! root       92:        bool PutcharSharp(uint32);
        !            93:        bool PutcharG0(uint32);
1.1       root       94: 
                     95:        void Clear();
                     96: 
                     97:        void LocateX(int x);
                     98:        void LocateY(int y);
                     99:        void Locate(int x, int y) {
                    100:                LocateX(x);
                    101:                LocateY(y);
                    102:        }
1.1.1.5 ! root      103:        void LocateXinMargin(int x);
        !           104:        void LocateYinScroll(int y);
        !           105: 
        !           106:        void CopyLineWhole(int dst, int src);
        !           107:        void CopyLineMargin(int dst, int src);
        !           108:        void EraseLineWhole(int y);
        !           109:        void EraseLineMargin(int y);
        !           110: 
        !           111:        // 現在位置に、現在の属性で文字 ch を出力する。出力後カーソルは移動する。
        !           112:        void PutcharNormal(uint32);
        !           113: 
        !           114:        // (x, y) の位置に chattr を出力する。カーソルは移動しない。
        !           115:        void Setchar(int x, int y, uint32 chattr);
1.1       root      116: 
1.1.1.5 ! root      117:        void HT();
1.1       root      118:        void CR();
                    119:        void LF();
                    120: 
                    121:        // 現在位置に、現在の属性で文字 ch を出力する。出力後カーソルは移動する。
                    122:        void Putc(uint32 ch);
                    123: 
                    124:        // (x, y) の位置に chattr を出力する。カーソルは移動しない。
                    125:        void Setc(int x, int y, uint32 chattr);
                    126: 
                    127:        // 現在の属性を設定する。
                    128:        void SetAttr(uint32 new_attr);
                    129: 
1.1.1.5 ! root      130:        // 未実装シーケンス。
        !           131:        bool Unimpl(uint32 ch, const char *name = NULL);
        !           132: 
        !           133:        int GetArgDefault(int defval);
        !           134:        int GetArg() { return GetArgDefault(0); }
        !           135:        int ParseArg();
        !           136: 
        !           137:        // 送信。
        !           138:        void SendString(const std::string&);
        !           139: 
1.1       root      140:        std::string Dump() const;
                    141:        std::string Dump(uint32 ch) const;
                    142:        static std::string Dump(const std::vector<uint8>&);
                    143: 
1.1.1.5 ! root      144:        // 画面は 1文字分が uint32 の [fullwidth * height] の配列。
1.1       root      145:        std::vector<uint32> screen {};
1.1.1.5 ! root      146:        // 仮想画面幅。(表示は80桁固定)
        !           147:        int width {};
        !           148: 
1.1       root      149:        // カーソル位置。
                    150:        int cur_x {};
                    151:        int cur_y {};
                    152: 
1.1.1.5 ! root      153:        // 左右マージン。両閉区間で表す。
        !           154:        // 例えばデフォルトの [0, width) なら left=0, right=width-1。
        !           155:        int margin_left {};
        !           156:        int margin_right {};
        !           157: 
        !           158:        // スクロール領域。両閉区間で表す。
        !           159:        // 例えばデフォルトの [0, height) なら top=0, btm=height-1。
        !           160:        int scroll_top {};
        !           161:        int scroll_btm {};
        !           162: 
        !           163:        // 遅延折り返し。
        !           164:        bool wrap_pending {};
        !           165: 
        !           166:        // 拡張オプション。
        !           167:        bool insert_mode {};
        !           168:        bool cr_on_lf {};
        !           169:        bool decom {};
        !           170:        bool cursor_visible {};
        !           171: 
        !           172:        // DECSC で保存するパラメータ。
        !           173:        int save_x {};
        !           174:        int save_y {};
        !           175:        uint32 save_attr {};
        !           176:        bool save_wrap {};
        !           177:        bool save_decom {};
        !           178: 
1.1       root      179:        // VM スレッド内での行ごとの更新情報。
1.1.1.3   root      180:        bitsetH dirty {};
1.1.1.5 ! root      181: 
1.1       root      182:        // レンダラスレッドで未処理の行。
                    183:        // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。
1.1.1.3   root      184:        bitsetH pending {};
1.1       root      185:        std::mutex mtx {};
                    186: 
                    187:        // 画面初期化。
                    188:        bool init_screen {};
                    189: 
                    190:        // 現在の状態。
                    191:        char state {};
                    192:        // 現在の属性。
                    193:        uint32 cur_attr {};
1.1.1.5 ! root      194:        // 行ごとに点滅文字を持っているか。
        !           195:        bitsetH has_blink {};
        !           196:        // 点滅の滅なら true。
        !           197:        bool blinking {};
1.1       root      198: 
1.1.1.2   root      199:        // パレット。
                    200:        // [0..1] だと通常色、[1..2] だと反転色になる。
                    201:        Color palette[3] {};
                    202: 
1.1       root      203:        // 現在の1文字前までのエスケープシーケンス。(現在の文字は ch)
                    204:        std::vector<uint8> seq {};
                    205:        // パラメータ部分。
                    206:        std::string arg {};
1.1.1.5 ! root      207:        // セミコロンで分解したもの。
        !           208:        std::vector<std::string> argv {};
        !           209:        // 処理中の位置。-1 なら分解前。
        !           210:        int argv_idx {};
1.1       root      211: 
                    212:        // デバッグログ。
                    213:        FILE *log {};
                    214:        bool log_newline {};
                    215: 
1.1.1.3   root      216:        Event *vsync_event {};
1.1       root      217: 
1.1.1.4   root      218:        VideoRenderer *renderer {};
1.1.1.5 ! root      219:        COMDriverConsole *comdriver {};
        !           220:        ConsoleKeyboard *keyboard {};
        !           221:        Syncer *syncer {};
1.1       root      222: 
                    223:        static const uint8 decsg8x16[15 * font_height];
1.1.1.5 ! root      224:        static const uint8 tofu8x16[font_height];
1.1       root      225: };
                    226: 
                    227: // 入力担当デバイス
                    228: class ConsoleKeyboard : public DumbKeyboard
                    229: {
                    230:        using inherited = DumbKeyboard;
                    231:  public:
                    232:        ConsoleKeyboard();
                    233:        ~ConsoleKeyboard() override;
                    234: 
1.1.1.2   root      235:        void Attach(COMDriverConsole *);
                    236:        void Detach() { Attach(NULL); }
1.1       root      237: 
                    238:        void CharInput(uint charcode) override;
                    239: 
1.1.1.5 ! root      240:        void SetCKM(bool val);
        !           241: 
1.1       root      242:  private:
1.1.1.5 ! root      243:        // 拡張オプション。
        !           244:        char ckm_char {};
        !           245: 
1.1.1.2   root      246:        COMDriverConsole *comdriver {};
1.1       root      247: };
                    248: 
1.1.1.5 ! root      249: inline ConsoleDevice *GetConsoleDevice() {
1.1       root      250:        return Object::GetObject<ConsoleDevice>(OBJ_CONSOLE);
                    251: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.