--- nono/lib/mainapp.h 2026/04/29 17:05:12 1.1.1.12 +++ nono/lib/mainapp.h 2026/04/29 17:05:22 1.1.1.14 @@ -23,6 +23,8 @@ enum class VMType { X68030, LUNA1, LUNA88K, + NEWS, + VIRT68K, }; // VM ケーパビリティ (ビットマスク表現) @@ -31,12 +33,17 @@ enum class VMCap : uint32 { X68030 = (1U << (int)VMType::X68030), LUNA1 = (1U << (int)VMType::LUNA1), LUNA88K = (1U << (int)VMType::LUNA88K), + NEWS = (1U << (int)VMType::NEWS), + VIRT68K = (1U << (int)VMType::VIRT68K), LUNA = VMCap::LUNA1 | VMCap::LUNA88K, - M68K = VMCap::X68030 | VMCap::LUNA1, + M68K = VMCap::X68030 | VMCap::LUNA1 | VMCap::NEWS | VMCap::VIRT68K, M88K = VMCap::LUNA88K, ALL = 0xffffffff, }; +static inline VMCap operator|(VMCap a, VMCap b) { + return static_cast(static_cast(a) | static_cast(b)); +} class MainApp { @@ -48,37 +55,83 @@ class MainApp MainApp(); ~MainApp(); + void Dispose(); + // 初期化 (ステージ1) int Init1(bool is_cli_, int ac, char *av[]); // 初期化 (ステージ2) bool Init2(); - std::string SearchFile(const std::string& name) const; - // VM 種別を返す。 // (Config が持っているのは文字列) VMType GetVMType() const { return vmtype; } + // VM 種別を文字列で返す。"luna" とか。 + const std::string& GetVMTypeStr() const { return vmstr; } + + // たいていは、この機種か?で調べたいことが多いので。 + 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); } + bool IsVIRT68K() const { return (GetVMType() == VMType::VIRT68K); } + // 現在の VM が指定のケーパビリティを持っているか? bool Has(VMCap cap) const; + // VM 機種名を返す。こっちが "LUNA-I" とかで表示用。 + const char *GetVMName() const; + // VM ディレクトリを返す const std::string& GetVMDir() const { return vmdir; } - // ログレベルを設定する。 - static bool SetLogopt(const std::vector&, std::string *errmsg); + // ファイル名から適切なフルパスを検索。 + std::string SearchFile(const std::string& name) const; - // ログ名の一覧を表示する - static std::vector GetLogNames(); + // 指定の path を正規化(展開)して返す。 + // path が絶対パスならそのまま返す。 + // path が '~' から始まっていればホームディレクトリからの相対パス、 + // それ以外なら VM ディレクトリからの相対パスとみなして展開する。 + std::string NormalizePath(const std::string& path) const; + + // オブジェクト登録 + void RegistObject(Object *obj); - // オブジェクトを追加/削除 (Object が呼ぶ) - void AddObject(Object *); - void DeleteObject(Object *); + // オブジェクト削除 + void UnregistObject(Object *obj); // オブジェクトのリストを返す const std::vector& GetObjects() const { return objects; } + // 指定のオブジェクトを返す。こっちは、なければ 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; + } + + // ログレベルを設定する。 + static bool SetLogopt(const std::vector&, std::string *errmsg); + + // ログ名の一覧を表示する + static std::vector GetLogNames(); + // Logger を返す Logger *GetLogger() const { return logger.get(); } @@ -86,36 +139,44 @@ class MainApp // -B: ベンチマークモード int benchmark_mode {}; - // -b: ブレークポイント "[,]" + // -b: ブレークポイント "[,][,]" std::vector debug_breakaddr {}; + // --bi-exg (とりあえず) + bool debug_breakinst_exg {}; + // -d: 起動時にデバッガで停止 bool debug_on_start {}; - // -D: デバッガを stdio で使う - bool opt_D {}; - - // -f: 高速モード (XXX 設定ファイルと含めて見直すこと) - bool fast_mode {}; - - // --fontsize: フォントサイズ指定値 (値は fontsize_t ではない) - int fontsize {}; - // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。 bool human_mode {}; // -M: モニタ名 std::string monitor_opt {}; - // -s,--scale: 画面スケール - double screen_scale {}; + // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。 + bool msxdos_mode {}; // -X: ホスト実行ファイル名とその引数 const char *exec_file {}; std::string exec_arg {}; - bool load_and_exec {}; + + // AVX2 を使うかどうか。ホスト CPU 調査と設定ファイル反映後の値。 + bool enable_avx2 {}; + + // AVX2 をホストがサポートしているかどうか。(こっちは情報表示用) + bool detect_avx2 {}; private: + // 初期化ステージ1 の下請け。 + int Init1a(int, char *[]); + int Init1b(); + + // path を正規化して返す (下請け)。 + // path が相対パスなら basedir を起点とする。 + std::string NormalizePath(const std::string& path, + const std::string& basedir) const; + // ヘルプメッセージを表示する void ShowHelp(bool all) const; @@ -123,7 +184,10 @@ class MainApp void ShowVersion() const; // 引数を処理する - bool ParseOpt(int ac, char *av[]); + int ParseOpt(int ac, char *av[]); + + // CPU の機能をチェックする。 + bool CheckCPU(); // opt を logopt に追加する (-L オプション用) void AddLogopt(const char *opt); @@ -134,6 +198,9 @@ class MainApp // ログレベル1つを設定する。 static bool SetLogopt1(const std::string&, std::string *errmsg); + // 初回起動時用に SRAM.DAT を作成する。 + int CreateSRAM(); + // コンパイルされている host netdriver の一覧を表示 void ShowHostnet() const; @@ -156,6 +223,7 @@ class MainApp // VM 種別 VMType vmtype {}; + std::string vmstr {}; // モニタマネージャ std::unique_ptr pMonitorManager /*{}*/; @@ -174,7 +242,10 @@ class MainApp int show_config {}; // -V: パラメータ指定 - std::vector config_options {}; + std::vector> config_options {}; + + // --create-sram オプション + bool create_sram {}; }; // グローバルインスタンス