--- nono/lib/mainapp.h 2026/04/29 17:04:30 1.1.1.2 +++ nono/lib/mainapp.h 2026/04/29 17:05:15 1.1.1.13 @@ -1,79 +1,148 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// CLI/GUI 共通のメイン部分 // #pragma once -#include "config.h" -#include "debugger.h" -#include "logger.h" -#include "vm_luna.h" -#include "vm_x68k.h" +#include "object.h" + +class Config; +class Logger; +class MonitorManager; +class VM; + +// VM 種別 +enum class VMType { + NONE = 0, + X68030, + LUNA1, + LUNA88K, + NEWS, +}; + +// VM ケーパビリティ (ビットマスク表現) +enum class VMCap : uint32 { + NONE = 0, + X68030 = (1U << (int)VMType::X68030), + LUNA1 = (1U << (int)VMType::LUNA1), + LUNA88K = (1U << (int)VMType::LUNA88K), + NEWS = (1U << (int)VMType::NEWS), + + LUNA = VMCap::LUNA1 | VMCap::LUNA88K, + M68K = VMCap::X68030 | VMCap::LUNA1 | VMCap::NEWS, + M88K = VMCap::LUNA88K, + ALL = 0xffffffff, +}; +static inline VMCap operator|(VMCap a, VMCap b) { + return static_cast(static_cast(a) | static_cast(b)); +} -// 起動時の引数処理などを行う。 class MainApp { public: - // 初期化 - bool Init(bool is_cli_, int ac, char *av[]); + // Init() の戻り値 + static const int PASS = -1; // 実行を継続 + + public: + MainApp(); + ~MainApp(); - // VM 実行開始 - bool Start(); + // 初期化 (ステージ1) + int Init1(bool is_cli_, int ac, char *av[]); + + // 初期化 (ステージ2) + bool Init2(); std::string SearchFile(const std::string& name) const; - // vmtype (VMTYPE_*) を返す。 + // VM 種別を返す。 // (Config が持っているのは文字列) - vmtype_t GetVMType() const { return vmtype; } + VMType GetVMType() const { return vmtype; } - public: - // -A: ホストファイル名 (とりあえず) - const char *host_file = NULL; + // VM 種別名を返す。 + const std::string& GetVMName() const { return vmstr; } - // -b: ブレークポイント - uint32 debug_breakaddr = 0; + // たいていは、この機種か?で調べたいことが多いので。 + bool IsX68030() const { return (GetVMType() == VMType::X68030); } + bool IsLUNA1() const { return (GetVMType() == VMType::LUNA1); } + bool IsLUNA88K() const { return (GetVMType() == VMType::LUNA88K); } + bool IsNEWS() const { return (GetVMType() == VMType::NEWS); } - // -B: ベンチマークモード - int benchmark_mode = 0; + // 現在の VM が指定のケーパビリティを持っているか? + bool Has(VMCap cap) const; - // -c: VM ディレクトリ - std::string vmdir {}; + // VM ディレクトリを返す const std::string& GetVMDir() const { return vmdir; } - // -C: ログをコンソールに出力 - bool log_to_console = false; + // オブジェクト登録 + void RegistObject(Object *obj); - // -d: 起動時にデバッガで停止 - bool debug_on_start = false; + // オブジェクト削除 + void UnregistObject(Object *obj); - // -D: コンソールをデバッガで使う - bool debug_on_console = false; + // オブジェクトのリストを返す + const std::vector& GetObjects() const { return objects; } - // -f: 高速モード (XXX 設定ファイルと含めて見直すこと) - bool fast_mode = false; + // 指定のオブジェクトを返す。こっちは、なければ NULL を返す。 + Object *FindObject(int id) const; + + // 指定のオブジェクトを返す。こっちは、なければ assert する。 + Object *GetObject(int id) const; + + // 指定のオブジェクトを型 T* にキャストして返す。 + // オブジェクトがないかキャストできなければ NULL を返す。 + template + T *FindObject(int id) const { + return dynamic_cast(FindObject(id)); + } + + // 指定のオブジェクトを型 T* にキャストして返す。 + // オブジェクトがないかキャストできなければ assert する。 + template + T *GetObject(int id) const { + auto dev = FindObject(id); + assert(dev); + return dev; + } - // --fontsize: フォントサイズ指定値 (値は fontsize_t ではない) - int fontsize = 0; + // ログレベルを設定する。 + static bool SetLogopt(const std::vector&, std::string *errmsg); - // -L: ログ指定文字列 - char logopt[256] {}; + // ログ名の一覧を表示する + static std::vector GetLogNames(); - // -M: モニタ名 - std::string monitor_opt {}; + // Logger を返す + Logger *GetLogger() const { return logger.get(); } - // -s,--scale: 画面スケール - double screen_scale = 0.0; + public: + // -B: ベンチマークモード + int benchmark_mode {}; - // --show-config: 設定内容を表示 - bool show_config {}; + // -b: ブレークポイント "[,][,]" + std::vector debug_breakaddr {}; - // -V: パラメータ指定 - std::vector config_options; + // -d: 起動時にデバッガで停止 + bool debug_on_start {}; + + // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。 + bool human_mode {}; - // -X: Human68k 実行ファイル名と引数 - const char *human68k_file = NULL; - char human68k_arg[256] {}; + // -M: モニタ名 + std::string monitor_opt {}; + + // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。 + bool msxdos_mode {}; + + // -X: ホスト実行ファイル名とその引数 + const char *exec_file {}; + std::string exec_arg {}; + bool load_and_exec {}; private: // ヘルプメッセージを表示する @@ -83,18 +152,65 @@ class MainApp void ShowVersion() const; // 引数を処理する - bool ParseOpt(int ac, char *av[]); + int ParseOpt(int ac, char *av[]); + + // opt を logopt に追加する (-L オプション用) + void AddLogopt(const char *opt); // -L オプションを処理する bool ParseLogopt(); + // ログレベル1つを設定する。 + static bool SetLogopt1(const std::string&, std::string *errmsg); + + // 初回起動時用に SRAM.DAT を作成する。 + int CreateSRAM(); + + // コンパイルされている host netdriver の一覧を表示 + void ShowHostnet() const; + // CLI/GUI 区別 bool IsCLI() const { return is_cli; } bool IsGUI() const { return !is_cli; } - bool is_cli; + bool is_cli {}; + + // ログ + std::unique_ptr logger /*{}*/; + + // 全オブジェクトへのポインタのリスト (所有はしていない) + std::vector objects {}; + + // VM + std::unique_ptr pVM /*{}*/; + + // 設定項目 + std::unique_ptr pConfig /*{}*/; // VM 種別 - vmtype_t vmtype {}; + VMType vmtype {}; + std::string vmstr {}; + + // モニタマネージャ + std::unique_ptr pMonitorManager /*{}*/; + + // -c: VM ディレクトリ or 設定ファイル + std::string vmdir {}; + std::string vmfile {}; + + // -C: ログをコンソールに出力 + bool log_to_console {}; + + // -L: ログ指定文字列 + std::string logopt {}; + + // --show-config: 設定内容を表示 (1なら通常、2ならall) + int show_config {}; + + // -V: パラメータ指定 + std::vector> config_options {}; + + // --create-sram オプション + bool create_sram {}; }; // グローバルインスタンス