--- nono/vm/power.h 2026/04/29 17:05:10 1.1 +++ nono/vm/power.h 2026/04/29 17:05:28 1.1.1.5 @@ -11,8 +11,23 @@ #pragma once #include "device.h" +#include "event.h" #include "message.h" +class Syncer; + +// 定数 +enum class PowerButtonState +{ + // 電源ボタンの状態がオフ/オン (bool にキャストできる) + Off = 0, + On = 1, + + // モーメンタリスイッチなどで状態を持たない場合 + NoState = -1, +}; + +// 電源周り (共通部分) class PowerDevice : public Device { using inherited = Device; @@ -22,37 +37,101 @@ class PowerDevice : public Device bool Init() override; - // 電源オンを指示 - // (当然電源オフ時に呼ぶので VM スレッド外から呼ばれることになる) - void MakePowerOn(); + // 電源ボタンを押す (どのスレッドから呼んでもよい) + void PushPowerButton(); - // リセットを指示 - // (どのスレッドから呼んでもよい) + // リセットを指示 (どのスレッドから呼んでもよい) void MakeResetHard(); - // 電源オフして終了を指示 - // (どのスレッドから呼んでもよい) - void MakePowerOffExit(); - - // リスタートを指示 - // (どのスレッドから呼んでもよい) + // リスタートを指示 (どのスレッドから呼んでもよい) void MakeRestart(); - // 電源オンなら true を返す。 + // 機種固有の電源オンオフ処理の信号を受け取る。 + virtual void SetSystemPowerOn(bool poweron); + + // 電源ボタンの状態 (オフ/オン/状態を持たない) を返す。(GUI 用) + PowerButtonState GetPowerButtonState() const; + + // 電源が実際にオンなら true を返す。 bool IsPower() const { return ispower; } - private: + // 電源 LED 点灯なら true を返す。 + bool GetPowerLED() const { return led; } + + protected: + // メッセージコールバック + void PowerButtonMessage(MessageID, uint32); + void ResetMessage(MessageID, uint32); + void PowerOffMessage(MessageID, uint32); + + // 電源ボタン操作 + virtual void DoPowerButton(); + + // 電源オン、リセット、電源オフ操作 void DoPowerOn(); void DoResetHard(); void DoPowerOff(MessageID); - // メッセージコールバック - void PowerOnCallback(MessageID, uint32); - void ResetCallback(MessageID, uint32); - void PowerOffCallback(MessageID, uint32); + // 電源ボタンがオルタネートスイッチなら true。 + bool alternate_switch {}; + + // 電源ボタンのオン/オフ状態。alternate_switch が false なら無効。 + bool power_button {}; // 電源オンなら true bool ispower {}; + + // 電源 LED + bool led {}; + + Syncer *syncer {}; +}; + +class LunaPowerDevice : public PowerDevice +{ + using inherited = PowerDevice; + public: + LunaPowerDevice(); + ~LunaPowerDevice() override; + + bool Init() override; + + // PIO1 の PC4 の状態を受け取る + void SetSystemPowerOn(bool poweron) override; + + 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 {}; }; -extern PowerDevice *gPower; +static inline PowerDevice *GetPowerDevice() { + return Object::GetObject(OBJ_POWER); +}