Annotation of nono/lib/mainapp.h, revision 1.1.1.13

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.11  root        7: //
                      8: // CLI/GUI 共通のメイン部分
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
1.1.1.12  root       13: #include "object.h"
1.1.1.11  root       14: 
                     15: class Config;
                     16: class Logger;
                     17: class MonitorManager;
1.1.1.12  root       18: class VM;
                     19: 
                     20: // VM 種別
                     21: enum class VMType {
                     22:        NONE = 0,
                     23:        X68030,
                     24:        LUNA1,
                     25:        LUNA88K,
1.1.1.13! root       26:        NEWS,
1.1.1.12  root       27: };
                     28: 
                     29: // VM ケーパビリティ (ビットマスク表現)
                     30: enum class VMCap : uint32 {
                     31:        NONE    = 0,
                     32:        X68030  = (1U << (int)VMType::X68030),
                     33:        LUNA1   = (1U << (int)VMType::LUNA1),
                     34:        LUNA88K = (1U << (int)VMType::LUNA88K),
1.1.1.13! root       35:        NEWS    = (1U << (int)VMType::NEWS),
1.1.1.12  root       36: 
                     37:        LUNA    = VMCap::LUNA1 | VMCap::LUNA88K,
1.1.1.13! root       38:        M68K    = VMCap::X68030 | VMCap::LUNA1 | VMCap::NEWS,
1.1.1.12  root       39:        M88K    = VMCap::LUNA88K,
                     40:        ALL             = 0xffffffff,
                     41: };
1.1.1.13! root       42: static inline VMCap operator|(VMCap a, VMCap b) {
        !            43:        return static_cast<VMCap>(static_cast<uint32>(a) | static_cast<uint32>(b));
        !            44: }
