ICommonStateGetter.cs 4.5 KB

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