--- nono/cli/cli_app.cpp 2026/04/29 17:05:13 1.1.1.10 +++ nono/cli/cli_app.cpp 2026/04/29 17:05:49 1.1.1.14 @@ -8,14 +8,12 @@ // CLI アプリケーションのエントリポイント // -#include "header.h" +#include "nono.h" #include "cuimessage.h" #include "kevent.h" #include "mainapp.h" -#include "mpu680x0.h" -#include "pluto.h" +#include "monitor.h" #include "power.h" -#include "vm.h" // wxApp と相似にするためのクラス class CLIApp @@ -25,7 +23,6 @@ class CLIApp bool Parse(); int OnCreate(); void OnHalt(); - void OnAppExit(); int ac {}; char **av {}; @@ -52,7 +49,7 @@ CLIApp::OnInit() int rv; // CLI 側では関係ないが wx 側で必要なので初期化は2ステージに分かれている - rv = gMainApp.Init1(true, ac, av); + rv = gMainApp.Init1(ac, av, NULL); if (rv != MainApp::PASS) { return rv; } @@ -61,6 +58,11 @@ CLIApp::OnInit() if (kq < 0) { return EXIT_FAILURE; } + + // モニタ登録締切。CLI ではあまり関係ないけど揃えておく。 + gMonitorManager->Fix(); + + // スレッド作成を伴う初期化。 if (!gMainApp.Init2()) { return EXIT_FAILURE; } @@ -68,6 +70,9 @@ CLIApp::OnInit() // メインウィンドウに相当するところ OnCreate(); + // 戻ってきたので、VM を解放。 + gMainApp.Dispose(); + return EXIT_SUCCESS; } @@ -75,17 +80,11 @@ CLIApp::OnInit() int CLIApp::OnCreate() { - CUIMessage::Connect(UIMessage::APPEXIT, - [&](const UIMessage&) { OnAppExit(); }); - if (gMPU680x0) { - CUIMessage::Connect(UIMessage::HALT, - [&](const UIMessage&) { OnHalt(); }); - } - // UIMessage の処理を開始する。 - UIMessage::Attach(&CUIMessage::Process); + gMainApp.GetUIMessage()->StartUIMessage(&CUIMessage::Process); // 電源投入 - gPower->PowerButton(); + auto power = GetPowerDevice(); + power->PushPowerButton(); // メッセージを待つ while (exit_request == false) { @@ -101,19 +100,28 @@ CLIApp::OnCreate() } // パイプから1メッセージ分読み出す - UIMessage m; + union64 m; if (read((int)kev.ident, &m, sizeof(m)) < 0) { warn("CLIApp::OnCreate: read"); // XXX どうする? continue; } + uint id = m.h; - // ディスパッチ - CUIMessage::Dispatch(m); + // 少ないのでこの場でディスパッチする。 + switch (id) { + case UIMessage::APPEXIT: + exit_request = true; + break; + case UIMessage::HALT: + OnHalt(); + break; + default: + break; + } } - // VM を解放 - gVM->Dispose(); + gMainApp.GetUIMessage()->StopUIMessage(); return 0; } @@ -125,10 +133,3 @@ CLIApp::OnHalt() // どうする? warnx("Double bus fault has occurred in VM"); } - -// アプリケーションの終了要求で呼ばれるコールバック。 -void -CLIApp::OnAppExit() -{ - exit_request = true; -}