--- nono/vm/power.h 2026/04/29 17:05:17 1.1.1.3 +++ nono/vm/power.h 2026/04/29 17:05:24 1.1.1.4 @@ -16,6 +16,18 @@ class Syncer; +// 定数 +enum class PowerButtonState +{ + // 電源ボタンの状態がオフ/オン (bool にキャストできる) + Off = 0, + On = 1, + + // モーメンタリスイッチなどで状態を持たない場合 + NoState = -1, +}; + +// 電源周り (共通部分) class PowerDevice : public Device { using inherited = Device; @@ -25,43 +37,46 @@ class PowerDevice : public Device bool Init() override; - // 電源ボタンを押す - void PowerButton(); + // 電源ボタンを押す (どのスレッドから呼んでもよい) + void PushPowerButton(); - // リセットを指示 - // (どのスレッドから呼んでもよい) + // リセットを指示 (どのスレッドから呼んでもよい) void MakeResetHard(); - // リスタートを指示 - // (どのスレッドから呼んでもよい) + // リスタートを指示 (どのスレッドから呼んでもよい) void MakeRestart(); + // 機種固有の電源オンオフ処理の信号を受け取る。 + virtual void SetSystemPowerOn(bool poweron); + + // 電源ボタンの状態 (オフ/オン/状態を持たない) を返す。(GUI 用) + PowerButtonState GetPowerButtonState() const; + // 電源が実際にオンなら true を返す。 bool IsPower() const { return ispower; } // 電源 LED 点灯なら true を返す。 bool GetPowerLED() const { return led; } - // X68030 では電源ボタンが押されていれば true を返す。 - // LUNA では意味を持たないので呼ばないこと。 - bool IsPowerPressed() const { return power_button; } + protected: + // メッセージコールバック + void PowerButtonMessage(MessageID, uint32); + void ResetMessage(MessageID, uint32); + void PowerOffMessage(MessageID, uint32); - void SetAlarmOut(bool alarm_out_); - void SetSystemPowerOn(bool poweron); - private: + // 電源ボタン操作 + virtual void DoPowerButton(); + + // 電源オン、リセット、電源オフ操作 void DoPowerOn(); void DoResetHard(); void DoPowerOff(MessageID); - void DoPowerButton(); - - // メッセージコールバック - void ResetCallback(MessageID, uint32); - void PowerOffCallback(MessageID, uint32); - void PowerButtonCallback(MessageID, uint32); - void PowerCallback(Event&); + // 電源ボタンがオルタネートスイッチなら true。 + bool alternate_switch {}; - void Change(); + // 電源ボタンのオン/オフ状態。alternate_switch が false なら無効。 + bool power_button {}; // 電源オンなら true bool ispower {}; @@ -69,21 +84,52 @@ class PowerDevice : public Device // 電源 LED bool led {}; - // 電源ボタン状態 - bool power_button {}; + Syncer *syncer {}; +}; - // ALARM_OUT 信号状態 - bool alarm_out {}; +class LunaPowerDevice : public PowerDevice +{ + using inherited = PowerDevice; + public: + LunaPowerDevice(); + ~LunaPowerDevice() override; - // システム内の電源オン信号に相当 - bool system_poweron {}; + // PIO1 の PC4 の状態を受け取る + void SetSystemPowerOn(bool poweron) override; - Syncer *syncer {}; + private: + void PowerCallback(Event&); // 電源オフイベント Event event { this }; }; +class X68030PowerDevice : public PowerDevice +{ + using inherited = PowerDevice; + public: + X68030PowerDevice(); + ~X68030PowerDevice() override; + + // システムポートからの電源オフコマンドを受け取る + void SetSystemPowerOn(bool poweron) override; + + // RP5C15 の ALARM_OUT を受け取る + void SetAlarmOut(bool alarm_out_); + + private: + // 電源ボタン操作 + void DoPowerButton() override; + + void Change(); + + // システム内の電源オン信号に相当 + bool system_poweron {}; + + // ALARM_OUT 信号状態 + bool alarm_out {}; +}; + static inline PowerDevice *GetPowerDevice() { return Object::GetObject(OBJ_POWER); }