Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
quajak committed May 17, 2021
1 parent d6bd15f commit 76dceac
Show file tree
Hide file tree
Showing 38 changed files with 273 additions and 274 deletions.
16 changes: 8 additions & 8 deletions source/Cosmos.Common/BinaryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BinaryHelper
/// <param name="data">A 16-bit unsigned int data</param>
/// <param name="bit">The zero-based position of a bit. I.e. bit 1 is the second bit.</param>
/// <returns>Returns TRUE if bit is set.</returns>
public static bool CheckBit(UInt16 data, ushort bit)
public static bool CheckBit(ushort data, ushort bit)
{
//A single bit is LEFT SHIFTED the number a given number of bits.
//and bitwise AND'ed together with the data.
Expand All @@ -31,9 +31,9 @@ public static bool CheckBit(UInt16 data, ushort bit)
/// <param name="data">A 32-bit unsigned int data.</param>
/// <param name="bit">The zero-based position of a bit. I.e. bit 1 is the second bit.</param>
/// <returns>Returns TRUE if bit is set.</returns>
public static bool CheckBit(UInt32 data, ushort bit)
public static bool CheckBit(uint data, ushort bit)
{
UInt32 mask = (UInt32)(1 << (int)bit);
uint mask = (uint)(1 << (int)bit);
return (data & mask) != 0;
}

Expand Down Expand Up @@ -64,13 +64,13 @@ public static byte FlipBit(byte data, ushort bitposition)
/// <param name="data">A 32-bit unsigned int of data.</param>
/// <param name="bitposition">A bit position to change.</param>
/// <returns>The same data, but with one bit changed.</returns>
public static UInt32 FlipBit(UInt32 data, ushort bitposition)
public static uint FlipBit(uint data, ushort bitposition)
{
UInt32 mask = (UInt32)(1 << bitposition);
uint mask = (uint)(1 << bitposition);
if (CheckBit(data, bitposition))
return (UInt32)(data & ~mask);
return (uint)(data & ~mask);
else
return (UInt32)(data | mask);
return (uint)(data | mask);
}


Expand All @@ -81,7 +81,7 @@ public static UInt32 FlipBit(UInt32 data, ushort bitposition)
/// <param name="offset">The offset (in bytes) from the start of the data.</param>
/// <exception cref="ArgumentException">Thrown when offset is greater then 24.</exception>
/// <returns>Extracted 8-bit unsigned int (byte).</returns>
public static byte GetByteFrom32bit(UInt32 data, byte offset)
public static byte GetByteFrom32bit(uint data, byte offset)
{
if (offset > 24)
throw new ArgumentException("Offset can not move outside the 32 bit range");
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.Core/IOGroup/ATA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal ATA(bool aSecondary)
/// <returns>ushort value.</returns>
private static ushort GetBAR1(bool aSecondary)
{
UInt16 xBAR1 = (UInt16)(aSecondary ? 0x0374 : 0x03F4);
ushort xBAR1 = (ushort)(aSecondary ? 0x0374 : 0x03F4);
return xBAR1;
}

Expand All @@ -103,7 +103,7 @@ private static ushort GetBAR1(bool aSecondary)
/// <returns>ushort value.</returns>
private static ushort GetBAR0(bool aSecondary)
{
UInt16 xBAR0 = (UInt16)(aSecondary ? 0x0170 : 0x01F0);
ushort xBAR0 = (ushort)(aSecondary ? 0x0170 : 0x01F0);
return xBAR0;
}
}
Expand Down
28 changes: 14 additions & 14 deletions source/Cosmos.Core/ManagedMemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public unsafe class ManagedMemoryBlock
/// <summary>
/// Offset.
/// </summary>
public UInt32 Offset;
public uint Offset;
/// <summary>
/// Size.
/// </summary>
public UInt32 Size;
public uint Size;

/// <summary>
/// Create a new buffer with the given size, not aligned
/// </summary>
/// <param name="size">Size of buffer</param>
public ManagedMemoryBlock(UInt32 size)
public ManagedMemoryBlock(uint size)
: this(size, 1, false)
{ }

Expand All @@ -31,7 +31,7 @@ public ManagedMemoryBlock(UInt32 size)
/// </summary>
/// <param name="size">Size of buffer</param>
/// <param name="alignment">Byte Boundary alignment</param>
public ManagedMemoryBlock(UInt32 size, int alignment)
public ManagedMemoryBlock(uint size, int alignment)
: this(size, alignment, true)
{ }

Expand All @@ -41,12 +41,12 @@ public ManagedMemoryBlock(UInt32 size, int alignment)
/// <param name="size">Size of buffer</param>
/// <param name="alignment">Byte Boundary alignment</param>
/// <param name="align">true if buffer should be aligned, false otherwise</param>
public ManagedMemoryBlock(UInt32 size, int alignment, bool align)
public ManagedMemoryBlock(uint size, int alignment, bool align)
{
memory = new byte[size + alignment - 1];
fixed (byte* bodystart = memory)
{
Offset = (UInt32)bodystart;
Offset = (uint)bodystart;
Size = size;
}
if (align == true)
Expand Down Expand Up @@ -152,11 +152,11 @@ public unsafe void Copy(MemoryBlock block)
/// <param name="offset">Data offset.</param>
/// <returns>UInt16 value.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if offset if bigger than memory block size.</exception>
public UInt16 Read16(uint offset)
public ushort Read16(uint offset)
{
if (offset > Size)
throw new ArgumentOutOfRangeException("offset");
return *(UInt16*)(this.Offset + offset);
return *(ushort*)(this.Offset + offset);
}

/// <summary>
Expand All @@ -165,11 +165,11 @@ public UInt16 Read16(uint offset)
/// <param name="offset">Data offset.</param>
/// <param name="value">Value to write.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if offset if bigger than memory block size or smaller than 0.</exception>
public void Write16(uint offset, UInt16 value)
public void Write16(uint offset, ushort value)
{
if (offset < 0 || offset > Size)
throw new ArgumentOutOfRangeException("offset");
(*(UInt16*)(this.Offset + offset)) = value;
(*(ushort*)(this.Offset + offset)) = value;
}

/// <summary>
Expand All @@ -178,11 +178,11 @@ public void Write16(uint offset, UInt16 value)
/// <param name="offset">Data offset.</param>
/// <returns>UInt32 value.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if offset if bigger than memory block size.</exception>
public UInt32 Read32(uint offset)
public uint Read32(uint offset)
{
if (offset > Size)
throw new ArgumentOutOfRangeException("offset");
return *(UInt32*)(this.Offset + offset);
return *(uint*)(this.Offset + offset);
}

/// <summary>
Expand All @@ -191,11 +191,11 @@ public UInt32 Read32(uint offset)
/// <param name="offset">Data offset.</param>
/// <param name="value">Value to write.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if offset if bigger than memory block size or smaller than 0.</exception>
public void Write32(uint offset, UInt32 value)
public void Write32(uint offset, uint value)
{
if (offset < 0 || offset > Size)
throw new ArgumentOutOfRangeException("offset");
(*(UInt32*)(this.Offset + offset)) = value;
(*(uint*)(this.Offset + offset)) = value;
}
}
}
8 changes: 4 additions & 4 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ public void MoveUp(uint aDest, uint aSrc, uint aCount)
/// <param name="aBuffer">A buffer to write the data to.</param>
/// <exception cref="OverflowException">Thrown if aBuffer length in greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown on memory access violation.</exception>
public unsafe void Read8(Byte[] aBuffer)
public unsafe void Read8(byte[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
aBuffer[i] = (*(Byte*)(Base + i));
aBuffer[i] = (*(byte*)(Base + i));
}

/// <summary>
Expand All @@ -316,14 +316,14 @@ public unsafe void Read8(Byte[] aBuffer)
/// <param name="aBuffer">A buffer to be written to the memory block.</param>
/// <exception cref="OverflowException">Thrown if aBuffer length in greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown on memory access violation.</exception>
public unsafe void Write8(Byte[] aBuffer)
public unsafe void Write8(byte[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
(*(Byte*)(Base + i)) = aBuffer[i];
(*(byte*)(Base + i)) = aBuffer[i];
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Core_Plugs/Interop/Advapi32Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static unsafe int EventWriteTransfer_PInvoke(long aLong, ref object aEven
}

[PlugMethod(Signature = "System_Int32__Interop_Advapi32_RegEnumValue_Internal_Win32_SafeHandles_SafeRegistryHandle__System_Int32__System_Char_____System_Int32__System_IntPtr__System_Int32____System_Byte____System_Int32___")]
public static unsafe int RegEnumValue(object aSafeRegistryHandle, int aInt, Char[] aCharArray, ref int aInt2,
public static unsafe int RegEnumValue(object aSafeRegistryHandle, int aInt, char[] aCharArray, ref int aInt2,
IntPtr aIntPtr, int[] aIntArray, byte[] aByteArray, int[] aIntArray2)
{
throw new NotImplementedException();
Expand Down
Loading

0 comments on commit 76dceac

Please sign in to comment.