1.1       root       45: 
1.1.1.2   root       46: class MainApp
1.1       root       47: {
1.1.1.2   root       48:  public:
1.1.1.5   root       49:        // Init() の戻り値
                     50:        static const int PASS = -1;             // 実行を継続
                     51: 
                     52:  public:
1.1.1.11  root       53:        MainApp();
                     54:        ~MainApp();
                     55: 
1.1.1.7   root       56:        // 初期化 (ステージ1)
                     57:        int Init1(bool is_cli_, int ac, char *av[]);
1.1       root       58: 
1.1.1.7   root       59:        // 初期化 (ステージ2)
                     60:        bool Init2();
1.1       root       61: 
1.1.1.2   root       62:        std::string SearchFile(const std::string& name) const;
                     63: 
1.1.1.12  root       64:        // VM 種別を返す。
1.1.1.2   root       65:        // (Config が持っているのは文字列)
1.1.1.12  root       66:        VMType GetVMType() const { return vmtype; }
1.1.1.2   root       67: 
1.1.1.13! root       68:        // VM 種別名を返す。
        !            69:        const std::string& GetVMName() const { return vmstr; }
        !            70: 
        !            71:        // たいていは、この機種か?で調べたいことが多いので。
        !            72:        bool IsX68030() const   { return (GetVMType() == VMType::X68030); }
        !            73:        bool IsLUNA1() const    { return (GetVMType() == VMType::LUNA1); }
        !            74:        bool IsLUNA88K() const  { return (GetVMType() == VMType::LUNA88K); }
        !            75:        bool IsNEWS() const             { return (GetVMType() == VMType::NEWS); }
        !            76: 
1.1.1.12  root       77:        // 現在の VM が指定のケーパビリティを持っているか?
                     78:        bool Has(VMCap cap) const;
1.1.1.3   root       79: 
1.1.1.11  root       80:        // VM ディレクトリを返す
                     81:        const std::string& GetVMDir() const { return vmdir; }
                     82: 
1.1.1.13! root       83:        // オブジェクト登録
        !            84:        void RegistObject(Object *obj);
        !            85: 
        !            86:        // オブジェクト削除
        !            87:        void UnregistObject(Object *obj);
        !            88: 
        !            89:        // オブジェクトのリストを返す
        !            90:        const std::vector<Object *>& GetObjects() const { return objects; }
        !            91: 
        !            92:        // 指定のオブジェクトを返す。こっちは、なければ NULL を返す。
        !            93:        Object *FindObject(int id) const;
        !            94: 
        !            95:        // 指定のオブジェクトを返す。こっちは、なければ assert する。
        !            96:        Object *GetObject(int id) const;
        !            97: 
        !            98:        // 指定のオブジェクトを型 T* にキャストして返す。
        !            99:        // オブジェクトがないかキャストできなければ NULL を返す。
        !           100:        template <typename T>
        !           101:        T *FindObject(int id) const {
        !           102:                return dynamic_cast<T *>(FindObject(id));
        !           103:        }
        !           104: 
        !           105:        // 指定のオブジェクトを型 T* にキャストして返す。
        !           106:        // オブジェクトがないかキャストできなければ assert する。
        !           107:        template <typename T>
        !           108:        T *GetObject(int id) const {
        !           109:                auto dev = FindObject<T>(id);
        !           110:                assert(dev);
        !           111:                return dev;
        !           112:        }
        !           113: 
1.1.1.8   root      114:        // ログレベルを設定する。
                    115:        static bool SetLogopt(const std::vector<std::string>&, std::string *errmsg);
                    116: 
                    117:        // ログ名の一覧を表示する
                    118:        static std::vector<std::string> GetLogNames();
                    119: 
1.1.1.11  root      120:        // Logger を返す
                    121:        Logger *GetLogger() const { return logger.get(); }
1.1.1.2   root      122: 
1.1.1.11  root      123:  public:
1.1.1.2   root      124:        // -B: ベンチマークモード
1.1.1.5   root      125:        int benchmark_mode {};
1.1.1.2   root      126: 
1.1.1.13! root      127:        // -b: ブレークポイント "[<cpu>,]<addr>[,<skip>]"
1.1.1.11  root      128:        std::vector<std::string> debug_breakaddr {};
1.1.1.2   root      129: 
                    130:        // -d: 起動時にデバッガで停止
1.1.1.5   root      131:        bool debug_on_start {};
1.1.1.2   root      132: 
1.1.1.9   root      133:        // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。
                    134:        bool human_mode {};
                    135: 
1.1.1.2   root      136:        // -M: モニタ名
                    137:        std::string monitor_opt {};
                    138: 
1.1.1.13! root      139:        // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。
        !           140:        bool msxdos_mode {};
1.1.1.2   root      141: 
1.1.1.9   root      142:        // -X: ホスト実行ファイル名とその引数
                    143:        const char *exec_file {};
                    144:        std::string exec_arg {};
1.1.1.10  root      145:        bool load_and_exec {};
1.1.1.2   root      146: 
                    147:  private:
                    148:        // ヘルプメッセージを表示する
                    149:        void ShowHelp(bool all) const;
                    150: 
                    151:        // バージョンを表示する
                    152:        void ShowVersion() const;
                    153: 
                    154:        // 引数を処理する
1.1.1.13! root      155:        int ParseOpt(int ac, char *av[]);
1.1.1.2   root      156: 
1.1.1.11  root      157:        // opt を logopt に追加する (-L オプション用)
                    158:        void AddLogopt(const char *opt);
                    159: 
1.1.1.2   root      160:        // -L オプションを処理する
                    161:        bool ParseLogopt();
                    162: 
1.1.1.8   root      163:        // ログレベル1つを設定する。
                    164:        static bool SetLogopt1(const std::string&, std::string *errmsg);
                    165: 
1.1.1.13! root      166:        // 初回起動時用に SRAM.DAT を作成する。
        !           167:        int CreateSRAM();
        !           168: 
1.1.1.8   root      169:        // コンパイルされている host netdriver の一覧を表示
                    170:        void ShowHostnet() const;
                    171: 
1.1.1.2   root      172:        // CLI/GUI 区別
                    173:        bool IsCLI() const { return  is_cli; }
                    174:        bool IsGUI() const { return !is_cli; }
1.1.1.5   root      175:        bool is_cli {};
1.1.1.2   root      176: 
1.1.1.11  root      177:        // ログ
                    178:        std::unique_ptr<Logger> logger /*{}*/;
                    179: 
                    180:        // 全オブジェクトへのポインタのリスト (所有はしていない)
                    181:        std::vector<Object*> objects {};
                    182: 
                    183:        // VM
1.1.1.12  root      184:        std::unique_ptr<VM> pVM /*{}*/;
1.1.1.11  root      185: 
                    186:        // 設定項目
                    187:        std::unique_ptr<Config> pConfig /*{}*/;
                    188: 
1.1.1.2   root      189:        // VM 種別
1.1.1.12  root      190:        VMType vmtype {};
1.1.1.13! root      191:        std::string vmstr {};
1.1.1.11  root      192: 
                    193:        // モニタマネージャ
                    194:        std::unique_ptr<MonitorManager> pMonitorManager /*{}*/;
                    195: 
                    196:        // -c: VM ディレクトリ or 設定ファイル
                    197:        std::string vmdir {};
                    198:        std::string vmfile {};
                    199: 
                    200:        // -C: ログをコンソールに出力
                    201:        bool log_to_console {};
                    202: 
                    203:        // -L: ログ指定文字列
                    204:        std::string logopt {};
                    205: 
                    206:        // --show-config: 設定内容を表示 (1なら通常、2ならall)
                    207:        int show_config {};
                    208: 
                    209:        // -V: パラメータ指定
1.1.1.13! root      210:        std::vector<std::pair<std::string, std::string>> config_options {};
        !           211: 
        !           212:        // --create-sram オプション
        !           213:        bool create_sram {};
1.1.1.2   root      214: };
                    215: 
                    216: // グローバルインスタンス
                    217: extern MainApp gMainApp;

unix.superglobalmegacorp.com

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