Ryujinx/Ryujinx.Core/OsHle/Services/Am/IStorageAccessor.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2018-02-05 00:08:20 +01:00
using ChocolArm64.Memory;
using Ryujinx.Core.OsHle.Ipc;
2018-02-05 00:08:20 +01:00
using System;
using System.Collections.Generic;
2018-02-05 00:08:20 +01:00
2018-03-20 21:00:00 +01:00
namespace Ryujinx.Core.OsHle.Services.Am
2018-02-05 00:08:20 +01:00
{
class IStorageAccessor : IpcService
2018-02-05 00:08:20 +01:00
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
2018-02-05 00:08:20 +01:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private IStorage Storage;
public IStorageAccessor(IStorage Storage)
2018-02-05 00:08:20 +01:00
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
2018-04-24 20:57:39 +02:00
{ 0, GetSize },
{ 11, Read }
};
2018-02-05 00:08:20 +01:00
this.Storage = Storage;
}
public long GetSize(ServiceCtx Context)
2018-02-05 00:08:20 +01:00
{
Context.ResponseData.Write((long)Storage.Data.Length);
2018-02-05 00:08:20 +01:00
return 0;
}
public long Read(ServiceCtx Context)
2018-02-05 00:08:20 +01:00
{
long ReadPosition = Context.RequestData.ReadInt64();
if (Context.Request.RecvListBuff.Count > 0)
{
long Position = Context.Request.RecvListBuff[0].Position;
short Size = Context.Request.RecvListBuff[0].Size;
byte[] Data;
if (Storage.Data.Length > Size)
{
Data = new byte[Size];
2018-04-24 20:57:39 +02:00
2018-02-05 00:08:20 +01:00
Buffer.BlockCopy(Storage.Data, 0, Data, 0, Size);
}
else
{
Data = Storage.Data;
}
AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
}
return 0;
}
}
}