ICommonStateGetter.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel;
  3. using Ryujinx.HLE.Logging;
  4. using System.Collections.Generic;
  5. using static Ryujinx.HLE.HOS.ErrorCode;
  6. namespace Ryujinx.HLE.HOS.Services.Am
  7. {
  8. class ICommonStateGetter : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> m_Commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  12. private KEvent DisplayResolutionChangeEvent;
  13. public ICommonStateGetter()
  14. {
  15. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  16. {
  17. { 0, GetEventHandle },
  18. { 1, ReceiveMessage },
  19. { 5, GetOperationMode },
  20. { 6, GetPerformanceMode },
  21. { 8, GetBootMode },
  22. { 9, GetCurrentFocusState },
  23. { 60, GetDefaultDisplayResolution },
  24. { 61, GetDefaultDisplayResolutionChangeEvent }
  25. };
  26. DisplayResolutionChangeEvent = new KEvent();
  27. }
  28. public long GetEventHandle(ServiceCtx Context)
  29. {
  30. KEvent Event = Context.Process.AppletState.MessageEvent;
  31. int Handle = Context.Process.HandleTable.OpenHandle(Event);
  32. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  33. return 0;
  34. }
  35. public long ReceiveMessage(ServiceCtx Context)
  36. {
  37. if (!Context.Process.AppletState.TryDequeueMessage(out MessageInfo Message))
  38. {
  39. return MakeError(ErrorModule.Am, AmErr.NoMessages);
  40. }
  41. Context.ResponseData.Write((int)Message);
  42. return 0;
  43. }
  44. public long GetOperationMode(ServiceCtx Context)
  45. {
  46. OperationMode Mode = Context.Device.System.State.DockedMode
  47. ? OperationMode.Docked
  48. : OperationMode.Handheld;
  49. Context.ResponseData.Write((byte)Mode);
  50. return 0;
  51. }
  52. public long GetPerformanceMode(ServiceCtx Context)
  53. {
  54. Apm.PerformanceMode Mode = Context.Device.System.State.DockedMode
  55. ? Apm.PerformanceMode.Docked
  56. : Apm.PerformanceMode.Handheld;
  57. Context.ResponseData.Write((int)Mode);
  58. return 0;
  59. }
  60. public long GetBootMode(ServiceCtx Context)
  61. {
  62. Context.ResponseData.Write((byte)0); //Unknown value.
  63. Context.Device.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");
  64. return 0;
  65. }
  66. public long GetCurrentFocusState(ServiceCtx Context)
  67. {
  68. Context.ResponseData.Write((byte)Context.Process.AppletState.FocusState);
  69. return 0;
  70. }
  71. public long GetDefaultDisplayResolution(ServiceCtx Context)
  72. {
  73. Context.ResponseData.Write(1280);
  74. Context.ResponseData.Write(720);
  75. return 0;
  76. }
  77. public long GetDefaultDisplayResolutionChangeEvent(ServiceCtx Context)
  78. {
  79. int Handle = Context.Process.HandleTable.OpenHandle(DisplayResolutionChangeEvent);
  80. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  81. Context.Device.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");
  82. return 0;
  83. }
  84. }
  85. }