ICommonStateGetter.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
  7. {
  8. class ICommonStateGetter : IpcService
  9. {
  10. private Apm.ManagerServer apmManagerServer;
  11. private Apm.SystemManagerServer apmSystemManagerServer;
  12. private bool _vrModeEnabled = false;
  13. public ICommonStateGetter(ServiceCtx context)
  14. {
  15. apmManagerServer = new Apm.ManagerServer(context);
  16. apmSystemManagerServer = new Apm.SystemManagerServer(context);
  17. }
  18. [Command(0)]
  19. // GetEventHandle() -> handle<copy>
  20. public ResultCode GetEventHandle(ServiceCtx context)
  21. {
  22. KEvent Event = context.Device.System.AppletState.MessageEvent;
  23. if (context.Process.HandleTable.GenerateHandle(Event.ReadableEvent, out int handle) != KernelResult.Success)
  24. {
  25. throw new InvalidOperationException("Out of handles!");
  26. }
  27. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  28. return ResultCode.Success;
  29. }
  30. [Command(1)]
  31. // ReceiveMessage() -> nn::am::AppletMessage
  32. public ResultCode ReceiveMessage(ServiceCtx context)
  33. {
  34. if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message))
  35. {
  36. return ResultCode.NoMessages;
  37. }
  38. context.ResponseData.Write((int)message);
  39. return ResultCode.Success;
  40. }
  41. [Command(5)]
  42. // GetOperationMode() -> u8
  43. public ResultCode GetOperationMode(ServiceCtx context)
  44. {
  45. OperationMode mode = context.Device.System.State.DockedMode
  46. ? OperationMode.Docked
  47. : OperationMode.Handheld;
  48. context.ResponseData.Write((byte)mode);
  49. return ResultCode.Success;
  50. }
  51. [Command(6)]
  52. // GetPerformanceMode() -> nn::apm::PerformanceMode
  53. public ResultCode GetPerformanceMode(ServiceCtx context)
  54. {
  55. return (ResultCode)apmManagerServer.GetPerformanceMode(context);
  56. }
  57. [Command(8)]
  58. // GetBootMode() -> u8
  59. public ResultCode GetBootMode(ServiceCtx context)
  60. {
  61. context.ResponseData.Write((byte)0); //Unknown value.
  62. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  63. return ResultCode.Success;
  64. }
  65. [Command(9)]
  66. // GetCurrentFocusState() -> u8
  67. public ResultCode GetCurrentFocusState(ServiceCtx context)
  68. {
  69. context.ResponseData.Write((byte)context.Device.System.AppletState.FocusState);
  70. return ResultCode.Success;
  71. }
  72. [Command(50)] // 3.0.0+
  73. // IsVrModeEnabled() -> b8
  74. public ResultCode IsVrModeEnabled(ServiceCtx context)
  75. {
  76. context.ResponseData.Write(_vrModeEnabled);
  77. return ResultCode.Success;
  78. }
  79. [Command(60)] // 3.0.0+
  80. // GetDefaultDisplayResolution() -> (u32, u32)
  81. public ResultCode GetDefaultDisplayResolution(ServiceCtx context)
  82. {
  83. context.ResponseData.Write(1280);
  84. context.ResponseData.Write(720);
  85. return ResultCode.Success;
  86. }
  87. [Command(61)] // 3.0.0+
  88. // GetDefaultDisplayResolutionChangeEvent() -> handle<copy>
  89. public ResultCode GetDefaultDisplayResolutionChangeEvent(ServiceCtx context)
  90. {
  91. if (context.Process.HandleTable.GenerateHandle(context.Device.System.DisplayResolutionChangeEvent.ReadableEvent, out int handle) != KernelResult.Success)
  92. {
  93. throw new InvalidOperationException("Out of handles!");
  94. }
  95. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  96. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  97. return ResultCode.Success;
  98. }
  99. [Command(66)] // 6.0.0+
  100. // SetCpuBoostMode(u32 cpu_boost_mode)
  101. public ResultCode SetCpuBoostMode(ServiceCtx context)
  102. {
  103. uint cpuBoostMode = context.RequestData.ReadUInt32();
  104. if (cpuBoostMode > 1)
  105. {
  106. return ResultCode.InvalidParameters;
  107. }
  108. apmSystemManagerServer.SetCpuBoostMode((Apm.CpuBoostMode)cpuBoostMode);
  109. // TODO: It signals an internal event of ICommonStateGetter. We have to determine where this event is used.
  110. return ResultCode.Success;
  111. }
  112. [Command(91)] // 7.0.0+
  113. // GetCurrentPerformanceConfiguration() -> nn::apm::PerformanceConfiguration
  114. public ResultCode GetCurrentPerformanceConfiguration(ServiceCtx context)
  115. {
  116. return (ResultCode)apmSystemManagerServer.GetCurrentPerformanceConfiguration(context);
  117. }
  118. }
  119. }