IStorageAccessor.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Core.OsHle.Ipc;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Core.OsHle.Objects.Am
  6. {
  7. class IStorageAccessor : IIpcInterface
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. private IStorage Storage;
  12. public IStorageAccessor(IStorage Storage)
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, GetSize },
  17. { 11, Read }
  18. };
  19. this.Storage = Storage;
  20. }
  21. public long GetSize(ServiceCtx Context)
  22. {
  23. Context.ResponseData.Write((long)Storage.Data.Length);
  24. return 0;
  25. }
  26. public long Read(ServiceCtx Context)
  27. {
  28. long ReadPosition = Context.RequestData.ReadInt64();
  29. if (Context.Request.RecvListBuff.Count > 0)
  30. {
  31. long Position = Context.Request.RecvListBuff[0].Position;
  32. short Size = Context.Request.RecvListBuff[0].Size;
  33. byte[] Data;
  34. if (Storage.Data.Length > Size)
  35. {
  36. Data = new byte[Size];
  37. Buffer.BlockCopy(Storage.Data, 0, Data, 0, Size);
  38. }
  39. else
  40. {
  41. Data = Storage.Data;
  42. }
  43. AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
  44. }
  45. return 0;
  46. }
  47. }
  48. }