From a5a1a7d23bad93c676671ca3f9c46956302650e1 Mon Sep 17 00:00:00 2001 From: Evan Lawrence Date: Fri, 13 May 2022 16:21:43 -0700 Subject: [PATCH] minor changes --- PrismOS/Kernel.cs | 224 +++++++++--------- PrismOS/Libraries/Graphics/Canvas.cs | 1 + .../Graphics/GUI/Elements/Element.cs | 2 +- PrismOS/Libraries/Numerics/Math.cs | 1 + PrismOS/Text/Tests.txt | 78 +++--- 5 files changed, 149 insertions(+), 157 deletions(-) diff --git a/PrismOS/Kernel.cs b/PrismOS/Kernel.cs index 7651f1b1..32b35e68 100644 --- a/PrismOS/Kernel.cs +++ b/PrismOS/Kernel.cs @@ -23,141 +23,137 @@ public unsafe class Kernel : Cosmos.System.Kernel (() => { VFS.Initialize(true); }, "Initilizing VFS..."), (() => { VFSManager.RegisterVFS(VFS); }, "Registering VFS..."), (() => { new DHCPClient().SendDiscoverPacket(); DNS = new(); }, "Starting network services..."), - (() => + (() => { Booting = false; }, "Updating boot status..."), + }; + public static WindowManager WM = new() + { + Windows = new() { - WM = new() + new() { - Windows = new() + X = 0, + Y = Canvas.Height - 32, + Width = Canvas.Width, + Height = 32, + Draggable = false, + TitleVisible = false, + Elements = new() { - new() + // Task bar and start button + new Panel() { X = 0, - Y = Canvas.Height - 32, - Width = Canvas.Width, + Y = -300, + Width = 150, + Height = 300, + Color = new(Color.Black, 128), + Visible = false, + }, + new Button() + { + X = 0, + Y = 0, + Width = 64, Height = 32, - Draggable = false, - TitleVisible = false, - Elements = new() - { - // Task bar and start button - new Panel() - { - X = 0, - Y = -300, - Width = 150, - Height = 300, - Color = new(Color.Black, 128), - Visible = false, - }, - new Button() - { - X = 0, - Y = 0, - Width = 64, - Height = 32, - Text = "Start", - OnClick = (ref Element E, ref Window Parent) => { Parent.Elements[0].Visible = !Parent.Elements[0].Visible; }, - }, + Text = "Start", + OnClick = (ref Element E, ref Window Parent) => { Parent.Elements[0].Visible = !Parent.Elements[0].Visible; }, + }, - // App buttons - new Button() + // App buttons + new Button() + { + X = 70, + Y = 0, + Width = 32, + Height = 32, + Text = "C", + OnClick = (ref Element E, ref Window Parent) => + { + WM.Windows.Add(new() { - X = 70, - Y = 0, - Width = 32, - Height = 32, - Text = "C", - OnClick = (ref Element E, ref Window Parent) => + X = 200, + Y = 50, + Width = 300, + Height = 150, + Text = "Clock", + Elements = new() { - WM.Windows.Add(new() + new Clock() { - X = 200, - Y = 50, - Width = 300, - Height = 150, - Text = "Clock", - Elements = new() - { - new Clock() - { - X = 150, - Y = 75, - Radius = 50, - OnUpdate = (ref Element E, ref Window Parent) => { ((Clock)E).Time = DateTime.Now; }, - }, - new Button() - { - X = 285, - Y = -15, - Width = 15, - Height = 15, - Text = "X", - OnClick = (ref Element E, ref Window Parent) => { WM.Windows.Remove(Parent); }, - }, - }, - }); + X = 150, + Y = 75, + Radius = 50, + OnUpdate = (ref Element E, ref Window Parent) => { ((Clock)E).Time = DateTime.Now; }, + }, + new Button() + { + X = 285, + Y = -15, + Width = 15, + Height = 15, + Text = "X", + OnClick = (ref Element E, ref Window Parent) => { WM.Windows.Remove(Parent); }, + }, }, - }, - new Button() + }); + }, + }, + new Button() + { + X = 108, + Y = 0, + Width = 32, + Height = 32, + Text = "TT", + OnClick = (ref Element E, ref Window Parent) => + { + WM.Windows.Add(new() { - X = 108, - Y = 0, - Width = 32, - Height = 32, - Text = "TT", - OnClick = (ref Element E, ref Window Parent) => + X = 200, + Y = 50, + Width = 300, + Height = 150, + Text = "typing test", + Elements = new() { - WM.Windows.Add(new() + new Textbox() { - X = 200, - Y = 50, + X = 0, + Y = 150 - 12, Width = 300, - Height = 150, - Text = "typing test", - Elements = new() + Height = 12, + OnUpdate = (ref Element E, ref Window Parent) => { - new Textbox() - { - X = 0, - Y = 150 - 12, - Width = 300, - Height = 12, - OnUpdate = (ref Element E, ref Window Parent) => - { - if (KeyboardManager.TryReadKey(out var Key) && Key.Key == ConsoleKeyEx.Enter) - { - ((Label)Parent.Elements[1]).Text += '\n' + ((Textbox)E).Text; - } - } - }, - new Label() - { - X = 0, - Y = 0, - Color = Color.White, - Text = "", - }, - new Button() + if (KeyboardManager.TryReadKey(out var Key) && Key.Key == ConsoleKeyEx.Enter) { - X = 285, - Y = -15, - Width = 15, - Height = 15, - Text = "X", - OnClick = (ref Element E, ref Window Parent) => { WM.Windows.Remove(Parent); }, - }, - }, - }); + ((Label)Parent.Elements[1]).Text += '\n' + ((Textbox)E).Text; + } + } + }, + new Label() + { + X = 0, + Y = 0, + Color = Color.White, + Text = "", + }, + new Button() + { + X = 285, + Y = -15, + Width = 15, + Height = 15, + Text = "X", + OnClick = (ref Element E, ref Window Parent) => { WM.Windows.Remove(Parent); }, + }, }, - }, + }); }, - } + }, }, - }; - }, "Starting desktop..."), - (() => { Booting = false; }, "Updating boot status..."), + } + }, }; - public static WindowManager WM; public static CosmosVFS VFS; public static DnsClient DNS; public static Canvas Canvas; diff --git a/PrismOS/Libraries/Graphics/Canvas.cs b/PrismOS/Libraries/Graphics/Canvas.cs index 701c293f..9db0a28a 100644 --- a/PrismOS/Libraries/Graphics/Canvas.cs +++ b/PrismOS/Libraries/Graphics/Canvas.cs @@ -389,6 +389,7 @@ public void Update(bool ShowMouse) DrawImage((int)Mouse.X, (int)Mouse.Y, Cursor); } + //MemoryOperations.Copy(*(uint**)0xE0000000, GCImplementation.GetPointer(Buffer), Width * Height * 4); Global.BaseIOGroups.VBE.LinearFrameBuffer.Copy((int[])(object)Buffer); MemoryOperations.Copy((int[])(object)Buffer, (int[])(object)Wallpaper.Buffer); } diff --git a/PrismOS/Libraries/Graphics/GUI/Elements/Element.cs b/PrismOS/Libraries/Graphics/GUI/Elements/Element.cs index c86bbe29..5cc13301 100644 --- a/PrismOS/Libraries/Graphics/GUI/Elements/Element.cs +++ b/PrismOS/Libraries/Graphics/GUI/Elements/Element.cs @@ -9,6 +9,6 @@ public abstract class Element public Event OnClick, OnUpdate; public bool Clicked, Hovering, Visible = true; - public abstract void Update(Canvas canvas, Window Parent); + public abstract void Update(Canvas Canvas, Window Parent); } } \ No newline at end of file diff --git a/PrismOS/Libraries/Numerics/Math.cs b/PrismOS/Libraries/Numerics/Math.cs index aac17099..06a43c61 100644 --- a/PrismOS/Libraries/Numerics/Math.cs +++ b/PrismOS/Libraries/Numerics/Math.cs @@ -28,6 +28,7 @@ public static int Abs(int Number) { return +Number; } + public static double Abs(double Number) { return +Number; diff --git a/PrismOS/Text/Tests.txt b/PrismOS/Text/Tests.txt index 92a73942..0274f10e 100644 --- a/PrismOS/Text/Tests.txt +++ b/PrismOS/Text/Tests.txt @@ -1,4 +1,4 @@ -Canvas.DrawString(15, 15, "VBE Version: " + Cosmos.Core.VBE.getControllerInfo().vbeVersion, Color.White); +vCanvas.DrawString(15, 15, "VBE Version: " + Cosmos.Core.VBE.getControllerInfo().vbeVersion, Color.White); Canvas.DrawString(15, 15, "Total VRAM: " + Cosmos.Core.VBE.getControllerInfo().totalmemory, Color.White); Canvas.DrawString(15, 15, "Total RAM: " + ((Cosmos.Core.GCImplementation.GetAvailableRAM() + Cosmos.Core.GCImplementation.GetUsedRAM()) / 1024) + " MB", Color.White); Canvas.DrawString(15, 15, "Used RAM: " + (Cosmos.Core.GCImplementation.GetUsedRAM() / 1024) + " MB", Color.White); @@ -116,21 +116,48 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) "

Hello, World!

")); } + System.Console.WriteLine("Gateway address: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.DefaultGateway.ToString()); + System.Console.WriteLine("Subnet mask: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.SubnetMask.ToString()); + System.Console.WriteLine("local IP: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.IPAddress.ToString()); + System.Console.WriteLine("Mac address: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Key.MACAddress.ToString()); + System.Console.WriteLine("network device: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Key.Name); + Cosmos.System.Network.IPv4.TCP.TcpClient TCP = new(80); + System.Console.WriteLine("Created DNS and TCP clients!"); + DNS.SendAsk("http://example.com/"); + System.Console.WriteLine("Sent request for 'http://example.com/'..."); + System.Console.WriteLine("Got return address!"); + TCP.Send(System.Text.Encoding.UTF8.GetBytes("GET /Index.html")); + System.Console.WriteLine("Sent request for index.html..."); + Cosmos.System.Network.IPv4.EndPoint E = TCP.LocalEndPoint; + System.Console.WriteLine(System.Text.Encoding.UTF8.GetString(TCP.Receive(ref E))); + while (true) { } + + // P = -P0*T^3+3*P0*T-3*P0*T+P0+3*P1*T^3-6*P1*T^2+3*P1*T+-3*P2*T^3+3*P2*T^2+P3*T^3 + + + (int, int) A = Numerics.Math.LinearInterpolate(X1, Y1, X2, Y2, T); + (int, int) B = Numerics.Math.LinearInterpolate(X2, Y2, X3, Y3, T); + (int, int) C = Numerics.Math.LinearInterpolate(X3, Y3, X4, Y4, T); + (int, int) D = Numerics.Math.LinearInterpolate(A, B, T); + (int, int) E = Numerics.Math.LinearInterpolate(B, C, T); + (int, int) P = Numerics.Math.LinearInterpolate(D, E, T); + + public uint* ParseTGA(byte[] ptr) { // 0 = Width, 1 = Height, rest is raw data uint* data; int i, j, k, x, y, w = (ptr[13] << 8) + ptr[12], h = (ptr[15] << 8) + ptr[14], o = (ptr[11] << 8) + ptr[10]; - int m = ((ptr[1] == 0 ? (ptr[7] >> 3) * ptr[5] : 0) + 18); + int m = (ptr[1] == 0 ? (ptr[7] >> 3) * ptr[5] : 0) + 18; if (w < 1 || h < 1) { return null; } - data = (uint*)Cosmos.Core.GCImplementation.AllocNewObject((uint)((w * h + 2) * sizeof(uint))); + data = (uint*)GC.AllocNewObject((uint)((w * h + 2) * sizeof(uint))); if ((int*)data != (uint*)0) { return null; @@ -141,7 +168,7 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) case 1: if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) { - Cosmos.Core.GCImplementation.Free((uint)data); + GC.Free((uint)data); return null; } for (y = i = 0; y < h; y++) @@ -157,7 +184,7 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) case 2: if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) { - Cosmos.Core.GCImplementation.Free((uint)data); + GC.Free((uint)data); return null; } for (y = i = 0; y < h; y++) @@ -173,7 +200,7 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) case 9: if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) { - Cosmos.Core.GCImplementation.Free((uint)data); + GC.Free((uint)data); return null; } y = i = 0; @@ -205,7 +232,7 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) case 10: if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) { - Cosmos.Core.GCImplementation.Free((uint)data); + GC.Free((uint)data); return null; } y = i = 0; @@ -243,43 +270,10 @@ if (Cosmos.System.KeyboardManager.ControlPressed || ShowMenu) } break; default: - Cosmos.Core.GCImplementation.Free((uint)data); + GC.Free((uint)data); return null; } data[0] = (uint)w; data[1] = (uint)h; return data; - } - - // Move the window to the correct position - Window.X = (int)Mouse.X - ((int)Mouse.X - Window.X); - Window.Y = (int)Mouse.Y - ((int)Mouse.Y - Window.Y); - - - - System.Console.WriteLine("Gateway address: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.DefaultGateway.ToString()); - System.Console.WriteLine("Subnet mask: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.SubnetMask.ToString()); - System.Console.WriteLine("local IP: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Value.IPAddress.ToString()); - System.Console.WriteLine("Mac address: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Key.MACAddress.ToString()); - System.Console.WriteLine("network device: " + Cosmos.System.Network.Config.NetworkConfig.CurrentConfig.Key.Name); - Cosmos.System.Network.IPv4.TCP.TcpClient TCP = new(80); - System.Console.WriteLine("Created DNS and TCP clients!"); - DNS.SendAsk("http://example.com/"); - System.Console.WriteLine("Sent request for 'http://example.com/'..."); - System.Console.WriteLine("Got return address!"); - TCP.Send(System.Text.Encoding.UTF8.GetBytes("GET /Index.html")); - System.Console.WriteLine("Sent request for index.html..."); - Cosmos.System.Network.IPv4.EndPoint E = TCP.LocalEndPoint; - System.Console.WriteLine(System.Text.Encoding.UTF8.GetString(TCP.Receive(ref E))); - while (true) { } - - - // P = -P0*T^3+3*P0*T-3*P0*T+P0+3*P1*T^3-6*P1*T^2+3*P1*T+-3*P2*T^3+3*P2*T^2+P3*T^3 - - - (int, int) A = Numerics.Math.LinearInterpolate(X1, Y1, X2, Y2, T); - (int, int) B = Numerics.Math.LinearInterpolate(X2, Y2, X3, Y3, T); - (int, int) C = Numerics.Math.LinearInterpolate(X3, Y3, X4, Y4, T); - (int, int) D = Numerics.Math.LinearInterpolate(A, B, T); - (int, int) E = Numerics.Math.LinearInterpolate(B, C, T); - (int, int) P = Numerics.Math.LinearInterpolate(D, E, T); \ No newline at end of file + } \ No newline at end of file