/ src / Ryujinx.HLE / HOS / UserChannelPersistence.cs
UserChannelPersistence.cs
 1  using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
 2  using System;
 3  using System.Collections.Generic;
 4  
 5  namespace Ryujinx.HLE.HOS
 6  {
 7      public class UserChannelPersistence
 8      {
 9          private readonly Stack<byte[]> _userChannelStorages;
10          public int PreviousIndex { get; private set; }
11          public int Index { get; private set; }
12          public ProgramSpecifyKind Kind { get; private set; }
13          public bool ShouldRestart { get; set; }
14  
15          public UserChannelPersistence()
16          {
17              _userChannelStorages = new Stack<byte[]>();
18              Kind = ProgramSpecifyKind.ExecuteProgram;
19              PreviousIndex = -1;
20              Index = 0;
21          }
22  
23          public void Clear()
24          {
25              _userChannelStorages.Clear();
26          }
27  
28          public void Push(byte[] data)
29          {
30              _userChannelStorages.Push(data);
31          }
32  
33          public byte[] Pop()
34          {
35              _userChannelStorages.TryPop(out byte[] result);
36  
37              return result;
38          }
39  
40          public bool IsEmpty => _userChannelStorages.Count == 0;
41  
42          public void ExecuteProgram(ProgramSpecifyKind kind, ulong value)
43          {
44              Kind = kind;
45              PreviousIndex = Index;
46              ShouldRestart = true;
47  
48              switch (kind)
49              {
50                  case ProgramSpecifyKind.ExecuteProgram:
51                      Index = (int)value;
52                      break;
53                  case ProgramSpecifyKind.RestartProgram:
54                      break;
55                  default:
56                      throw new NotImplementedException($"{kind} not implemented");
57              }
58          }
59      }
60  }