... Aren't they more cute as enumerations ?
parent
d5efc12872
commit
dbe5cc6559
|
@ -1,46 +1,13 @@
|
|||
using System.Collections.Specialized;
|
||||
|
||||
namespace DotN64.PI
|
||||
namespace DotN64.PI
|
||||
{
|
||||
public partial class PeripheralInterface
|
||||
{
|
||||
public struct StatusRegister
|
||||
[System.Flags]
|
||||
public enum StatusRegister
|
||||
{
|
||||
#region Fields
|
||||
private BitVector32 bits;
|
||||
|
||||
private static readonly int dmaBusy = BitVector32.CreateMask(),
|
||||
ioBusy = BitVector32.CreateMask(dmaBusy),
|
||||
error = BitVector32.CreateMask(ioBusy);
|
||||
public static readonly int ResetControllerMask = BitVector32.CreateMask(),
|
||||
ClearInterruptMask = BitVector32.CreateMask(ResetControllerMask);
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public bool DMABusy
|
||||
{
|
||||
get => bits[dmaBusy];
|
||||
set => bits[dmaBusy] = value;
|
||||
}
|
||||
|
||||
public bool IOBusy
|
||||
{
|
||||
get => bits[ioBusy];
|
||||
set => bits[ioBusy] = value;
|
||||
}
|
||||
|
||||
public bool Error
|
||||
{
|
||||
get => bits[error];
|
||||
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
|
||||
DMABusy = 1 << 0,
|
||||
IOBusy = 1 << 1,
|
||||
Error = 1 << 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Net;
|
||||
|
||||
namespace DotN64.PI
|
||||
|
@ -12,11 +11,12 @@ namespace DotN64.PI
|
|||
#region Fields
|
||||
private readonly IReadOnlyList<MappingEntry> memoryMaps;
|
||||
|
||||
private const int CICStatusOffset = 60;
|
||||
private const byte CICStatusOffset = 60;
|
||||
private const byte ResetControllerStatus = 1 << 0, ClearInterruptStatus = 1 << 1;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public StatusRegister Status { get; } = new StatusRegister();
|
||||
public StatusRegister Status { get; set; }
|
||||
|
||||
public byte[] BootROM { get; set; }
|
||||
|
||||
|
@ -57,15 +57,13 @@ namespace DotN64.PI
|
|||
},
|
||||
new MappingEntry(0x04600010, 0x04600013) // PI status.
|
||||
{
|
||||
Read = o => Status,
|
||||
Read = o => (uint)Status,
|
||||
Write = (o, v) =>
|
||||
{
|
||||
var bits = new BitVector32((int)v);
|
||||
|
||||
if (bits[StatusRegister.ResetControllerMask])
|
||||
if ((v & ResetControllerStatus) != 0)
|
||||
ResetController();
|
||||
|
||||
if (bits[StatusRegister.ClearInterruptMask])
|
||||
if ((v & ClearInterruptStatus) != 0)
|
||||
ClearInterrupt();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,49 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace DotN64.SI
|
||||
namespace DotN64.SI
|
||||
{
|
||||
public partial class SerialInterface
|
||||
{
|
||||
public class StatusRegister
|
||||
[System.Flags]
|
||||
public enum StatusRegister
|
||||
{
|
||||
#region Fields
|
||||
private static readonly BitVector32.Section dmaBusy = BitVector32.CreateSection(1),
|
||||
ioReadBusy = BitVector32.CreateSection(1, dmaBusy),
|
||||
reserved = BitVector32.CreateSection(1, ioReadBusy),
|
||||
dmaError = BitVector32.CreateSection(1, reserved),
|
||||
unknown1 = BitVector32.CreateSection((1 << 8) - 1, dmaError),
|
||||
interrupt = BitVector32.CreateSection(1, unknown1);
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
private BitVector32 bits;
|
||||
public BitVector32 Bits => bits;
|
||||
|
||||
public bool DMABusy
|
||||
{
|
||||
get => Convert.ToBoolean(bits[dmaBusy]);
|
||||
set => bits[dmaBusy] = Convert.ToInt32(value);
|
||||
}
|
||||
|
||||
public bool IOReadBusy
|
||||
{
|
||||
get => Convert.ToBoolean(bits[ioReadBusy]);
|
||||
set => bits[ioReadBusy] = Convert.ToInt32(value);
|
||||
}
|
||||
|
||||
public bool DMAError
|
||||
{
|
||||
get => Convert.ToBoolean(bits[dmaError]);
|
||||
set => bits[dmaError] = Convert.ToInt32(value);
|
||||
}
|
||||
|
||||
public bool Interrupt
|
||||
{
|
||||
get => Convert.ToBoolean(bits[interrupt]);
|
||||
set => bits[interrupt] = Convert.ToInt32(value);
|
||||
}
|
||||
#endregion
|
||||
DMABusy = 1 << 0,
|
||||
IOReadBusy = 1 << 1,
|
||||
DMAError = 1 << 3,
|
||||
Interrupt = 1 << 12
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace DotN64.SI
|
|||
#endregion
|
||||
|
||||
#region Properties
|
||||
public StatusRegister Status { get; } = new StatusRegister();
|
||||
public StatusRegister Status { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
@ -21,8 +21,8 @@ namespace DotN64.SI
|
|||
{
|
||||
new MappingEntry(0x04800018, 0x0480001B) // SI status.
|
||||
{
|
||||
Read = o => (uint)Status.Bits.Data,
|
||||
Write = (o, v) => Status.Interrupt = false
|
||||
Read = o => (uint)Status,
|
||||
Write = (o, v) => Status &= ~StatusRegister.Interrupt
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue