More registers.

master
Nabile Rahmani 2017-10-30 12:55:01 +01:00
parent d7e97d9b46
commit a605598241
9 changed files with 248 additions and 9 deletions

View File

@ -58,6 +58,10 @@
<Compile Include="CPU\VR4300.RegImmOpCode.cs" />
<Compile Include="PI\PeripheralInterface.CICStatus.cs" />
<Compile Include="Extensions\MappingEntryExtensions.cs" />
<Compile Include="RI\RDRAMInterface.cs" />
<Compile Include="RI\RDRAMInterface.ConfigRegister.cs" />
<Compile Include="RI\RDRAMInterface.ModeRegister.cs" />
<Compile Include="MI\MIPSInterface.InitModeRegister.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CPU\" />
@ -69,6 +73,7 @@
<Folder Include="VI\" />
<Folder Include="MI\" />
<Folder Include="Extensions\" />
<Folder Include="RI\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Specialized;
namespace DotN64.MI
{
public partial class MIPSInterface
{
public struct InitModeRegister
{
#region Fields
private BitVector32 bits;
public static readonly BitVector32.Section InitLengthSection = BitVector32.CreateSection((1 << 7) - 1),
ClearInitModeSection = BitVector32.CreateSection(1, InitLengthSection),
SetInitModeSection = BitVector32.CreateSection(1, ClearInitModeSection),
ClearEbusTestModeSection = BitVector32.CreateSection(1, SetInitModeSection),
SetEbusTestModeSection = BitVector32.CreateSection(1, ClearEbusTestModeSection),
ClearDPInterruptSection = BitVector32.CreateSection(1, SetEbusTestModeSection),
ClearRDRAMRegSection = BitVector32.CreateSection(1, ClearDPInterruptSection),
SetRDRAMRegModeSection = BitVector32.CreateSection(1, ClearRDRAMRegSection);
private static readonly BitVector32.Section initModeSection = BitVector32.CreateSection(1, InitLengthSection),
ebusTestModeSection = BitVector32.CreateSection(1, initModeSection),
rdramRegModeSection = BitVector32.CreateSection(1, ebusTestModeSection);
#endregion
#region Properties
public byte InitLength
{
get => (byte)bits[InitLengthSection];
set => bits[InitLengthSection] = value;
}
public bool InitMode
{
get => Convert.ToBoolean(bits[initModeSection]);
set => bits[initModeSection] = Convert.ToInt32(value);
}
public bool EbusTestMode
{
get => Convert.ToBoolean(bits[ebusTestModeSection]);
set => bits[ebusTestModeSection] = Convert.ToInt32(value);
}
public bool RDRAMRegMode
{
get => Convert.ToBoolean(bits[rdramRegModeSection]);
set => bits[rdramRegModeSection] = Convert.ToInt32(value);
}
#endregion
#region Operators
public static implicit operator InitModeRegister(uint data) => new InitModeRegister { bits = new BitVector32((int)data) };
public static implicit operator uint(InitModeRegister mode) => (uint)mode.bits.Data;
#endregion
}
}
}

View File

@ -1,23 +1,49 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace DotN64.MI
{
using Extensions;
public class MIPSInterface
public partial class MIPSInterface
{
#region Fields
private readonly IReadOnlyList<MappingEntry> memoryMaps;
#endregion
#region Properties
public InitModeRegister InitMode { get; set; }
#endregion
#region Constructors
public MIPSInterface()
{
memoryMaps = new[]
{
new MappingEntry(0x04300004, 0x04300007) // MI version.
new MappingEntry(0x04300000, 0x04300003) // MI init mode.
{
Write = (o, v) => { }
Write = (o, v) =>
{
var bits = new BitVector32((int)v);
var mode = InitMode;
mode.InitLength = (byte)bits[InitModeRegister.InitLengthSection];
mode.InitMode &= bits[InitModeRegister.ClearInitModeSection] == 0;
mode.InitMode |= bits[InitModeRegister.SetInitModeSection] != 0;
mode.EbusTestMode &= bits[InitModeRegister.ClearEbusTestModeSection] == 0;
mode.EbusTestMode |= bits[InitModeRegister.SetEbusTestModeSection] != 0;
if (bits[InitModeRegister.ClearDPInterruptSection] != 0)
throw new NotImplementedException("Clear DP interrupt.");
mode.RDRAMRegMode &= bits[InitModeRegister.ClearRDRAMRegSection] == 0;
mode.RDRAMRegMode |= bits[InitModeRegister.SetRDRAMRegModeSection] != 0;
InitMode = mode;
}
}
};
}

View File

@ -8,6 +8,7 @@ namespace DotN64
using MI;
using PI;
using RCP;
using RI;
using SI;
using VI;
@ -28,6 +29,8 @@ namespace DotN64
public MIPSInterface MI { get; } = new MIPSInterface();
public RDRAMInterface RI { get; } = new RDRAMInterface();
public Cartridge Cartridge { get; set; }
#endregion
@ -84,6 +87,11 @@ namespace DotN64
{
Read = RCP.DP.ReadWord,
Write = RCP.DP.WriteWord
},
new MappingEntry(0x04700000, 0x047FFFFF, false) // RDRAM interface (RI) registers.
{
Read = RI.ReadWord,
Write = RI.WriteWord
}
};
CPU = new VR4300(memoryMaps);

View File

@ -4,9 +4,11 @@ namespace DotN64.PI
{
public partial class PeripheralInterface
{
public class StatusRegister
public struct StatusRegister
{
#region Fields
private BitVector32 bits;
private static readonly int dmaBusy = BitVector32.CreateMask(),
ioBusy = BitVector32.CreateMask(dmaBusy),
error = BitVector32.CreateMask(ioBusy);
@ -15,9 +17,6 @@ namespace DotN64.PI
#endregion
#region Properties
private BitVector32 bits;
public BitVector32 Bits => bits;
public bool DMABusy
{
get => bits[dmaBusy];
@ -36,6 +35,12 @@ namespace DotN64.PI
set => bits[error] = value;
}
#endregion
#region Operators
public static implicit operator StatusRegister(uint data) => new StatusRegister { bits = new BitVector32((int)data) };
public static implicit operator uint(StatusRegister register) => (uint)register.bits.Data;
#endregion
}
}
}

View File

@ -57,7 +57,7 @@ namespace DotN64.PI
},
new MappingEntry(0x04600010, 0x04600013) // PI status.
{
Read = o => (uint)Status.Bits.Data,
Read = o => Status,
Write = (o, v) =>
{
var bits = new BitVector32((int)v);

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Specialized;
namespace DotN64.RI
{
public partial class RDRAMInterface
{
public struct ConfigRegister
{
#region Fields
private BitVector32 bits;
private static readonly BitVector32.Section currentControlInput = BitVector32.CreateSection((1 << 6) - 1),
currentControlEnable = BitVector32.CreateSection(1, currentControlInput);
#endregion
#region Properties
public byte CurrentControlInput
{
get => (byte)bits[currentControlInput];
set => bits[currentControlInput] = value;
}
public bool CurrentControlEnable
{
get => Convert.ToBoolean(bits[currentControlEnable]);
set => bits[currentControlEnable] = Convert.ToInt32(value);
}
#endregion
#region Operators
public static implicit operator ConfigRegister(uint data) => new ConfigRegister { bits = new BitVector32((int)data) };
public static implicit operator uint(ConfigRegister register) => (uint)register.bits.Data;
#endregion
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Specialized;
namespace DotN64.RI
{
public partial class RDRAMInterface
{
public struct ModeRegister
{
#region Fields
private BitVector32 bits;
private static readonly BitVector32.Section operatingMode = BitVector32.CreateSection((1 << 2) - 1),
stopTActive = BitVector32.CreateSection(1, operatingMode),
stopRActive = BitVector32.CreateSection(1, stopTActive);
#endregion
#region Properties
public byte OperatingMode
{
get => (byte)bits[operatingMode];
set => bits[operatingMode] = value;
}
public bool StopTActive
{
get => Convert.ToBoolean(bits[stopTActive]);
set => bits[stopTActive] = Convert.ToInt32(value);
}
public bool StopRActive
{
get => Convert.ToBoolean(bits[stopRActive]);
set => bits[stopRActive] = Convert.ToInt32(value);
}
#endregion
#region Operators
public static implicit operator ModeRegister(uint data) => new ModeRegister { bits = new BitVector32((int)data) };
public static implicit operator uint(ModeRegister register) => (uint)register.bits.Data;
#endregion
}
}
}

View File

@ -0,0 +1,53 @@
using System.Collections.Generic;
namespace DotN64.RI
{
using Extensions;
public partial class RDRAMInterface
{
#region Fields
private readonly IReadOnlyList<MappingEntry> memoryMaps;
#endregion
#region Properties
public byte Select { get; set; }
public ConfigRegister Config { get; set; }
public ModeRegister Mode { get; set; }
#endregion
#region Constructors
public RDRAMInterface()
{
memoryMaps = new[]
{
new MappingEntry(0x0470000C, 0x0470000F) // RI select.
{
Read = o => Select,
Write = (o, v) => Select = (byte)(v & (1 << 3) - 1)
},
new MappingEntry(0x04700004, 0x04700007) // RI config.
{
Write = (o, v) => Config = v
},
new MappingEntry(0x04700008, 0x0470000B) // RI current load.
{
Write = (o, v) => { /* TODO: Any write updates current control register. */ }
},
new MappingEntry(0x04700000, 0x04700003) // RI mode.
{
Write = (o, v) => Mode = v
}
};
}
#endregion
#region Methods
public uint ReadWord(ulong address) => memoryMaps.GetEntry(address).ReadWord(address);
public void WriteWord(ulong address, uint value) => memoryMaps.GetEntry(address).WriteWord(address, value);
#endregion
}
}