ICommonStateGetter.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 Ryujinx.HLE.HOS.Services.Apm;
  6. using System;
  7. namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
  8. {
  9. class ICommonStateGetter : IpcService
  10. {
  11. private CpuBoostMode _cpuBoostMode = CpuBoostMode.Disabled;
  12. private bool _vrModeEnabled = false;
  13. public ICommonStateGetter() { }
  14. [Command(0)]
  15. // GetEventHandle() -> handle<copy>
  16. public ResultCode GetEventHandle(ServiceCtx context)
  17. {
  18. KEvent Event = context.Device.System.AppletState.MessageEvent;
  19. if (context.Process.HandleTable.GenerateHandle(Event.ReadableEvent, out int handle) != KernelResult.Success)
  20. {
  21. throw new InvalidOperationException("Out of handles!");
  22. }
  23. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  24. return ResultCode.Success;
  25. }
  26. [Command(1)]
  27. // ReceiveMessage() -> nn::am::AppletMessage
  28. public ResultCode ReceiveMessage(ServiceCtx context)
  29. {
  30. if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message))
  31. {
  32. return ResultCode.NoMessages;
  33. }
  34. context.ResponseData.Write((int)message);
  35. return ResultCode.Success;
  36. }
  37. [Command(5)]
  38. // GetOperationMode() -> u8
  39. public ResultCode GetOperationMode(ServiceCtx context)
  40. {
  41. OperationMode mode = context.Device.System.State.DockedMode
  42. ? OperationMode.Docked
  43. : OperationMode.Handheld;
  44. context.ResponseData.Write((byte)mode);
  45. return ResultCode.Success;
  46. }
  47. [Command(6)]
  48. // GetPerformanceMode() -> u32
  49. public ResultCode GetPerformanceMode(ServiceCtx context)
  50. {
  51. PerformanceMode mode = context.Device.System.State.DockedMode
  52. ? PerformanceMode.Docked
  53. : PerformanceMode.Handheld;
  54. context.ResponseData.Write((int)mode);
  55. return ResultCode.Success;
  56. }
  57. [Command(8)]
  58. // GetBootMode() -> u8
  59. public ResultCode GetBootMode(ServiceCtx context)
  60. {
  61. context.ResponseData.Write((byte)0); //Unknown value.
  62. Logger.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.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. _cpuBoostMode = (CpuBoostMode)cpuBoostMode;
  109. // NOTE: There is a condition variable after the assignment, probably waiting something with apm:sys service (SetCpuBoostMode call?).
  110. // Since we will probably never support CPU boost things, it's not needed to implement more.
  111. return ResultCode.Success;
  112. }
  113. }
  114. }