|
|
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.14! root 27: VIRT68K,
1.1.1.12 root 28: };
29:
30: // VM ケーパビリティ (ビットマスク表現)
31: enum class VMCap : uint32 {
32: NONE = 0,
33: X68030 = (1U << (int)VMType::X68030),
34: LUNA1 = (1U << (int)VMType::LUNA1),
35: LUNA88K = (1U << (int)VMType::LUNA88K),
1.1.1.13 root 36: NEWS = (1U << (int)VMType::NEWS),
1.1.1.14! root 37: VIRT68K = (1U << (int)VMType::VIRT68K),
1.1.1.12 root 38:
39: LUNA = VMCap::LUNA1 | VMCap::LUNA88K,
1.1.1.14! root 40: M68K = VMCap::X68030 | VMCap::LUNA1 | VMCap::NEWS | VMCap::VIRT68K,
1.1.1.12 root 41: M88K = VMCap::LUNA88K,
42: ALL = 0xffffffff,
43: };
1.1.1.13 root 44: static inline VMCap operator|(VMCap a, VMCap b) {
45: return static_cast<VMCap>(static_cast<uint32>(a) | static_cast<uint32>(b));
46: }
1.1 root 47:
1.1.1.2 root 48: class MainApp
1.1 root 49: {
1.1.1.2 root 50: public:
1.1.1.5 root 51: // Init() の戻り値
52: static const int PASS = -1; // 実行を継続
53:
54: public:
1.1.1.11 root 55: MainApp();
56: ~MainApp();
57:
1.1.1.14! root 58: void Dispose();
! 59:
1.1.1.7 root 60: // 初期化 (ステージ1)
61: int Init1(bool is_cli_, int ac, char *av[]);
1.1 root 62:
1.1.1.7 root 63: // 初期化 (ステージ2)
64: bool Init2();
1.1 root 65:
1.1.1.12 root 66: // VM 種別を返す。
1.1.1.2 root 67: // (Config が持っているのは文字列)
1.1.1.12 root 68: VMType GetVMType() const { return vmtype; }
1.1.1.2 root 69:
1.1.1.14! root 70: // VM 種別を文字列で返す。"luna" とか。
! 71: const std::string& GetVMTypeStr() const { return vmstr; }
1.1.1.13 root 72:
73: // たいていは、この機種か?で調べたいことが多いので。
74: bool IsX68030() const { return (GetVMType() == VMType::X68030); }
75: bool IsLUNA1() const { return (GetVMType() == VMType::LUNA1); }
76: bool IsLUNA88K() const { return (GetVMType() == VMType::LUNA88K); }
77: bool IsNEWS() const { return (GetVMType() == VMType::NEWS); }
1.1.1.14! root 78: bool IsVIRT68K() const { return (GetVMType() == VMType::VIRT68K); }
1.1.1.13 root 79:
1.1.1.12 root 80: // 現在の VM が指定のケーパビリティを持っているか?
81: bool Has(VMCap cap) const;
1.1.1.3 root 82:
1.1.1.14! root 83: // VM 機種名を返す。こっちが "LUNA-I" とかで表示用。
! 84: const char *GetVMName() const;
! 85:
1.1.1.11 root 86: // VM ディレクトリを返す
87: const std::string& GetVMDir() const { return vmdir; }
88:
1.1.1.14! root 89: // ファイル名から適切なフルパスを検索。
! 90: std::string SearchFile(const std::string& name) const;
! 91:
! 92: // 指定の path を正規化(展開)して返す。
! 93: // path が絶対パスならそのまま返す。
! 94: // path が '~' から始まっていればホームディレクトリからの相対パス、
! 95: // それ以外なら VM ディレクトリからの相対パスとみなして展開する。
! 96: std::string NormalizePath(const std::string& path) const;
! 97:
1.1.1.13 root 98: // オブジェクト登録
99: void RegistObject(Object *obj);
100:
101: // オブジェクト削除
102: void UnregistObject(Object *obj);
103:
104: // オブジェクトのリストを返す
105: const std::vector<Object *>& GetObjects() const { return objects; }
106:
107: // 指定のオブジェクトを返す。こっちは、なければ NULL を返す。
108: Object *FindObject(int id) const;
109:
110: // 指定のオブジェクトを返す。こっちは、なければ assert する。
111: Object *GetObject(int id) const;
112:
113: // 指定のオブジェクトを型 T* にキャストして返す。
114: // オブジェクトがないかキャストできなければ NULL を返す。
115: template <typename T>
116: T *FindObject(int id) const {
117: return dynamic_cast<T *>(FindObject(id));
118: }
119:
120: // 指定のオブジェクトを型 T* にキャストして返す。
121: // オブジェクトがないかキャストできなければ assert する。
122: template <typename T>
123: T *GetObject(int id) const {
124: auto dev = FindObject<T>(id);
125: assert(dev);
126: return dev;
127: }
128:
1.1.1.8 root 129: // ログレベルを設定する。
130: static bool SetLogopt(const std::vector<std::string>&, std::string *errmsg);
131:
132: // ログ名の一覧を表示する
133: static std::vector<std::string> GetLogNames();
134:
1.1.1.11 root 135: // Logger を返す
136: Logger *GetLogger() const { return logger.get(); }
1.1.1.2 root 137:
1.1.1.11 root 138: public:
1.1.1.2 root 139: // -B: ベンチマークモード
1.1.1.5 root 140: int benchmark_mode {};
1.1.1.2 root 141:
1.1.1.13 root 142: // -b: ブレークポイント "[<cpu>,]<addr>[,<skip>]"
1.1.1.11 root 143: std::vector<std::string> debug_breakaddr {};
1.1.1.2 root 144:
1.1.1.14! root 145: // --bi-exg (とりあえず)
! 146: bool debug_breakinst_exg {};
! 147:
1.1.1.2 root 148: // -d: 起動時にデバッガで停止
1.1.1.5 root 149: bool debug_on_start {};
1.1.1.2 root 150:
1.1.1.9 root 151: // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。
152: bool human_mode {};
153:
1.1.1.2 root 154: // -M: モニタ名
155: std::string monitor_opt {};
156:
1.1.1.13 root 157: // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。
158: bool msxdos_mode {};
1.1.1.2 root 159:
1.1.1.9 root 160: // -X: ホスト実行ファイル名とその引数
161: const char *exec_file {};
162: std::string exec_arg {};
1.1.1.14! root 163:
! 164: // AVX2 を使うかどうか。ホスト CPU 調査と設定ファイル反映後の値。
! 165: bool enable_avx2 {};
! 166:
! 167: // AVX2 をホストがサポートしているかどうか。(こっちは情報表示用)
! 168: bool detect_avx2 {};
1.1.1.2 root 169:
170: private:
1.1.1.14! root 171: // 初期化ステージ1 の下請け。
! 172: int Init1a(int, char *[]);
! 173: int Init1b();
! 174:
! 175: // path を正規化して返す (下請け)。
! 176: // path が相対パスなら basedir を起点とする。
! 177: std::string NormalizePath(const std::string& path,
! 178: const std::string& basedir) const;
! 179:
1.1.1.2 root 180: // ヘルプメッセージを表示する
181: void ShowHelp(bool all) const;
182:
183: // バージョンを表示する
184: void ShowVersion() const;
185:
186: // 引数を処理する
1.1.1.13 root 187: int ParseOpt(int ac, char *av[]);
1.1.1.2 root 188:
1.1.1.14! root 189: // CPU の機能をチェックする。
! 190: bool CheckCPU();
! 191:
1.1.1.11 root 192: // opt を logopt に追加する (-L オプション用)
193: void AddLogopt(const char *opt);
194:
1.1.1.2 root 195: // -L オプションを処理する
196: bool ParseLogopt();
197:
1.1.1.8 root 198: // ログレベル1つを設定する。
199: static bool SetLogopt1(const std::string&, std::string *errmsg);
200:
1.1.1.13 root 201: // 初回起動時用に SRAM.DAT を作成する。
202: int CreateSRAM();
203:
1.1.1.8 root 204: // コンパイルされている host netdriver の一覧を表示
205: void ShowHostnet() const;
206:
1.1.1.2 root 207: // CLI/GUI 区別
208: bool IsCLI() const { return is_cli; }
209: bool IsGUI() const { return !is_cli; }
1.1.1.5 root 210: bool is_cli {};
1.1.1.2 root 211:
1.1.1.11 root 212: // ログ
213: std::unique_ptr<Logger> logger /*{}*/;
214:
215: // 全オブジェクトへのポインタのリスト (所有はしていない)
216: std::vector<Object*> objects {};
217:
218: // VM
1.1.1.12 root 219: std::unique_ptr<VM> pVM /*{}*/;
1.1.1.11 root 220:
221: // 設定項目
222: std::unique_ptr<Config> pConfig /*{}*/;
223:
1.1.1.2 root 224: // VM 種別
1.1.1.12 root 225: VMType vmtype {};
1.1.1.13 root 226: std::string vmstr {};
1.1.1.11 root 227:
228: // モニタマネージャ
229: std::unique_ptr<MonitorManager> pMonitorManager /*{}*/;
230:
231: // -c: VM ディレクトリ or 設定ファイル
232: std::string vmdir {};
233: std::string vmfile {};
234:
235: // -C: ログをコンソールに出力
236: bool log_to_console {};
237:
238: // -L: ログ指定文字列
239: std::string logopt {};
240:
241: // --show-config: 設定内容を表示 (1なら通常、2ならall)
242: int show_config {};
243:
244: // -V: パラメータ指定
1.1.1.13 root 245: std::vector<std::pair<std::string, std::string>> config_options {};
246:
247: // --create-sram オプション
248: bool create_sram {};
1.1.1.2 root 249: };
250:
251: // グローバルインスタンス
252: extern MainApp gMainApp;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.