--- nono/lib/mainapp.h 2026/04/29 17:04:28 1.1 +++ nono/lib/mainapp.h 2026/04/29 17:04:34 1.1.1.3 @@ -1,93 +1,105 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once -#include "configfile.h" +#include "config.h" #include "debugger.h" #include "logger.h" -#include "scheduler.h" -#include "vm.h" +#include "vm_luna.h" +#include "vm_x68k.h" -extern bool console_log; -extern bool fast_mode; -extern char logopt[256]; -extern const char *human68k_file; -extern char human68k_arg[256]; - -extern std::string vmdir; - -extern bool parse_logopt(const char *arg, u_int vmtype); - -// 起動時の処理 は CLI と GUI でよく似ているので共通化する。 -// ただし地味に異なるところがあるのでテンプレートでコンパイル時処理。 -// log_to_stdout はログをコンソールに(も)出力するなら true。 -template bool -main_init(bool log_to_stdout) +// 起動時の引数処理などを行う。 +class MainApp { - // ログ機構は引数処理後なるはや - logger_init(); - gLogger->UseStdout(log_to_stdout); - - // 引数で指定されたディレクトリの設定ファイルを読む - gConfig = new Config(vmdir); - if (!gConfig->Load()) { - return false; - } - - // VM 種別を決定 - u_int vm_type; - if (is_cli && human68k_file) { - vm_type = VM::TYPE_RXZ; - } else { - vm_type = gConfig->ReadInt("vm_type"); - } - - // VM 作成 - if (vm_type == VM::TYPE_X68030) { - gVM = new VM_X68030(); - - } else if (vm_type == VM::TYPE_LUNA) { - gVM = new VM_LUNA(); - - } else if (vm_type == VM::TYPE_RXZ && is_cli) { - gVM = new VM_RXZ(human68k_file, human68k_arg); - - } else { - warnx("%s: invalid vm_type %d", - gConfig->GetFilename().c_str(), vm_type); - return false; - } - - // 動的なコンストラクション - if (!gVM->Create()) { - return false; - } - - // ログレベルを設定。コンストラクト後すぐに行う。 - // -L help もここで処理。 - if (!parse_logopt(logopt, vm_type)) { - return false; - } - - // VM 初期化 - // (デバッガは VM オブジェクトリストに入っていない) - if (!gVM->Init()) { - return false; - } - debugger_init(); - - // 起動時設定の適用 - if (!gVM->Apply()) { - return false; - } - - // ここで引数を VM に適用? - // XXX これは設定ファイルのオーバーライド方向にするべき - gScheduler->SetFullSpeed(fast_mode); + public: + // 初期化 + bool Init(bool is_cli_, int ac, char *av[]); - return true; -} + // VM 実行開始 + bool Start(); + std::string SearchFile(const std::string& name) const; + + // vmtype (VMTYPE_*) を返す。 + // (Config が持っているのは文字列) + vmtype_t GetVMType() const { return vmtype; } + + // 現在の VM が指定の feature を持っているか? + bool HasVMFeature(vmf_t flag) const; + + public: + // -A: ホストファイル名 (とりあえず) + const char *host_file = NULL; + + // -b: ブレークポイント + std::vector debug_breakaddr {}; + + // -B: ベンチマークモード + int benchmark_mode = 0; + + // -c: VM ディレクトリ + std::string vmdir {}; + const std::string& GetVMDir() const { return vmdir; } + + // -C: ログをコンソールに出力 + bool log_to_console = false; + + // -d: 起動時にデバッガで停止 + bool debug_on_start = false; + + // -D: コンソールをデバッガで使う + bool debug_on_console = false; + + // -f: 高速モード (XXX 設定ファイルと含めて見直すこと) + bool fast_mode = false; + + // --fontsize: フォントサイズ指定値 (値は fontsize_t ではない) + int fontsize = 0; + + // -L: ログ指定文字列 + char logopt[256] {}; + + // -M: モニタ名 + std::string monitor_opt {}; + + // -s,--scale: 画面スケール + double screen_scale = 0.0; + + // --show-config: 設定内容を表示 (1なら通常、2ならall) + int show_config {}; + + // -V: パラメータ指定 + std::vector config_options; + + // -X: Human68k 実行ファイル名と引数 + const char *human68k_file = NULL; + char human68k_arg[256] {}; + + private: + // ヘルプメッセージを表示する + void ShowHelp(bool all) const; + + // バージョンを表示する + void ShowVersion() const; + + // 引数を処理する + bool ParseOpt(int ac, char *av[]); + + // -L オプションを処理する + bool ParseLogopt(); + + // CLI/GUI 区別 + bool IsCLI() const { return is_cli; } + bool IsGUI() const { return !is_cli; } + bool is_cli; + + // VM 種別 + vmtype_t vmtype {}; +}; + +// グローバルインスタンス +extern MainApp gMainApp;