ICommonStateGetter.cs 4.4 KB

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