aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/OsHle/Services/Am/ICommonStateGetter.cs
blob: 2b575cb7cb100c998e5ad64bd0bcb4ce45e507a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle.Handles;
using Ryujinx.HLE.OsHle.Ipc;
using System.Collections.Generic;

using static Ryujinx.HLE.OsHle.ErrorCode;

namespace Ryujinx.HLE.OsHle.Services.Am
{
    class ICommonStateGetter : IpcService
    {
        private Dictionary<int, ServiceProcessRequest> m_Commands;

        public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;

        public ICommonStateGetter()
        {
            m_Commands = new Dictionary<int, ServiceProcessRequest>()
            {
                { 0, GetEventHandle       },
                { 1, ReceiveMessage       },
                { 5, GetOperationMode     },
                { 6, GetPerformanceMode   },
                { 8, GetBootMode          },
                { 9, GetCurrentFocusState }
            };
        }

        public long GetEventHandle(ServiceCtx Context)
        {
            KEvent Event = Context.Process.AppletState.MessageEvent;

            int Handle = Context.Process.HandleTable.OpenHandle(Event);

            Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);

            return 0;
        }

        public long ReceiveMessage(ServiceCtx Context)
        {
            if (!Context.Process.AppletState.TryDequeueMessage(out MessageInfo Message))
            {
                return MakeError(ErrorModule.Am, AmErr.NoMessages);
            }

            Context.ResponseData.Write((int)Message);

            return 0;
        }

        public long GetOperationMode(ServiceCtx Context)
        {
            Context.ResponseData.Write((byte)OperationMode.Handheld);

            return 0;
        }

        public long GetPerformanceMode(ServiceCtx Context)
        {
            Context.ResponseData.Write((byte)Apm.PerformanceMode.Handheld);

            return 0;
        }

        public long GetBootMode(ServiceCtx Context)
        {
            Context.ResponseData.Write((byte)0); //Unknown value.

            Context.Ns.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");

            return 0;
        }

        public long GetCurrentFocusState(ServiceCtx Context)
        {
            Context.ResponseData.Write((byte)Context.Process.AppletState.FocusState);

            return 0;
        }
    }
}