UserChannelPersistence.cs 1.6 KB

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