DotN64/DotN64/MappingEntry.cs

47 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
2017-10-09 08:21:31 +02:00
namespace DotN64
{
public struct MappingEntry
{
#region Properties
public uint StartAddress { get; }
public uint EndAddress { get; }
2017-11-04 12:14:51 +01:00
public bool OffsetAddress { get; set; }
public Func<uint, uint> Read { get; set; }
public Action<uint, uint> Write { get; set; }
#endregion
#region Constructors
public MappingEntry(uint startAddress, uint endAddress, bool offsetAddress = true)
: this()
{
StartAddress = startAddress;
EndAddress = endAddress;
2017-10-04 10:54:40 +02:00
OffsetAddress = offsetAddress;
Contract.Ensures(EndAddress >= StartAddress);
}
#endregion
#region Methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(uint address) => address >= StartAddress && address <= EndAddress;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint ReadWord(uint address) => Read(OffsetAddress ? address - StartAddress : address);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2018-06-09 18:31:15 +02:00
public void WriteWord(uint address, uint data) => Write(OffsetAddress ? address - StartAddress : address, data);
2018-06-05 17:32:59 +02:00
public override string ToString() => $"0x{StartAddress:X8} .. 0x{EndAddress:X8} ({(Read != null ? "R" : string.Empty)}{(Write != null ? "W" : string.Empty)})";
#endregion
}
}