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

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2018 [email protected]
        !             4: //
        !             5: 
        !             6: #pragma once
        !             7: 
        !             8: #include "configfile.h"
        !             9: #include "debugger.h"
        !            10: #include "logger.h"
        !            11: #include "scheduler.h"
        !            12: #include "vm.h"
        !            13: 
        !            14: extern bool console_log;
        !            15: extern bool fast_mode;
        !            16: extern char logopt[256];
        !            17: extern const char *human68k_file;
        !            18: extern char human68k_arg[256];
        !            19: 
        !            20: extern std::string vmdir;
        !            21: 
        !            22: extern bool parse_logopt(const char *arg, u_int vmtype);
        !            23: 
        !            24: // 起動時の処理 は CLI と GUI でよく似ているので共通化する。
        !            25: // ただし地味に異なるところがあるのでテンプレートでコンパイル時処理。
        !            26: // log_to_stdout はログをコンソールに(も)出力するなら true。
        !            27: template<bool is_cli> bool
        !            28: main_init(bool log_to_stdout)
        !            29: {
        !            30:        // ログ機構は引数処理後なるはや
        !            31:        logger_init();
        !            32:        gLogger->UseStdout(log_to_stdout);
        !            33: 
        !            34:        // 引数で指定されたディレクトリの設定ファイルを読む
        !            35:        gConfig = new Config(vmdir);
        !            36:        if (!gConfig->Load()) {
        !            37:                return false;
        !            38:        }
        !            39: 
        !            40:        // VM 種別を決定
        !            41:        u_int vm_type;
        !            42:        if (is_cli && human68k_file) {
        !            43:                vm_type = VM::TYPE_RXZ;
        !            44:        } else {
        !            45:                vm_type = gConfig->ReadInt("vm_type");
        !            46:        }
        !            47: 
        !            48:        // VM 作成
        !            49:        if (vm_type == VM::TYPE_X68030) {
        !            50:                gVM = new VM_X68030();
        !            51: 
        !            52:        } else if (vm_type == VM::TYPE_LUNA) {
        !            53:                gVM = new VM_LUNA();
        !            54: 
        !            55:        } else if (vm_type == VM::TYPE_RXZ && is_cli) {
        !            56:                gVM = new VM_RXZ(human68k_file, human68k_arg);
        !            57: 
        !            58:        } else {
        !            59:                warnx("%s: invalid vm_type %d",
        !            60:                        gConfig->GetFilename().c_str(), vm_type);
        !            61:                return false;
        !            62:        }
        !            63: 
        !            64:        // 動的なコンストラクション
        !            65:        if (!gVM->Create()) {
        !            66:                return false;
        !            67:        }
        !            68: 
        !            69:        // ログレベルを設定。コンストラクト後すぐに行う。
        !            70:        // -L help もここで処理。
        !            71:        if (!parse_logopt(logopt, vm_type)) {
        !            72:                return false;
        !            73:        }
        !            74: 
        !            75:        // VM 初期化
        !            76:        // (デバッガは VM オブジェクトリストに入っていない)
        !            77:        if (!gVM->Init()) {
        !            78:                return false;
        !            79:        }
        !            80:        debugger_init();
        !            81: 
        !            82:        // 起動時設定の適用
        !            83:        if (!gVM->Apply()) {
        !            84:                return false;
        !            85:        }
        !            86: 
        !            87:        // ここで引数を VM に適用?
        !            88:        // XXX これは設定ファイルのオーバーライド方向にするべき
        !            89:        gScheduler->SetFullSpeed(fast_mode);
        !            90: 
        !            91:        return true;
        !            92: }
        !            93: 

unix.superglobalmegacorp.com

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