Start Storage Impl

This commit is contained in:
Isaac Marovitz 2024-02-15 13:05:18 -05:00
parent c1c7f455fa
commit 9a767b1654
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
6 changed files with 78 additions and 25 deletions

View file

@ -7,11 +7,19 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
{ {
partial class Storage : IStorage partial class Storage : IStorage
{ {
public bool IsReadOnly { get; private set; }
public byte[] Data { get; private set; }
public Storage(byte[] data, bool isReadOnly = false)
{
IsReadOnly = isReadOnly;
Data = data;
}
[CmifCommand(0)] [CmifCommand(0)]
public Result Open(out IStorageAccessor storageAccessor) public Result Open(out IStorageAccessor storageAccessor)
{ {
storageAccessor = new StorageAccessor(); storageAccessor = new StorageAccessor(this);
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success; return Result.Success;
} }
@ -19,17 +27,7 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
[CmifCommand(1)] [CmifCommand(1)]
public Result OpenTransferStorage(out ITransferStorageAccessor transferStorageAccessor) public Result OpenTransferStorage(out ITransferStorageAccessor transferStorageAccessor)
{ {
transferStorageAccessor = new TransferStorageAccessor(); transferStorageAccessor = new TransferStorageAccessor(this);
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success;
}
// TODO: Get CMD No.
public Result GetAndInvalidate(out IStorage storage)
{
storage = new Storage();
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success; return Result.Success;
} }

View file

@ -1,5 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Horizon.Common; using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Am;
using Ryujinx.Horizon.Sdk.Am.Storage; using Ryujinx.Horizon.Sdk.Am.Storage;
using Ryujinx.Horizon.Sdk.Sf; using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc; using Ryujinx.Horizon.Sdk.Sf.Hipc;
@ -9,11 +9,17 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
{ {
partial class StorageAccessor : IStorageAccessor partial class StorageAccessor : IStorageAccessor
{ {
private readonly Storage _storage;
public StorageAccessor(Storage storage)
{
_storage = storage;
}
[CmifCommand(0)] [CmifCommand(0)]
public Result GetSize(out long size) public Result GetSize(out long size)
{ {
size = 0; size = _storage.Data.Length;
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success; return Result.Success;
} }
@ -21,7 +27,17 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
[CmifCommand(10)] [CmifCommand(10)]
public Result Write(long offset, [Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySpan<byte> span) public Result Write(long offset, [Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySpan<byte> span)
{ {
Logger.Stub?.PrintStub(LogClass.ServiceAm); if (_storage.IsReadOnly)
{
return AmResult.ObjectInvalid;
}
if (offset > _storage.Data.Length)
{
return AmResult.OutOfBounds;
}
// TODO: Write
return Result.Success; return Result.Success;
} }
@ -29,7 +45,12 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
[CmifCommand(11)] [CmifCommand(11)]
public Result Read(long offset, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Span<byte> span) public Result Read(long offset, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Span<byte> span)
{ {
Logger.Stub?.PrintStub(LogClass.ServiceAm); if (offset > _storage.Data.Length)
{
return AmResult.OutOfBounds;
}
// TODO: Read
return Result.Success; return Result.Success;
} }

View file

@ -2,15 +2,18 @@ using Ryujinx.Common.Logging;
using Ryujinx.Horizon.Common; using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Am.Storage; using Ryujinx.Horizon.Sdk.Am.Storage;
using Ryujinx.Horizon.Sdk.Sf; using Ryujinx.Horizon.Sdk.Sf;
using System.Collections.Generic;
namespace Ryujinx.Horizon.Am.Ipc.Storage namespace Ryujinx.Horizon.Am.Ipc.Storage
{ {
partial class StorageChannel : IStorageChannel partial class StorageChannel : IStorageChannel
{ {
private Stack<IStorage> _storages;
[CmifCommand(0)] [CmifCommand(0)]
public Result Push(IStorage storage) public Result Push(IStorage storage)
{ {
Logger.Stub?.PrintStub(LogClass.ServiceAm); _storages.Push(storage);
return Result.Success; return Result.Success;
} }
@ -26,8 +29,7 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
[CmifCommand(2)] [CmifCommand(2)]
public Result Pop(out IStorage storage) public Result Pop(out IStorage storage)
{ {
storage = new Storage(); storage = _storages.Pop();
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success; return Result.Success;
} }
@ -44,7 +46,7 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
[CmifCommand(4)] [CmifCommand(4)]
public Result Clear() public Result Clear()
{ {
Logger.Stub?.PrintStub(LogClass.ServiceAm); _storages.Clear();
return Result.Success; return Result.Success;
} }

View file

@ -7,11 +7,17 @@ namespace Ryujinx.Horizon.Am.Ipc.Storage
{ {
partial class TransferStorageAccessor : ITransferStorageAccessor partial class TransferStorageAccessor : ITransferStorageAccessor
{ {
private readonly Storage _storage;
public TransferStorageAccessor(Storage storage)
{
_storage = storage;
}
[CmifCommand(0)] [CmifCommand(0)]
public Result GetSize(out long size) public Result GetSize(out long size)
{ {
size = 0; size = _storage.Data.Length;
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return Result.Success; return Result.Success;
} }

View file

@ -0,0 +1,27 @@
using Ryujinx.Horizon.Common;
namespace Ryujinx.Horizon.Sdk.Am
{
static class AmResult
{
private const int Moduleld = 128;
public static Result NotAvailable => new(Moduleld, 2);
public static Result NoMessages => new(Moduleld, 3);
public static Result AppletLaunchFailed => new(Moduleld, 35);
public static Result TitleIdNotFound => new(Moduleld, 37);
public static Result ObjectInvalid => new(Moduleld, 500);
public static Result IStorageInUse => new(Moduleld, 502);
public static Result OutOfBounds => new(Moduleld, 502);
public static Result BufferNotAcquired => new(Moduleld, 504);
public static Result BufferAlreadyAcquired => new(Moduleld, 505);
public static Result InvalidParameters => new(Moduleld, 506);
public static Result OpenedAsWrongType => new(Moduleld, 511);
public static Result UnbalancedFatalSection => new(Moduleld, 512);
public static Result NullObject => new(Moduleld, 518);
public static Result MemoryAllocationFailed => new(Moduleld, 600);
public static Result StackPoolExhausted => new(Moduleld, 712);
public static Result DebugModeNotEnabled => new(Moduleld, 974);
public static Result DevFunctionNotEnabled => new(Moduleld, 980);
}
}

View file

@ -7,6 +7,5 @@ namespace Ryujinx.Horizon.Sdk.Am.Storage
{ {
Result Open(out IStorageAccessor storageAccessor); Result Open(out IStorageAccessor storageAccessor);
Result OpenTransferStorage(out ITransferStorageAccessor transferStorageAccessor); Result OpenTransferStorage(out ITransferStorageAccessor transferStorageAccessor);
Result GetAndInvalidate(out IStorage storage);
} }
} }