diff --git a/PrismAPI/Audio/AudioPlayer.cs b/PrismAPI/Audio/AudioPlayer.cs index ad915d11..cbe2ab4b 100644 --- a/PrismAPI/Audio/AudioPlayer.cs +++ b/PrismAPI/Audio/AudioPlayer.cs @@ -1,6 +1,6 @@ using Cosmos.HAL.Drivers.Audio; using Cosmos.System.Audio; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; namespace PrismAPI.Audio; diff --git a/PrismAPI/Filesystem/FilesystemManager.cs b/PrismAPI/Filesystem/FilesystemManager.cs index 372ffa1d..08c530db 100644 --- a/PrismAPI/Filesystem/FilesystemManager.cs +++ b/PrismAPI/Filesystem/FilesystemManager.cs @@ -1,7 +1,7 @@ using Cosmos.System.FileSystem.VFS; using Cosmos.System.FileSystem; using Cosmos.HAL.BlockDevice; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; namespace PrismAPI.Filesystem; diff --git a/PrismAPI/Graphics/Image.cs b/PrismAPI/Graphics/Image.cs index e444acbf..4b9a794a 100644 --- a/PrismAPI/Graphics/Image.cs +++ b/PrismAPI/Graphics/Image.cs @@ -1,4 +1,4 @@ -using PrismAPI.Processing.Compression; +using PrismAPI.Tools.Compression; using System.Runtime.InteropServices; using System.Text; diff --git a/PrismAPI/Graphics/Physics/Colisions/CubeColider.cs b/PrismAPI/Graphics/Physics/Colisions/CubeColider.cs new file mode 100644 index 00000000..ebb539c5 --- /dev/null +++ b/PrismAPI/Graphics/Physics/Colisions/CubeColider.cs @@ -0,0 +1,6 @@ +namespace PrismAPI.Graphics.Physics.Colisions; + +public class CubeColider +{ + // To-Do +} \ No newline at end of file diff --git a/PrismAPI/Graphics/Physics/Gravity.cs b/PrismAPI/Graphics/Physics/Gravity.cs new file mode 100644 index 00000000..1a4634f2 --- /dev/null +++ b/PrismAPI/Graphics/Physics/Gravity.cs @@ -0,0 +1,32 @@ +using System.Numerics; + +namespace PrismAPI.Graphics.Physics; + +public class Gravity +{ + public Gravity() + { + Velocity = Vector3.Zero; + } + + #region Methods + + public void Next() + { + Velocity += Force - new Vector3(Mass); + Velocity.Z -= 9.80665f; + + Speed = (Velocity.X + Velocity.Y + Velocity.Z) / 3; + } + + #endregion + + #region Fields + + public Vector3 Velocity; + public Vector3 Force; + public float Speed; + public float Mass; + + #endregion +} \ No newline at end of file diff --git a/PrismAPI/Graphics/Rasterizer/Engine.cs b/PrismAPI/Graphics/Rasterizer/Engine.cs index 8de6c84c..89b5782d 100644 --- a/PrismAPI/Graphics/Rasterizer/Engine.cs +++ b/PrismAPI/Graphics/Rasterizer/Engine.cs @@ -30,7 +30,6 @@ public Engine(ushort Width, ushort Height, float FOV) : base(Width, Height) Lights = new(); Objects = new(); Camera = new(FOV); - Gravity = 1f; Zoom = 0f; } @@ -56,13 +55,6 @@ public void Render() // Calculate Objects - Loops over all triangle in every mesh. foreach (Mesh M in Objects) { - // Check if the mesh has physics. - if (M.HasPhysics) - { - // Apply physics. - M.Step(Gravity, 1.0f); - } - // Create a rotation matrix for the mesh - Separate from camera rotation. Matrix4x4 Rotation = M.GetRotationMatrix(); @@ -102,7 +94,6 @@ public void Render() public List Objects; public Color SkyColor; public Camera Camera; - public float Gravity; public float Zoom; #endregion diff --git a/PrismAPI/Graphics/Rasterizer/Mesh.cs b/PrismAPI/Graphics/Rasterizer/Mesh.cs index 54a56df1..1b68722e 100644 --- a/PrismAPI/Graphics/Rasterizer/Mesh.cs +++ b/PrismAPI/Graphics/Rasterizer/Mesh.cs @@ -21,12 +21,6 @@ public Mesh() Triangles = new(); Position = Vector3.Zero; Rotation = Vector3.Zero; - Velocity = Vector3.Zero; - Force = Vector3.Zero; - - HasCollision = true; - HasPhysics = false; - Mass = 1f; } #endregion @@ -208,15 +202,6 @@ public void TestLogic(float ElapsedTime) Rotation.X += ElapsedTime; } - public void Step(float Gravity, float DT) - { - // Increment gravity. - Force.Y += Mass * Gravity; - Velocity.Y += Force.Y / Mass * DT; - Position.Y += Velocity.Y * DT; - Force = Vector3.Zero; - } - #endregion #region Fields @@ -225,12 +210,6 @@ public void Step(float Gravity, float DT) public List Triangles; public Vector3 Position; public Vector3 Rotation; - public Vector3 Velocity; - public Vector3 Force; - - public bool HasCollision; - public bool HasPhysics; - public float Mass; #endregion } \ No newline at end of file diff --git a/PrismAPI/Network/NetworkManager.cs b/PrismAPI/Network/NetworkManager.cs index 07dd5843..c8a74704 100644 --- a/PrismAPI/Network/NetworkManager.cs +++ b/PrismAPI/Network/NetworkManager.cs @@ -1,7 +1,7 @@ using Cosmos.System.Network.IPv4.UDP.DHCP; using Cosmos.System.Network.IPv4.TCP; using Cosmos.System.Network.IPv4; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; namespace PrismAPI.Network; diff --git a/PrismAPI/Runtime/Executable.cs b/PrismAPI/Runtime/Executable.cs index 75c5564b..f5ff9dd2 100644 --- a/PrismAPI/Runtime/Executable.cs +++ b/PrismAPI/Runtime/Executable.cs @@ -1,6 +1,7 @@ using PrismAPI.Filesystem.Formats.ELF.ELFProgramHeader; using PrismAPI.Filesystem.Formats.ELF.ELFHeader; using PrismAPI.Filesystem.Formats.ELF; +using PrismAPI.Runtime.SystemCall; namespace PrismAPI.Runtime; @@ -13,7 +14,7 @@ public unsafe class Executable public Executable() { Main = (delegate* unmanaged)0; - Permissions = PermissionLevel.User; + Permissions = AccessLevel.User; } #region Methods @@ -122,7 +123,7 @@ public static Executable FromBIN(byte[] Binary) #region Fields public delegate* unmanaged Main; - public PermissionLevel Permissions; + public AccessLevel Permissions; #endregion } \ No newline at end of file diff --git a/PrismAPI/Runtime/SSharp/Compiler.cs b/PrismAPI/Runtime/SSharp/Compiler.cs index 5c4f417c..86163db8 100644 --- a/PrismAPI/Runtime/SSharp/Compiler.cs +++ b/PrismAPI/Runtime/SSharp/Compiler.cs @@ -1,5 +1,6 @@ using PrismAPI.Runtime.SSharp.Structure; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; +using PrismAPI.Tools.Extentions; namespace PrismAPI.Runtime.SSharp; diff --git a/PrismAPI/Runtime/SSharp/Tokenizer.cs b/PrismAPI/Runtime/SSharp/Tokenizer.cs index a408900d..0426d397 100644 --- a/PrismAPI/Runtime/SSharp/Tokenizer.cs +++ b/PrismAPI/Runtime/SSharp/Tokenizer.cs @@ -1,5 +1,5 @@ using PrismAPI.Runtime.SSharp.Structure; -using PrismAPI.Tools; +using PrismAPI.Tools.Extentions; namespace PrismAPI.Runtime.SSharp; diff --git a/PrismAPI/Runtime/SShell/Scripts/Locker.cs b/PrismAPI/Runtime/SShell/Scripts/Locker.cs index a9b6b055..4e7b749e 100644 --- a/PrismAPI/Runtime/SShell/Scripts/Locker.cs +++ b/PrismAPI/Runtime/SShell/Scripts/Locker.cs @@ -1,4 +1,4 @@ -using PrismAPI.Processing; +using PrismAPI.Tools; namespace PrismAPI.Runtime.SShell.Scripts; diff --git a/PrismAPI/Runtime/SShell/Shell.cs b/PrismAPI/Runtime/SShell/Shell.cs index 2fa2fa12..dff178fa 100644 --- a/PrismAPI/Runtime/SShell/Shell.cs +++ b/PrismAPI/Runtime/SShell/Shell.cs @@ -1,7 +1,7 @@ using PrismAPI.Filesystem.Formats.ELF.ELFHeader; using PrismAPI.Runtime.SShell.Scripts; using PrismAPI.Runtime.SSharp; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; namespace PrismAPI.Runtime.SShell; diff --git a/PrismAPI/Runtime/PermissionLevel.cs b/PrismAPI/Runtime/SystemCall/AccessLevel.cs similarity index 90% rename from PrismAPI/Runtime/PermissionLevel.cs rename to PrismAPI/Runtime/SystemCall/AccessLevel.cs index 77bd5f91..6f74a309 100644 --- a/PrismAPI/Runtime/PermissionLevel.cs +++ b/PrismAPI/Runtime/SystemCall/AccessLevel.cs @@ -1,6 +1,6 @@ -namespace PrismAPI.Runtime; +namespace PrismAPI.Runtime.SystemCall; -public enum PermissionLevel +public enum AccessLevel { /// /// Full access to all files and features. No access to full system memory. diff --git a/PrismAPI/Runtime/SystemCalls.cs b/PrismAPI/Runtime/SystemCall/Handler.cs similarity index 75% rename from PrismAPI/Runtime/SystemCalls.cs rename to PrismAPI/Runtime/SystemCall/Handler.cs index 01dd0d76..8a8186a2 100644 --- a/PrismAPI/Runtime/SystemCalls.cs +++ b/PrismAPI/Runtime/SystemCall/Handler.cs @@ -1,11 +1,11 @@ using System.Runtime.InteropServices; -using PrismAPI.Tools; +using PrismAPI.Tools.Diagnostics; using Cosmos.Core; using TinyMath; -namespace PrismAPI.Runtime; +namespace PrismAPI.Runtime.SystemCall; -public static unsafe class SystemCalls +public static unsafe class Handler { #region Methods @@ -35,24 +35,24 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal // can just do the action anyway due to them being core apps, it will be good so // the user knows it is going to be doing special access. - switch ((SystemCallKind)Context.EAX) + switch ((Kind)Context.EAX) { #region Console - case SystemCallKind.System_Console_WriteLine_string: + case Kind.System_Console_WriteLine_string: Console.WriteLine(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_Console_Write_string: + case Kind.System_Console_Write_string: Console.Write(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_Console_Clear: + case Kind.System_Console_Clear: Console.Clear(); break; - case SystemCallKind.System_Console_SetColor: + case Kind.System_Console_SetColor: Console.ForegroundColor = (ConsoleColor)Context.EBX; Console.BackgroundColor = (ConsoleColor)Context.ECX; break; - case SystemCallKind.System_Console_ResetColor: + case Kind.System_Console_ResetColor: Console.ResetColor(); break; @@ -60,50 +60,50 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal #region Memory - case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Realloc: // Realloc + case Kind.System_Runtime_InteropServices_NativeMemory_Realloc: // Realloc Context.EAX = (uint)NativeMemory.Realloc((byte*)Context.EBX, Context.EDX); break; - case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Alloc: // Alloc + case Kind.System_Runtime_InteropServices_NativeMemory_Alloc: // Alloc Context.EAX = (uint)NativeMemory.Alloc(Context.EBX); break; - case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Free: // Free + case Kind.System_Runtime_InteropServices_NativeMemory_Free: // Free NativeMemory.Free((uint*)Context.EBX); break; - case SystemCallKind.System_Buffer_MemoryCopy64: // Copy64 + case Kind.System_Buffer_MemoryCopy64: // Copy64 System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 8, Context.EDX * 8); break; - case SystemCallKind.System_Buffer_MemoryCopy32: // Copy32 + case Kind.System_Buffer_MemoryCopy32: // Copy32 System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 4, Context.EDX * 4); break; - case SystemCallKind.System_Buffer_MemoryCopy16: // Copy16 + case Kind.System_Buffer_MemoryCopy16: // Copy16 System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 2, Context.EDX * 2); break; - case SystemCallKind.System_Buffer_MemoryCopy8: // Copy8 + case Kind.System_Buffer_MemoryCopy8: // Copy8 System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX, Context.EDX); break; - case SystemCallKind.Core_Fill64: // Fill64 + case Kind.Core_Fill64: // Fill64 for (int I = 0; I < (int)(int*)Context.EDX; I++) { *((long**)Context.EBX)[I] = (long)(long*)Context.ECX; } break; - case SystemCallKind.Core_Fill32: // Fill32 + case Kind.Core_Fill32: // Fill32 MemoryOperations.Fill((uint*)Context.EBX, Context.ECX, (int)(int*)Context.EDX); break; - case SystemCallKind.Core_Fill16: // Fill16 + case Kind.Core_Fill16: // Fill16 MemoryOperations.Fill((ushort*)Context.EBX, (ushort)(ushort*)Context.ECX, (int)(int*)Context.EDX); break; - case SystemCallKind.Core_Fill8: // Fill8 + case Kind.Core_Fill8: // Fill8 MemoryOperations.Fill((byte*)Context.EBX, (byte)(byte*)Context.ECX, (int)(int*)Context.EDX); break; @@ -111,7 +111,7 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal #region Files - case SystemCallKind.System_IO_File_ReadAllBytes_string: + case Kind.System_IO_File_ReadAllBytes_string: fixed (byte* PTR = File.ReadAllBytes(GetString((char*)Context.EBX))) { Context.EAX = (uint)new FileInfo(GetString((char*)Context.EBX)).Length; @@ -119,7 +119,7 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal } break; - case SystemCallKind.System_IO_File_WriteeAllBytes_string_bytes: + case Kind.System_IO_File_WriteeAllBytes_string_bytes: byte[] Buffer = new byte[Context.EDX]; fixed (byte* PTR = Buffer) { @@ -128,27 +128,27 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal File.WriteAllBytes(GetString((char*)Context.EBX), Buffer); break; - case SystemCallKind.System_IO_Directory_Delete: + case Kind.System_IO_Directory_Delete: Directory.Delete(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_IO_File_Delete: + case Kind.System_IO_File_Delete: File.Delete(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_IO_Directory_Create: + case Kind.System_IO_Directory_Create: Directory.CreateDirectory(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_IO_File_Create: + case Kind.System_IO_File_Create: File.Create(GetString((char*)Context.EBX)); break; - case SystemCallKind.System_IO_Directory_Exists: + case Kind.System_IO_Directory_Exists: Context.EAX = (uint)(Directory.Exists(GetString((char*)Context.EBX)) ? 1 : 0); break; - case SystemCallKind.System_IO_File_Exists: + case Kind.System_IO_File_Exists: Context.EAX = (uint)(File.Exists(GetString((char*)Context.EBX)) ? 1 : 0); break; @@ -156,7 +156,7 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal #region Core - case SystemCallKind.Core_Set_Permissions: + case Kind.Core_Set_Permissions: // If CallingBinary.Permissions == Kernel // CallingBinary.Permissions = Requested permissions // Else ask user permission @@ -164,10 +164,10 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal // CallingBinary.Permissions = Requested permissions // Else, do nothing and return. break; - case SystemCallKind.Core_Get_Permissions: + case Kind.Core_Get_Permissions: // Return CallingBinary.Permissions break; - case SystemCallKind.Core_Math_Eval: + case Kind.Core_Math_Eval: fixed (char* C = SyntaxParser.Evaluate(GetString((char*)Context.EBX)).ToString()) { Context.EAX = (uint)C; diff --git a/PrismAPI/Runtime/SystemCallKind.cs b/PrismAPI/Runtime/SystemCall/Kind.cs similarity index 92% rename from PrismAPI/Runtime/SystemCallKind.cs rename to PrismAPI/Runtime/SystemCall/Kind.cs index 898f8df8..5c1cab5a 100644 --- a/PrismAPI/Runtime/SystemCallKind.cs +++ b/PrismAPI/Runtime/SystemCall/Kind.cs @@ -1,6 +1,6 @@ -namespace PrismAPI.Runtime; +namespace PrismAPI.Runtime.SystemCall; -public enum SystemCallKind : uint +public enum Kind : uint { System_Console_WriteLine_string, System_Console_Write_string, diff --git a/PrismAPI/Tools/ByteFormatter.cs b/PrismAPI/Tools/ByteFormatter.cs deleted file mode 100644 index 4e4e0754..00000000 --- a/PrismAPI/Tools/ByteFormatter.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace PrismAPI.Tools; - -/// -/// The class. Used to format byte counts into the requested format. -/// -public static class ByteFormatter -{ - #region Constants - - public const ulong BytesPerTerrabye = BytesPerGigabyte * 1000; - public const ulong BytesPerGigabyte = BytesPerMegabyte * 1000; - public const ulong BytesPerMegabyte = BytesPerKilobyte * 1000; - public const ulong BytesPerKilobyte = 1024; - - #endregion - - #region Methods - - public static ulong GetTerabytes(ulong Bytes) => Bytes / BytesPerTerrabye; - - public static ulong GetGigabytes(ulong Bytes) => Bytes / BytesPerGigabyte; - - public static ulong GetMegaBytes(ulong Bytes) => Bytes / BytesPerMegabyte; - - public static ulong GetKilobytes(ulong Bytes) => Bytes / BytesPerKilobyte; - - #endregion -} \ No newline at end of file diff --git a/PrismAPI/Processing/Compression/DeflateStream.cs b/PrismAPI/Tools/Compression/DeflateStream.cs similarity index 99% rename from PrismAPI/Processing/Compression/DeflateStream.cs rename to PrismAPI/Tools/Compression/DeflateStream.cs index 2e64aa20..99679d89 100644 --- a/PrismAPI/Processing/Compression/DeflateStream.cs +++ b/PrismAPI/Tools/Compression/DeflateStream.cs @@ -1,4 +1,4 @@ -namespace PrismAPI.Processing.Compression; +namespace PrismAPI.Tools.Compression; /// /// public domain zlib decode diff --git a/PrismAPI/Processing/Compression/LZW.cs b/PrismAPI/Tools/Compression/LZW.cs similarity index 98% rename from PrismAPI/Processing/Compression/LZW.cs rename to PrismAPI/Tools/Compression/LZW.cs index 333395c1..f2405338 100644 --- a/PrismAPI/Processing/Compression/LZW.cs +++ b/PrismAPI/Tools/Compression/LZW.cs @@ -1,6 +1,6 @@ using System.Text; -namespace PrismAPI.Processing.Compression; +namespace PrismAPI.Tools.Compression; /// /// LZW (De)compression class. diff --git a/PrismAPI/Processing/Crypt.cs b/PrismAPI/Tools/Crypt.cs similarity index 55% rename from PrismAPI/Processing/Crypt.cs rename to PrismAPI/Tools/Crypt.cs index 95745210..1f5a42f4 100644 --- a/PrismAPI/Processing/Crypt.cs +++ b/PrismAPI/Tools/Crypt.cs @@ -1,4 +1,4 @@ -namespace PrismAPI.Processing; +namespace PrismAPI.Tools; /// /// The class, used for binary security. @@ -6,47 +6,47 @@ namespace PrismAPI.Processing; /// public static class Crypt { - /// - /// Encrypts data using an char array as a key. + /// + /// Encrypts data using an char array as a key. /// Chars in C# can use up to 2 bytes per character. - /// - /// The Key to encrypt with. - /// The Input data to encrypt. - /// Encrypted data. - public static byte[] Encrypt(char[] Key, byte[] Input) - { - byte[] Encrypted = new byte[Input.Length]; + /// + /// The Key to encrypt with. + /// The Input data to encrypt. + /// Encrypted data. + public static byte[] Encrypt(char[] Key, byte[] Input) + { + byte[] Encrypted = new byte[Input.Length]; // Loop over all bytes to cypher/encrypt. - for (int I = 0; I < Input.Length; I++) - { + for (int I = 0; I < Input.Length; I++) + { // Offset the byte by the value of the key, and modulate the key. - Encrypted[I] = (byte)((Input[I] + Key[I % Key.Length]) & 255); - } + Encrypted[I] = (byte)(Input[I] + Key[I % Key.Length] & 255); + } - return Encrypted; - } + return Encrypted; + } - /// - /// Decrypts data using an int array as a key. - /// Chars in C# can use up to 2 bytes per character. - /// - /// The Key to decrypt with. - /// The Input data to decrypt. - /// decrypted data. - public static byte[] Decrypt(char[] Key, byte[] Input) + /// + /// Decrypts data using an int array as a key. + /// Chars in C# can use up to 2 bytes per character. + /// + /// The Key to decrypt with. + /// The Input data to decrypt. + /// decrypted data. + public static byte[] Decrypt(char[] Key, byte[] Input) { - byte[] Decrypted = new byte[Input.Length]; + byte[] Decrypted = new byte[Input.Length]; - // Loop over all bytes to decypher/decrypt. - for (int I = 0; I < Input.Length; I++) - { - // Offset the byte by the value of the key, and modulate the key. - Decrypted[I] = (byte)((Input[I] - Key[I % Key.Length]) & 255); - } + // Loop over all bytes to decypher/decrypt. + for (int I = 0; I < Input.Length; I++) + { + // Offset the byte by the value of the key, and modulate the key. + Decrypted[I] = (byte)(Input[I] - Key[I % Key.Length] & 255); + } - return Decrypted; - } + return Decrypted; + } /// /// Encrypts data using a string as a key. diff --git a/PrismAPI/Tools/Debugger.cs b/PrismAPI/Tools/Debugger.cs deleted file mode 100644 index e3b9cf5f..00000000 --- a/PrismAPI/Tools/Debugger.cs +++ /dev/null @@ -1,110 +0,0 @@ -namespace PrismAPI.Tools; - -/// -/// Debugger class, used for logging errors. -/// -public class Debugger -{ - /// - /// Creates a new instance of the class. - /// - /// Category to print as (e.g. Kernel, Graphics... etc) - public Debugger(string Category) - { - this.Category = Category; - } - - #region Methods - - /// - /// Logs a full info message to the console. - /// - /// Message details. - /// The severity of the message. - public void WriteFull(string Message, Severity Severity) - { - // Print out the category - Console.Write($"{Category} "); - - // Switch to the correct colors. - switch (Severity) - { - case Severity.Success: - Console.ForegroundColor = ConsoleColor.Green; - break; - case Severity.Warn: - Console.ForegroundColor = ConsoleColor.Yellow; - break; - case Severity.Fail: - Console.ForegroundColor = ConsoleColor.Red; - break; - case Severity.Info: - Console.ForegroundColor = ConsoleColor.Cyan; - break; - } - - // Write status, then reset. - Console.Write('>'); - Console.ResetColor(); - - // Print out the main message. - Console.WriteLine($" {Message}"); - } - - /// - /// Log an partial message to the console. - /// Use to mark it's status. - /// - /// Message to display. - public void WritePartial(string Message) - { - // Print out the category - Console.Write($"{Category} > {Message}"); - } - - /// - /// Finalizes a log status, use after . - /// - /// The severity to give the message. - public void Finalize(Severity Severity) - { - // Offset the position to reset the '>' character. - Console.CursorLeft = Category.Length + 1; - - // Switch to the correct colors. - switch (Severity) - { - case Severity.Success: - Console.ForegroundColor = ConsoleColor.Green; - break; - case Severity.Warn: - Console.ForegroundColor = ConsoleColor.Yellow; - break; - case Severity.Fail: - Console.ForegroundColor = ConsoleColor.Red; - break; - case Severity.Info: - Console.ForegroundColor = ConsoleColor.Cyan; - break; - } - - // Re-write the value and reset the color. - Console.Write('>'); - Console.ResetColor(); - - // Increment the console line. - Console.CursorLeft = 0; - Console.CursorTop++; - } - - #endregion - - #region Fields - - /// - /// Category marker for the debugger instance. - /// - public string Category; - - #endregion -} \ No newline at end of file diff --git a/PrismAPI/Tools/Diagnostics/Debugger.cs b/PrismAPI/Tools/Diagnostics/Debugger.cs new file mode 100644 index 00000000..d54bb7d6 --- /dev/null +++ b/PrismAPI/Tools/Diagnostics/Debugger.cs @@ -0,0 +1,110 @@ +namespace PrismAPI.Tools.Diagnostics; + +/// +/// Debugger class, used for logging errors. +/// +public class Debugger +{ + /// + /// Creates a new instance of the class. + /// + /// Category to print as (e.g. Kernel, Graphics... etc) + public Debugger(string Category) + { + this.Category = Category; + } + + #region Methods + + /// + /// Logs a full info message to the console. + /// + /// Message details. + /// The severity of the message. + public void WriteFull(string Message, Severity Severity) + { + // Print out the category + Console.Write($"{Category} "); + + // Switch to the correct colors. + switch (Severity) + { + case Severity.Success: + Console.ForegroundColor = ConsoleColor.Green; + break; + case Severity.Warn: + Console.ForegroundColor = ConsoleColor.Yellow; + break; + case Severity.Fail: + Console.ForegroundColor = ConsoleColor.Red; + break; + case Severity.Info: + Console.ForegroundColor = ConsoleColor.Cyan; + break; + } + + // Write status, then reset. + Console.Write('>'); + Console.ResetColor(); + + // Print out the main message. + Console.WriteLine($" {Message}"); + } + + /// + /// Log an partial message to the console. + /// Use to mark it's status. + /// + /// Message to display. + public void WritePartial(string Message) + { + // Print out the category + Console.Write($"{Category} > {Message}"); + } + + /// + /// Finalizes a log status, use after . + /// + /// The severity to give the message. + public void Finalize(Severity Severity) + { + // Offset the position to reset the '>' character. + Console.CursorLeft = Category.Length + 1; + + // Switch to the correct colors. + switch (Severity) + { + case Severity.Success: + Console.ForegroundColor = ConsoleColor.Green; + break; + case Severity.Warn: + Console.ForegroundColor = ConsoleColor.Yellow; + break; + case Severity.Fail: + Console.ForegroundColor = ConsoleColor.Red; + break; + case Severity.Info: + Console.ForegroundColor = ConsoleColor.Cyan; + break; + } + + // Re-write the value and reset the color. + Console.Write('>'); + Console.ResetColor(); + + // Increment the console line. + Console.CursorLeft = 0; + Console.CursorTop++; + } + + #endregion + + #region Fields + + /// + /// Category marker for the debugger instance. + /// + public string Category; + + #endregion +} \ No newline at end of file diff --git a/PrismAPI/Tools/Severity.cs b/PrismAPI/Tools/Diagnostics/Severity.cs similarity index 55% rename from PrismAPI/Tools/Severity.cs rename to PrismAPI/Tools/Diagnostics/Severity.cs index 8baeb700..0cd32686 100644 --- a/PrismAPI/Tools/Severity.cs +++ b/PrismAPI/Tools/Diagnostics/Severity.cs @@ -1,12 +1,12 @@ -namespace PrismAPI.Tools; +namespace PrismAPI.Tools.Diagnostics; /// /// The severity enum used to define error levels. /// public enum Severity { - Success, - Warn, - Fail, - Info, + Success, + Warn, + Fail, + Info, } \ No newline at end of file diff --git a/PrismAPI/Tools/Extentions/KeyboardEx.cs b/PrismAPI/Tools/Extentions/KeyboardEx.cs new file mode 100644 index 00000000..20de8d68 --- /dev/null +++ b/PrismAPI/Tools/Extentions/KeyboardEx.cs @@ -0,0 +1,77 @@ +using Cosmos.System; + +namespace PrismAPI.Tools.Extentions; + +/// +/// Keyboard conversion class. +/// +public static class KeyboardEx +{ + /// + /// Initializes the KeyboardEx class uppon access. + /// + static KeyboardEx() + { + // Initialize callback list. + Callbacks = new(); + + // Create timer to call every 150 MS. + Timer T = new((O) => + { + if (TryReadKey(out ConsoleKeyInfo Key)) + { + for (int I = 0; I < Callbacks.Count; I++) + { + Callbacks[I].Invoke(Key); + } + } + }, null, 150, 0); + } + + #region Methods + + /// + /// Registers a new callback to an event to be fired whenever a key is pressed. + /// + /// Action to call uppon a key press. + public static void RegisterCallback(Action CallBack) + { + Callbacks.Add(CallBack); + } + + /// + /// Attempts to read a key, returns true if a key is pressed. + /// + /// Key read, if key is available. + /// True when key is read. + public static bool TryReadKey(out ConsoleKeyInfo Key) + { + if (KeyboardManager.TryReadKey(out var KeyX)) + { + Key = new(KeyX.KeyChar, KeyX.Key.ToConsoleKey(), KeyX.Modifiers == ConsoleModifiers.Shift, KeyX.Modifiers == ConsoleModifiers.Alt, KeyX.Modifiers == ConsoleModifiers.Control); + return true; + } + + Key = default; + return false; + } + + /// + /// A non-blocking key read method. + /// + /// The currently pressed key. + public static ConsoleKeyInfo ReadKey() + { + ConsoleKeyInfo Key; + while (!TryReadKey(out Key)) { } + return Key; + } + + #endregion + + #region Fields + + private static readonly List> Callbacks; + + #endregion +} \ No newline at end of file diff --git a/PrismAPI/Tools/Extentions/MouseEx.cs b/PrismAPI/Tools/Extentions/MouseEx.cs new file mode 100644 index 00000000..410bcb6e --- /dev/null +++ b/PrismAPI/Tools/Extentions/MouseEx.cs @@ -0,0 +1,44 @@ +using Cosmos.System; + +namespace PrismAPI.Tools.Extentions; + +/// +/// A basic mouse extention class, used to detect extra mouse information. +/// +public static class MouseEx +{ + /// + /// A method to check if the mouse is within the given coordinates, + /// + /// The X position to check. + /// The Y position to check. + /// The Horizontal size to check. + /// The Vertical size to check. + /// True if the mouse is within the coordinates, Otherwise false. + public static bool IsMouseWithin(int X, int Y, ushort Width, ushort Height) + { + return + MouseManager.X >= X && MouseManager.X <= X + Width && + MouseManager.Y >= Y && MouseManager.Y <= Y + Height; + } + + /// + /// Checks if the mouse has any buttons pressed. + /// + /// True if any buttons are pressed, Otherwise False. + public static bool IsClickPressed() + { + return MouseManager.MouseState != MouseState.None; + } + + /// + /// A method to check if a click event is ready to be fired. + /// + /// True if a control's click event is ready to fire, Otherwise False. + public static bool IsClickReady() + { + return + MouseManager.MouseState == MouseState.None && + MouseManager.LastMouseState == MouseState.Left; + } +} \ No newline at end of file diff --git a/PrismAPI/Tools/StringEx.cs b/PrismAPI/Tools/Extentions/StringEx.cs similarity index 59% rename from PrismAPI/Tools/StringEx.cs rename to PrismAPI/Tools/Extentions/StringEx.cs index 12ff6b82..fb6e4622 100644 --- a/PrismAPI/Tools/StringEx.cs +++ b/PrismAPI/Tools/Extentions/StringEx.cs @@ -1,7 +1,26 @@ -namespace PrismAPI.Tools; +namespace PrismAPI.Tools.Extentions; public static unsafe class StringEx { + #region Constants + + public const ulong BytesPerTerrabye = BytesPerGigabyte * 1000; + public const ulong BytesPerGigabyte = BytesPerMegabyte * 1000; + public const ulong BytesPerMegabyte = BytesPerKilobyte * 1000; + public const ulong BytesPerKilobyte = 1024; + + #endregion + + #region Methods + + public static ulong GetTerabytes(ulong Bytes) => Bytes / BytesPerTerrabye; + + public static ulong GetGigabytes(ulong Bytes) => Bytes / BytesPerGigabyte; + + public static ulong GetMegaBytes(ulong Bytes) => Bytes / BytesPerMegabyte; + + public static ulong GetKilobytes(ulong Bytes) => Bytes / BytesPerKilobyte; + /// /// Get the number of instances that the char 'C' is found in the string. /// @@ -31,4 +50,6 @@ public static (int Line, int Column) GetLineColumn(string S, int Index) { return (NumberOf(S[Index..], '\n') + 1, Index - S.LastIndexOf('\n', Index)); } + + #endregion } \ No newline at end of file diff --git a/PrismAPI/Tools/KeyboardEx.cs b/PrismAPI/Tools/KeyboardEx.cs deleted file mode 100644 index 4fa3318d..00000000 --- a/PrismAPI/Tools/KeyboardEx.cs +++ /dev/null @@ -1,77 +0,0 @@ -using Cosmos.System; - -namespace PrismAPI.Tools; - -/// -/// Keyboard conversion class. -/// -public static class KeyboardEx -{ - /// - /// Initializes the KeyboardEx class uppon access. - /// - static KeyboardEx() - { - // Initialize callback list. - Callbacks = new(); - - // Create timer to call every 150 MS. - Timer T = new((O) => - { - if (TryReadKey(out ConsoleKeyInfo Key)) - { - for (int I = 0; I < Callbacks.Count; I++) - { - Callbacks[I].Invoke(Key); - } - } - }, null, 150, 0); - } - - #region Methods - - /// - /// Registers a new callback to an event to be fired whenever a key is pressed. - /// - /// Action to call uppon a key press. - public static void RegisterCallback(Action CallBack) - { - Callbacks.Add(CallBack); - } - - /// - /// Attempts to read a key, returns true if a key is pressed. - /// - /// Key read, if key is available. - /// True when key is read. - public static bool TryReadKey(out ConsoleKeyInfo Key) - { - if (KeyboardManager.TryReadKey(out var KeyX)) - { - Key = new(KeyX.KeyChar, ConsoleKeyExExtensions.ToConsoleKey(KeyX.Key), KeyX.Modifiers == ConsoleModifiers.Shift, KeyX.Modifiers == ConsoleModifiers.Alt, KeyX.Modifiers == ConsoleModifiers.Control); - return true; - } - - Key = default; - return false; - } - - /// - /// A non-blocking key read method. - /// - /// The currently pressed key. - public static ConsoleKeyInfo ReadKey() - { - ConsoleKeyInfo Key; - while (!TryReadKey(out Key)) { } - return Key; - } - - #endregion - - #region Fields - - private static readonly List> Callbacks; - - #endregion -} \ No newline at end of file diff --git a/PrismAPI/Tools/MouseEx.cs b/PrismAPI/Tools/MouseEx.cs deleted file mode 100644 index c88008c3..00000000 --- a/PrismAPI/Tools/MouseEx.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Cosmos.System; - -namespace PrismAPI.Tools; - -/// -/// A basic mouse extention class, used to detect extra mouse information. -/// -public static class MouseEx -{ - /// - /// A method to check if the mouse is within the given coordinates, - /// - /// The X position to check. - /// The Y position to check. - /// The Horizontal size to check. - /// The Vertical size to check. - /// True if the mouse is within the coordinates, Otherwise false. - public static bool IsMouseWithin(int X, int Y, ushort Width, ushort Height) - { - return - MouseManager.X >= X && MouseManager.X <= X + Width && - MouseManager.Y >= Y && MouseManager.Y <= Y + Height; - } - - /// - /// Checks if the mouse has any buttons pressed. - /// - /// True if any buttons are pressed, Otherwise False. - public static bool IsClickPressed() - { - return MouseManager.MouseState != MouseState.None; - } - - /// - /// A method to check if a click event is ready to be fired. - /// - /// True if a control's click event is ready to fire, Otherwise False. - public static bool IsClickReady() - { - return - MouseManager.MouseState == MouseState.None && - MouseManager.LastMouseState == MouseState.Left; - } -} \ No newline at end of file diff --git a/PrismOS/Program.cs b/PrismOS/Program.cs index 0bfd0825..c1386c6c 100644 --- a/PrismOS/Program.cs +++ b/PrismOS/Program.cs @@ -1,9 +1,9 @@ -using PrismAPI.Runtime.SShell; +using PrismAPI.Runtime.SystemCall; +using PrismAPI.Tools.Extentions; +using PrismAPI.Runtime.SShell; using PrismAPI.Filesystem; using PrismAPI.Network; -using PrismAPI.Runtime; using PrismAPI.Audio; -using PrismAPI.Tools; namespace PrismOS; @@ -31,7 +31,7 @@ protected override void BeforeRun() // Initialize system services. FilesystemManager.Init(); NetworkManager.Init(); - SystemCalls.Init(); + Handler.Init(); AudioPlayer.Play(Media.Startup); } diff --git a/PrismOS/Tests.cs b/PrismOS/Tests.cs index 7c64de6b..603329ad 100644 --- a/PrismOS/Tests.cs +++ b/PrismOS/Tests.cs @@ -1,9 +1,9 @@ using PrismAPI.Graphics.Rasterizer; +using PrismAPI.Tools.Extentions; using PrismAPI.Hardware.GPU; using PrismAPI.UI.Controls; using Cosmos.Core.Memory; using PrismAPI.Graphics; -using PrismAPI.Tools; using Cosmos.System; using Cosmos.Core; using PrismAPI.UI; @@ -50,7 +50,7 @@ public static void TestGraphics() Engine.Objects[^1].TestLogic(0.01f); Engine.Render(); - string Info = $"{Canvas.GetFPS()} FPS\n{Canvas.GetName()}\n{ByteFormatter.GetMegaBytes(GCImplementation.GetUsedRAM())} MB"; + string Info = $"{Canvas.GetFPS()} FPS\n{Canvas.GetName()}\n{StringEx.GetMegaBytes(GCImplementation.GetUsedRAM())} MB"; Canvas.Clear(); Canvas.DrawImage(150, 150, Buffer, false); @@ -61,7 +61,7 @@ public static void TestGraphics() GCImplementation.Free(Info); WindowManager.Update(Canvas); Canvas.Update(); - //Heap.Collect(); + Heap.Collect(); } } } \ No newline at end of file