ICommonStateGetter.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. public ICommonStateGetter() { }
  13. [Command(0)]
  14. // GetEventHandle() -> handle<copy>
  15. public ResultCode GetEventHandle(ServiceCtx context)
  16. {
  17. KEvent Event = context.Device.System.AppletState.MessageEvent;
  18. if (context.Process.HandleTable.GenerateHandle(Event.ReadableEvent, out int handle) != KernelResult.Success)
  19. {
  20. throw new InvalidOperationException("Out of handles!");
  21. }
  22. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  23. return ResultCode.Success;
  24. }
  25. [Command(1)]
  26. // ReceiveMessage() -> nn::am::AppletMessage
  27. public ResultCode ReceiveMessage(ServiceCtx context)
  28. {
  29. if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message))
  30. {
  31. return ResultCode.NoMessages;
  32. }
  33. context.ResponseData.Write((int)message);
  34. return ResultCode.Success;
  35. }
  36. [Command(5)]
  37. // GetOperationMode() -> u8
  38. public ResultCode GetOperationMode(ServiceCtx context)
  39. {
  40. OperationMode mode = context.Device.System.State.DockedMode
  41. ? OperationMode.Docked
  42. : OperationMode.Handheld;
  43. context.ResponseData.Write((byte)mode);
  44. return ResultCode.Success;
  45. }
  46. [Command(6)]
  47. // GetPerformanceMode() -> u32
  48. public ResultCode GetPerformanceMode(ServiceCtx context)
  49. {
  50. PerformanceMode mode = context.Device.System.State.DockedMode
  51. ? PerformanceMode.Docked
  52. : PerformanceMode.Handheld;
  53. context.ResponseData.Write((int)mode);
  54. return ResultCode.Success;
  55. }
  56. [Command(8)]
  57. // GetBootMode() -> u8
  58. public ResultCode GetBootMode(ServiceCtx context)
  59. {
  60. context.ResponseData.Write((byte)0); //Unknown value.
  61. Logger.PrintStub(LogClass.ServiceAm);
  62. return ResultCode.Success;
  63. }
  64. [Command(9)]
  65. // GetCurrentFocusState() -> u8
  66. public ResultCode GetCurrentFocusState(ServiceCtx context)
  67. {
  68. context.ResponseData.Write((byte)context.Device.System.AppletState.FocusState);
  69. return ResultCode.Success;
  70. }
  71. [Command(60)] // 3.0.0+
  72. // GetDefaultDisplayResolution() -> (u32, u32)
  73. public ResultCode GetDefaultDisplayResolution(ServiceCtx context)
  74. {
  75. context.ResponseData.Write(1280);
  76. context.ResponseData.Write(720);
  77. return ResultCode.Success;
  78. }
  79. [Command(61)] // 3.0.0+
  80. // GetDefaultDisplayResolutionChangeEvent() -> handle<copy>
  81. public ResultCode GetDefaultDisplayResolutionChangeEvent(ServiceCtx context)
  82. {
  83. if (context.Process.HandleTable.GenerateHandle(context.Device.System.DisplayResolutionChangeEvent.ReadableEvent, out int handle) != KernelResult.Success)
  84. {
  85. throw new InvalidOperationException("Out of handles!");
  86. }
  87. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  88. Logger.PrintStub(LogClass.ServiceAm);
  89. return ResultCode.Success;
  90. }
  91. [Command(66)] // 6.0.0+
  92. // SetCpuBoostMode(u32 cpu_boost_mode)
  93. public ResultCode SetCpuBoostMode(ServiceCtx context)
  94. {
  95. uint cpuBoostMode = context.RequestData.ReadUInt32();
  96. if (cpuBoostMode > 1)
  97. {
  98. return ResultCode.InvalidParameters;
  99. }
  100. _cpuBoostMode = (CpuBoostMode)cpuBoostMode;
  101. // NOTE: There is a condition variable after the assignment, probably waiting something with apm:sys service (SetCpuBoostMode call?).
  102. // Since we will probably never support CPU boost things, it's not needed to implement more.
  103. return ResultCode.Success;
  104. }
  105. }
  106. }