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