--- nono/vm/uimessage.h 2026/04/29 17:04:59 1.1 +++ nono/vm/uimessage.h 2026/04/29 17:05:51 1.1.1.5 @@ -5,13 +5,14 @@ // // -// VM から UI へのメッセージ機構 +// UI スレッドへのメッセージ機構 // #pragma once -#include "fixedqueue.h" +#include "header.h" #include +#include class UIMessage { @@ -20,8 +21,8 @@ class UIMessage enum ID { NONE = 0, - // VM 電源オフになったのでアプリケーションを終了する場合 - POWEROFF, + // アプリケーションを終了する + APPEXIT, // MPU がホールト状態になった HALT, @@ -32,44 +33,51 @@ class UIMessage // SCSI メディアの挿入に失敗した SCSI_MEDIA_FAILED, + // FDD (各 ID) のメディア状態が変わった (Load/Unload) + FDD_MEDIA_CHANGE, + + // FDD メディアの挿入に失敗した + FDD_MEDIA_FAILED, + // キー入力状態が変わった KEYBOARD, // LCD 状態が変わった LCD, + // 画面を更新した + RENDER, + + // パレットが変更になった + PALETTE, + + // LED 状態が変わった + LED, + + // 新しいホストドライバの起動に失敗した。 + HOSTNET_FAILED, + HOSTCOM_FAILED, + ID_MAX, }; - using Queue = FixedQueue; - public: UIMessage(); + ~UIMessage(); - ID GetID() const { return id; } - int GetArg() const { return arg; } - - // メッセージ処理関数をアタッチ - static void Attach(const std::function& process_); - - // VM 外に向けてメッセージを投函 - // 新しい UIMessage を生成して投函 - static void Post(ID id); - // 新しい UIMessage を生成して投函(argあり) - static void Post(ID id, int arg); + // コールバックを指定して UIMessage サービスを開始。 + void StartUIMessage(const std::function& func_); - protected: - UIMessage(ID id_, int arg_); + // UIMessage サービスを停止。 + void StopUIMessage(); - // 自身を投函 - void Post(); + // UIMessage をポスト (コールバックを実行)。 + void Post(uint id) { + Post(id, 0); + } + void Post(uint id, int arg); private: - ID id; - int arg; - - static Queue queue; - - // メッセージ処理コールバック - static std::function process; + std::function func {}; + std::mutex mtx {}; };