2018-02-04 23:08:20 +00:00
|
|
|
using ChocolArm64.Memory;
|
2018-02-10 00:14:55 +00:00
|
|
|
using Ryujinx.OsHle.Ipc;
|
2018-02-04 23:08:20 +00:00
|
|
|
using System;
|
2018-02-10 00:14:55 +00:00
|
|
|
using System.Collections.Generic;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-02-10 00:14:55 +00:00
|
|
|
namespace Ryujinx.OsHle.Objects.Am
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-10 00:14:55 +00:00
|
|
|
class IStorageAccessor : IIpcInterface
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-10 00:14:55 +00:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-02-10 00:14:55 +00:00
|
|
|
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
|
|
|
|
|
|
|
public IStorage Storage { get; private set; }
|
|
|
|
|
|
|
|
public IStorageAccessor(IStorage Storage)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-10 00:14:55 +00:00
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 0, GetSize },
|
|
|
|
{ 11, Read }
|
|
|
|
};
|
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
this.Storage = Storage;
|
|
|
|
}
|
|
|
|
|
2018-02-10 00:14:55 +00:00
|
|
|
public long GetSize(ServiceCtx Context)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-10 00:14:55 +00:00
|
|
|
IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
Context.ResponseData.Write((long)Accessor.Storage.Data.Length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 00:14:55 +00:00
|
|
|
public long Read(ServiceCtx Context)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-10 00:14:55 +00:00
|
|
|
IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-02-10 00:14:55 +00:00
|
|
|
IStorage Storage = Accessor.Storage;
|
2018-02-04 23:08:20 +00: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];
|
|
|
|
|
|
|
|
Buffer.BlockCopy(Storage.Data, 0, Data, 0, Size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Data = Storage.Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|