Skip to content

Instantly share code, notes, and snippets.

@Myvar
Last active September 15, 2015 07:48
Show Gist options
  • Save Myvar/6a3e96e699aed4efc00f to your computer and use it in GitHub Desktop.
Save Myvar/6a3e96e699aed4efc00f to your computer and use it in GitHub Desktop.
public static class Screen
{
public static int ClearColor { get; set; } = 0x167F39;
public static sys.VBEScreen Vbe = new sys.VBEScreen();
private static int[] Buffer = new int[0];
public static void Init()
{
Vbe.SetMode(sys.VBEScreen.ScreenSize.Size1280x1024, sys.VBEScreen.Bpp.Bpp24);
Buffer = new int[Vbe.ScreenHeight * Vbe.ScreenWidth];
for (int i = 0; i < Vbe.ScreenHeight * Vbe.ScreenWidth; i++)
{
Buffer[i] = ClearColor;
}
Vbe.Clear((uint)ClearColor);
}
public static void SetPixel(int x, int y, int c)
{
if(x < Vbe.ScreenWidth && y < Vbe.ScreenHeight)
Buffer[(y * Vbe.ScreenWidth) + x] = c;
}
public static int GetPixel(int x, int y)
{
return Buffer[(y * Vbe.ScreenWidth) + x];
}
public static void Redraw()
{
int c = 0;
for (int x = 0; x < Vbe.ScreenWidth; x++)
{
for (int y = 0; y < Vbe.ScreenHeight; y++)
{
var px = Buffer[(y * Vbe.ScreenWidth) + x];
if (Vbe.GetPixel((uint)x, (uint)y) != px)
{
Vbe.SetPixel((uint)x, (uint)y, (uint)px);
}
c++;
}
}
for (int i = 0; i < Vbe.ScreenHeight * Vbe.ScreenWidth; i++)
{
Buffer[i] = ClearColor;
}
}
public static void DrawRect(int x, int y, int w, int h, int c)
{
for (int w1 = 0; w1 < w; w1++)
{
for (int h1 = 0; h1 < h; h1++)
{
SetPixel(x + w1, y + h1, c);
}
}
}
}
----------------------------------------------------------------------------------------------------
public class Kernel : Sys.Kernel
{
public Desktop d = new Desktop();
protected override void BeforeRun()
{
Screen.Init();
}
protected override void Run()
{
//Draw your Screen here
Screen.Redraw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment