The CPU only supports 32-bit physical addresses.
No point in keeping the result of translated addresses 64-bit.master
parent
cc81d9d21d
commit
08853d495f
|
@ -27,14 +27,14 @@ namespace DotN64.CPU
|
|||
/// Translates a virtual address into a physical address.
|
||||
/// See: datasheet#5.2.4 Table 5-3.
|
||||
/// </summary>
|
||||
public ulong Translate(ulong address)
|
||||
public uint Translate(ulong address)
|
||||
{
|
||||
switch (address >> 29 & 0b111)
|
||||
{
|
||||
case 0b100: // kseg0.
|
||||
return address - 0xFFFFFFFF80000000;
|
||||
return (uint)(address - 0xFFFFFFFF80000000);
|
||||
case 0b101: // kseg1.
|
||||
return address - 0xFFFFFFFFA0000000;
|
||||
return (uint)(address - 0xFFFFFFFFA0000000);
|
||||
default:
|
||||
throw new Exception($"Unknown memory map segment for location 0x{address:X16}.");
|
||||
}
|
||||
|
|
|
@ -73,12 +73,12 @@ namespace DotN64.CPU
|
|||
/// <summary>
|
||||
/// System address/data bus.
|
||||
/// </summary>
|
||||
public Func<ulong, uint> ReadSysAD { get; set; }
|
||||
public Func<uint, uint> ReadSysAD { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// System address/data bus.
|
||||
/// </summary>
|
||||
public Action<ulong, uint> WriteSysAD { get; set; }
|
||||
public Action<uint, uint> WriteSysAD { get; set; }
|
||||
|
||||
public SystemControlUnit CP0 { get; } = new SystemControlUnit();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace DotN64.Extensions
|
|||
{
|
||||
#region Methods
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MappingEntry GetEntry(this IReadOnlyList<MappingEntry> memoryMaps, ulong address)
|
||||
public static MappingEntry GetEntry(this IReadOnlyList<MappingEntry> memoryMaps, uint address)
|
||||
{
|
||||
for (int i = 0; i < memoryMaps.Count; i++)
|
||||
{
|
||||
|
@ -18,14 +18,14 @@ namespace DotN64.Extensions
|
|||
return entry;
|
||||
}
|
||||
|
||||
throw new Exception($"Unknown physical address: 0x{address:X16}.");
|
||||
throw new Exception($"Unknown physical address: 0x{address:X8}.");
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint ReadWord(this IReadOnlyList<MappingEntry> memoryMaps, ulong address) => memoryMaps.GetEntry(address).ReadWord(address);
|
||||
public static uint ReadWord(this IReadOnlyList<MappingEntry> memoryMaps, uint address) => memoryMaps.GetEntry(address).ReadWord(address);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteWord(this IReadOnlyList<MappingEntry> memoryMaps, ulong address, uint value) => memoryMaps.GetEntry(address).WriteWord(address, value);
|
||||
public static void WriteWord(this IReadOnlyList<MappingEntry> memoryMaps, uint address, uint value) => memoryMaps.GetEntry(address).WriteWord(address, value);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,19 @@ namespace DotN64
|
|||
public struct MappingEntry
|
||||
{
|
||||
#region Properties
|
||||
public ulong StartAddress { get; set; }
|
||||
public uint StartAddress { get; set; }
|
||||
|
||||
public ulong EndAddress { get; set; }
|
||||
public uint EndAddress { get; set; }
|
||||
|
||||
public bool OffsetAddress { get; set; }
|
||||
|
||||
public Func<ulong, uint> Read { get; set; }
|
||||
public Func<uint, uint> Read { get; set; }
|
||||
|
||||
public Action<ulong, uint> Write { get; set; }
|
||||
public Action<uint, uint> Write { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public MappingEntry(ulong startAddress, ulong endAddress, bool offsetAddress = true)
|
||||
public MappingEntry(uint startAddress, uint endAddress, bool offsetAddress = true)
|
||||
: this()
|
||||
{
|
||||
StartAddress = startAddress;
|
||||
|
@ -29,15 +29,15 @@ namespace DotN64
|
|||
|
||||
#region Methods
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Contains(ulong address) => address >= StartAddress && address <= EndAddress;
|
||||
public bool Contains(uint address) => address >= StartAddress && address <= EndAddress;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint ReadWord(ulong address) => Read(OffsetAddress ? address - StartAddress : address);
|
||||
public uint ReadWord(uint address) => Read(OffsetAddress ? address - StartAddress : address);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteWord(ulong address, uint value) => Write(OffsetAddress ? address - StartAddress : address, value);
|
||||
public void WriteWord(uint address, uint value) => Write(OffsetAddress ? address - StartAddress : address, value);
|
||||
|
||||
public override string ToString() => $"[0x{StartAddress:X16}..0x{EndAddress:X16}] - {(Read != null ? "R" : "-")}{(Write != null ? "W" : "-")}";
|
||||
public override string ToString() => $"[0x{StartAddress:X8}..0x{EndAddress:X8}] - {(Read != null ? "R" : "-")}{(Write != null ? "W" : "-")}";
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue