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