mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-30 22:49:53 +08:00
initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2026 SharpEmu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
using SharpEmu.HLE;
|
||||
|
||||
namespace SharpEmu.Core.Cpu;
|
||||
|
||||
public sealed class TrackedCpuMemory : ICpuMemory, ITrackedCpuMemory
|
||||
{
|
||||
private readonly ICpuMemory _inner;
|
||||
|
||||
public TrackedCpuMemory(ICpuMemory inner)
|
||||
{
|
||||
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
|
||||
}
|
||||
|
||||
public CpuMemoryAccessFailure? LastFailure { get; private set; }
|
||||
|
||||
public ICpuMemory Inner => _inner;
|
||||
|
||||
public bool TryRead(ulong virtualAddress, Span<byte> destination)
|
||||
{
|
||||
var result = _inner.TryRead(virtualAddress, destination);
|
||||
if (!result)
|
||||
{
|
||||
LastFailure = new CpuMemoryAccessFailure(virtualAddress, destination.Length, isWrite: false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool TryWrite(ulong virtualAddress, ReadOnlySpan<byte> source)
|
||||
{
|
||||
var result = _inner.TryWrite(virtualAddress, source);
|
||||
if (!result)
|
||||
{
|
||||
LastFailure = new CpuMemoryAccessFailure(virtualAddress, source.Length, isWrite: true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user