From 808380690c684a7598efad791f560e02ce70bc82 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Wed, 16 Dec 2020 01:41:42 +0100 Subject: [PATCH] am/gui: Implement Wake-up message (#1750) * am/gui: Implement Wake-up message. This implement the ability to send a Wake-up (Resume) message to the guest. Sometime games needs to Sleep and Wake-up the switch to unlock some ingame features. * Address gdkchan feedback --- Ryujinx.HLE/HOS/Horizon.cs | 12 +++++++-- .../SystemAppletProxy/ICommonStateGetter.cs | 16 ++++++++++- .../SystemAppletProxy/Types/MessageInfo.cs | 1 + Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs | 27 +++---------------- Ryujinx/Ui/MainWindow.cs | 5 ++++ Ryujinx/Ui/MainWindow.glade | 10 +++++++ 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index 16b3b80731..e6e9cbb0b7 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -278,8 +278,10 @@ namespace Ryujinx.HLE.HOS State.DockedMode = e.NewValue; PerformanceState.PerformanceMode = State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default; - AppletState.EnqueueMessage(MessageInfo.OperationModeChanged); - AppletState.EnqueueMessage(MessageInfo.PerformanceModeChanged); + AppletState.Messages.Enqueue(MessageInfo.OperationModeChanged); + AppletState.Messages.Enqueue(MessageInfo.PerformanceModeChanged); + AppletState.MessageEvent.ReadableEvent.Signal(); + SignalDisplayResolutionChange(); // Reconfigure controllers @@ -287,6 +289,12 @@ namespace Ryujinx.HLE.HOS } } + public void SimulateWakeUpMessage() + { + AppletState.Messages.Enqueue(MessageInfo.Resume); + AppletState.MessageEvent.ReadableEvent.Signal(); + } + public void SignalDisplayResolutionChange() { DisplayResolutionChangeEvent.ReadableEvent.Signal(); diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs index e3b73c2941..0d003abaa7 100644 --- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs +++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs @@ -46,11 +46,25 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // ReceiveMessage() -> nn::am::AppletMessage public ResultCode ReceiveMessage(ServiceCtx context) { - if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message)) + if (!context.Device.System.AppletState.Messages.TryDequeue(out MessageInfo message)) { return ResultCode.NoMessages; } + KEvent messageEvent = context.Device.System.AppletState.MessageEvent; + + // NOTE: Service checks if current states are different than the stored ones. + // Since we don't support any states for now, it's fine to check if there is still messages available. + + if (context.Device.System.AppletState.Messages.IsEmpty) + { + messageEvent.ReadableEvent.Clear(); + } + else + { + messageEvent.ReadableEvent.Signal(); + } + context.ResponseData.Write((int)message); return ResultCode.Success; diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs index ff699315a1..0291b9bc1c 100644 --- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs +++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/MessageInfo.cs @@ -3,6 +3,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys enum MessageInfo { FocusStateChanged = 0xf, + Resume = 0x10, OperationModeChanged = 0x1e, PerformanceModeChanged = 0x1f } diff --git a/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs b/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs index b9229b3303..8fd2f08d88 100644 --- a/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs +++ b/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.SystemState { class AppletStateMgr { - private ConcurrentQueue _messages; + public ConcurrentQueue Messages { get; } public FocusState FocusState { get; private set; } @@ -16,8 +16,7 @@ namespace Ryujinx.HLE.HOS.SystemState public AppletStateMgr(Horizon system) { - _messages = new ConcurrentQueue(); - + Messages = new ConcurrentQueue(); MessageEvent = new KEvent(system.KernelContext); AppletResourceUserIds = new IdDictionary(); @@ -25,28 +24,10 @@ namespace Ryujinx.HLE.HOS.SystemState public void SetFocus(bool isFocused) { - FocusState = isFocused - ? FocusState.InFocus - : FocusState.OutOfFocus; - - EnqueueMessage(MessageInfo.FocusStateChanged); - } - - public void EnqueueMessage(MessageInfo message) - { - _messages.Enqueue(message); + FocusState = isFocused ? FocusState.InFocus : FocusState.OutOfFocus; + Messages.Enqueue(MessageInfo.FocusStateChanged); MessageEvent.ReadableEvent.Signal(); } - - public bool TryDequeueMessage(out MessageInfo message) - { - if (_messages.Count < 2) - { - MessageEvent.ReadableEvent.Clear(); - } - - return _messages.TryDequeue(out message); - } } } \ No newline at end of file diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index b54ba6249c..245d4b09c5 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -1205,6 +1205,11 @@ namespace Ryujinx.Ui settingsWin.Show(); } + private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args) + { + _emulationContext.System.SimulateWakeUpMessage(); + } + private void Update_Pressed(object sender, EventArgs args) { if (Updater.CanUpdate(true)) diff --git a/Ryujinx/Ui/MainWindow.glade b/Ryujinx/Ui/MainWindow.glade index 3b93486105..24c6d1e59c 100644 --- a/Ryujinx/Ui/MainWindow.glade +++ b/Ryujinx/Ui/MainWindow.glade @@ -137,6 +137,16 @@ + + + True + False + Simulate a Wake-up Message + Simulate Wake-up Message + True + + + True