using Ryujinx.Memory;
using Ryujinx.Memory.Range;
using System;
namespace Ryujinx.Graphics.Gpu.Memory
{
///
/// A writable block that targets a given MultiRange within a PhysicalMemory instance.
///
internal class MultiRangeWritableBlock : IWritableBlock
{
private readonly MultiRange _range;
private readonly PhysicalMemory _physicalMemory;
///
/// Creates a new MultiRangeWritableBlock.
///
/// The MultiRange to write to
/// The PhysicalMemory the given MultiRange addresses
public MultiRangeWritableBlock(MultiRange range, PhysicalMemory physicalMemory)
{
_range = range;
_physicalMemory = physicalMemory;
}
///
/// Write data to the MultiRange.
///
/// Offset address
/// Data to write
/// Throw when a non-zero offset is given
public void Write(ulong va, ReadOnlySpan data)
{
if (va != 0)
{
throw new ArgumentException($"{nameof(va)} cannot be non-zero for {nameof(MultiRangeWritableBlock)}.");
}
_physicalMemory.Write(_range, data);
}
///
/// Write data to the MultiRange, without tracking.
///
/// Offset address
/// Data to write
/// Throw when a non-zero offset is given
public void WriteUntracked(ulong va, ReadOnlySpan data)
{
if (va != 0)
{
throw new ArgumentException($"{nameof(va)} cannot be non-zero for {nameof(MultiRangeWritableBlock)}.");
}
_physicalMemory.WriteUntracked(_range, data);
}
}
}