ICommonStateGetter.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Ryujinx.HLE.Logging;
  2. using Ryujinx.HLE.OsHle.Handles;
  3. using Ryujinx.HLE.OsHle.Ipc;
  4. using System.Collections.Generic;
  5. using static Ryujinx.HLE.OsHle.ErrorCode;
  6. namespace Ryujinx.HLE.OsHle.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. Context.ResponseData.Write((byte)OperationMode.Handheld);
  47. return 0;
  48. }
  49. public long GetPerformanceMode(ServiceCtx Context)
  50. {
  51. Context.ResponseData.Write((byte)Apm.PerformanceMode.Handheld);
  52. return 0;
  53. }
  54. public long GetBootMode(ServiceCtx Context)
  55. {
  56. Context.ResponseData.Write((byte)0); //Unknown value.
  57. Context.Ns.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");
  58. return 0;
  59. }
  60. public long GetCurrentFocusState(ServiceCtx Context)
  61. {
  62. Context.ResponseData.Write((byte)Context.Process.AppletState.FocusState);
  63. return 0;
  64. }
  65. public long GetDefaultDisplayResolution(ServiceCtx Context)
  66. {
  67. Context.ResponseData.Write(1280);
  68. Context.ResponseData.Write(720);
  69. return 0;
  70. }
  71. public long GetDefaultDisplayResolutionChangeEvent(ServiceCtx Context)
  72. {
  73. int Handle = Context.Process.HandleTable.OpenHandle(DisplayResolutionChangeEvent);
  74. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  75. Context.Ns.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");
  76. return 0;
  77. }
  78. }
  79. }