|
|
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.9 root 7: //
8: // CLI アプリケーションのエントリポイント
9: //
10:
1.1 root 11: #include "header.h"
1.1.1.8 root 12: #include "cuimessage.h"
1.1.1.9 root 13: #include "kevent.h"
1.1 root 14: #include "mainapp.h"
1.1.1.3 root 15: #include "mpu680x0.h"
1.1 root 16: #include "pluto.h"
1.1.1.10! root 17: #include "power.h"
1.1 root 18: #include "vm.h"
19:
20: // wxApp と相似にするためのクラス
21: class CLIApp
22: {
23: public:
1.1.1.4 root 24: int OnInit();
1.1 root 25: bool Parse();
1.1.1.7 root 26: int OnCreate();
1.1.1.8 root 27: void OnHalt();
1.1.1.9 root 28: void OnAppExit();
29:
30: int ac {};
31: char **av {};
1.1 root 32:
1.1.1.9 root 33: autofd kq {};
34: bool exit_request {};
1.1 root 35: };
36:
37: int
38: main(int ac, char *av[])
39: {
1.1.1.2 root 40: std::unique_ptr<CLIApp> app(new CLIApp());
1.1 root 41:
42: // wxApp とよく似せるため
43: app->ac = ac;
44: app->av = av;
1.1.1.4 root 45: return app->OnInit();
1.1 root 46: }
47:
48: // ここがエントリポイント(のつもり)
1.1.1.4 root 49: int
1.1 root 50: CLIApp::OnInit()
51: {
1.1.1.4 root 52: int rv;
53:
1.1.1.6 root 54: // CLI 側では関係ないが wx 側で必要なので初期化は2ステージに分かれている
55: rv = gMainApp.Init1(true, ac, av);
1.1.1.4 root 56: if (rv != MainApp::PASS) {
57: return rv;
1.1 root 58: }
1.1.1.9 root 59: // UIMessage の初期化はなんとなくスレッド開始前のほうがよかろう
60: kq = CUIMessage::Init();
61: if (kq < 0) {
62: return EXIT_FAILURE;
63: }
1.1.1.6 root 64: if (!gMainApp.Init2()) {
1.1.1.4 root 65: return EXIT_FAILURE;
1.1 root 66: }
67:
68: // メインウィンドウに相当するところ
69: OnCreate();
70:
1.1.1.4 root 71: return EXIT_SUCCESS;
1.1 root 72: }
73:
74: // メインウィンドウ作成後のイベントに相当するところ
1.1.1.7 root 75: int
1.1 root 76: CLIApp::OnCreate()
77: {
1.1.1.9 root 78: CUIMessage::Connect(UIMessage::APPEXIT,
79: [&](const UIMessage&) { OnAppExit(); });
1.1.1.8 root 80: if (gMPU680x0) {
81: CUIMessage::Connect(UIMessage::HALT,
82: [&](const UIMessage&) { OnHalt(); });
83: }
84: // UIMessage の処理を開始する。
85: UIMessage::Attach(&CUIMessage::Process);
86:
1.1.1.6 root 87: // 電源投入
1.1.1.10! root 88: gPower->PowerButton();
1.1 root 89:
1.1.1.9 root 90: // メッセージを待つ
91: while (exit_request == false) {
92: struct kevent kev;
93:
94: if (kevent_poll(kq, &kev, 1, NULL) < 0) {
95: if (errno == EINTR) {
96: continue;
97: }
98: warn("CLIApp::OnCreate: kevent_poll");
99: // XXX どうする?
100: continue;
101: }
102:
103: // パイプから1メッセージ分読み出す
104: UIMessage m;
105: if (read((int)kev.ident, &m, sizeof(m)) < 0) {
106: warn("CLIApp::OnCreate: read");
107: // XXX どうする?
108: continue;
109: }
110:
111: // ディスパッチ
112: CUIMessage::Dispatch(m);
113: }
1.1.1.7 root 114:
1.1.1.9 root 115: // VM を解放
116: gVM->Dispose();
1.1.1.7 root 117:
118: return 0;
1.1 root 119: }
1.1.1.3 root 120:
121: // m680x0 ダブルバスフォールト時に呼ばれるコールバック。
122: void
1.1.1.8 root 123: CLIApp::OnHalt()
1.1.1.3 root 124: {
125: // どうする?
126: warnx("Double bus fault has occurred in VM");
127: }
1.1.1.9 root 128:
129: // アプリケーションの終了要求で呼ばれるコールバック。
130: void
131: CLIApp::OnAppExit()
132: {
133: exit_request = true;
134: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.