ICommonStateGetter.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. public ICommonStateGetter(Horizon system)
  12. {
  13. _displayResolutionChangeEvent = new KEvent(system);
  14. }
  15. [Command(0)]
  16. // GetEventHandle() -> handle<copy>
  17. public ResultCode GetEventHandle(ServiceCtx context)
  18. {
  19. KEvent Event = context.Device.System.AppletState.MessageEvent;
  20. if (context.Process.HandleTable.GenerateHandle(Event.ReadableEvent, out int handle) != KernelResult.Success)
  21. {
  22. throw new InvalidOperationException("Out of handles!");
  23. }
  24. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  25. return ResultCode.Success;
  26. }
  27. [Command(1)]
  28. // ReceiveMessage() -> nn::am::AppletMessage
  29. public ResultCode ReceiveMessage(ServiceCtx context)
  30. {
  31. if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message))
  32. {
  33. return ResultCode.NoMessages;
  34. }
  35. context.ResponseData.Write((int)message);
  36. return ResultCode.Success;
  37. }
  38. [Command(5)]
  39. // GetOperationMode() -> u8
  40. public ResultCode GetOperationMode(ServiceCtx context)
  41. {
  42. OperationMode mode = context.Device.System.State.DockedMode
  43. ? OperationMode.Docked
  44. : OperationMode.Handheld;
  45. context.ResponseData.Write((byte)mode);
  46. return ResultCode.Success;
  47. }
  48. [Command(6)]
  49. // GetPerformanceMode() -> u32
  50. public ResultCode GetPerformanceMode(ServiceCtx context)
  51. {
  52. Apm.PerformanceMode mode = context.Device.System.State.DockedMode
  53. ? Apm.PerformanceMode.Docked
  54. : Apm.PerformanceMode.Handheld;
  55. context.ResponseData.Write((int)mode);
  56. return ResultCode.Success;
  57. }
  58. [Command(8)]
  59. // GetBootMode() -> u8
  60. public ResultCode GetBootMode(ServiceCtx context)
  61. {
  62. context.ResponseData.Write((byte)0); //Unknown value.
  63. Logger.PrintStub(LogClass.ServiceAm);
  64. return ResultCode.Success;
  65. }
  66. [Command(9)]
  67. // GetCurrentFocusState() -> u8
  68. public ResultCode GetCurrentFocusState(ServiceCtx context)
  69. {
  70. context.ResponseData.Write((byte)context.Device.System.AppletState.FocusState);
  71. return ResultCode.Success;
  72. }
  73. [Command(60)] // 3.0.0+
  74. // GetDefaultDisplayResolution() -> (u32, u32)
  75. public ResultCode GetDefaultDisplayResolution(ServiceCtx context)
  76. {
  77. context.ResponseData.Write(1280);
  78. context.ResponseData.Write(720);
  79. return ResultCode.Success;
  80. }
  81. [Command(61)] // 3.0.0+
  82. // GetDefaultDisplayResolutionChangeEvent() -> handle<copy>
  83. public ResultCode GetDefaultDisplayResolutionChangeEvent(ServiceCtx context)
  84. {
  85. if (context.Process.HandleTable.GenerateHandle(_displayResolutionChangeEvent.ReadableEvent, out int handle) != KernelResult.Success)
  86. {
  87. throw new InvalidOperationException("Out of handles!");
  88. }
  89. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  90. Logger.PrintStub(LogClass.ServiceAm);
  91. return ResultCode.Success;
  92. }
  93. }
  94. }