1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| class RegBitSupplies
{
public static System.Collections.Hashtable Data = new System.Collections.Hashtable();
};
struct RegBit<T>
{
public T Data;
public RegBit(uint bitno, uint nbits, T p_DefaultValue)
{
Data = p_DefaultValue;
RegBitSupplies.Data.Add(this, new Tuple<uint, uint>(bitno, nbits ));
}
public uint GetMask()
{
return (uint)((1 << ((int)(RegBitSupplies.Data[this] as Tuple<uint, uint>).Item2)) - 1);
}
public RegBit<T> Set<T2>(T2 p_Val)
{
uint l_BitNo = (RegBitSupplies.Data[this] as Tuple<uint, uint>).Item1;
uint l_NBits = (RegBitSupplies.Data[this] as Tuple<uint, uint>).Item2;
Int32 l_Part1 = ((Int32)Convert.ChangeType(Data, TypeCode.Int32)) & ~(((Int32)GetMask() << (Int32)(l_BitNo)));
Int32 l_Part2 = (((Int32)(l_NBits) > 1 ? (Int32)Convert.ChangeType(p_Val, TypeCode.Int32) & (Int32)GetMask() : (Int32)Convert.ChangeType(p_Val, TypeCode.Int32)) << (Int32)(l_BitNo));
Data = (T)Convert.ChangeType((Int32)(l_Part1 | l_Part2), typeof(T));
return this;
}
public static explicit operator uint(RegBit<T> p_RegBit)
{
return (uint)(((Int32)Convert.ChangeType(p_RegBit.Data, TypeCode.Int32) >> (Int32)(RegBitSupplies.Data[p_RegBit] as Tuple<uint, uint>).Item1) & (Int32)p_RegBit.GetMask());
}
/* RegBit& operator++ () { return *this = *this + 1; }
uint operator++ (int) { uint r = *this; ++*this; return r; }*/
}; |
Partager