2017-10-03 02:14:41 +02:00
|
|
|
|
using System;
|
2018-11-21 17:30:21 +01:00
|
|
|
|
using System.Diagnostics.Contracts;
|
2017-11-21 12:59:59 +01:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2017-10-09 08:21:31 +02:00
|
|
|
|
namespace DotN64
|
2017-10-03 02:14:41 +02:00
|
|
|
|
{
|
|
|
|
|
public struct MappingEntry
|
|
|
|
|
{
|
|
|
|
|
#region Properties
|
2018-11-21 17:30:21 +01:00
|
|
|
|
public uint StartAddress { get; }
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2018-11-21 17:30:21 +01:00
|
|
|
|
public uint EndAddress { get; }
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2017-11-04 12:14:51 +01:00
|
|
|
|
public bool OffsetAddress { get; set; }
|
|
|
|
|
|
2017-12-20 01:41:27 +01:00
|
|
|
|
public Func<uint, uint> Read { get; set; }
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2017-12-20 01:41:27 +01:00
|
|
|
|
public Action<uint, uint> Write { get; set; }
|
2017-10-03 02:14:41 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
2017-12-20 01:41:27 +01:00
|
|
|
|
public MappingEntry(uint startAddress, uint endAddress, bool offsetAddress = true)
|
2017-10-03 02:14:41 +02:00
|
|
|
|
: this()
|
|
|
|
|
{
|
|
|
|
|
StartAddress = startAddress;
|
|
|
|
|
EndAddress = endAddress;
|
2017-10-04 10:54:40 +02:00
|
|
|
|
OffsetAddress = offsetAddress;
|
2018-11-21 17:30:21 +01:00
|
|
|
|
|
|
|
|
|
Contract.Ensures(EndAddress >= StartAddress);
|
2017-10-03 02:14:41 +02:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2017-11-21 12:59:59 +01:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2017-12-20 01:41:27 +01:00
|
|
|
|
public bool Contains(uint address) => address >= StartAddress && address <= EndAddress;
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2017-11-21 12:59:59 +01:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2017-12-20 01:41:27 +01:00
|
|
|
|
public uint ReadWord(uint address) => Read(OffsetAddress ? address - StartAddress : address);
|
2017-10-03 02:14:41 +02:00
|
|
|
|
|
2017-11-21 12:59:59 +01:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2018-06-09 18:31:15 +02:00
|
|
|
|
public void WriteWord(uint address, uint data) => Write(OffsetAddress ? address - StartAddress : address, data);
|
2017-10-30 21:46:09 +01:00
|
|
|
|
|
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)})";
|
2017-10-03 02:14:41 +02:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|