Basic Drawing 6 Comments
using System;
using Cosmos.Compiler.Builder;
using Cosmos.Hardware;
using Cosmos.Sys;
using Cosmos.Kernel;
using System.Collections;
using System.Collections.Generic;
using Screen = Cosmos.Hardware.VGAScreen;
namespace Draw
{
class Program
{
[STAThread]
static void Main(string[] args)
{
BuildUI.Run();
}
private static uint[] screenbuffer = new uint[(320 * 200 * 8 ) + 320]; //Ok, you can use 512320
public static uint inviscolor = 300; //Some value that won’t be assigned to a color. Used to designate a pixel with no color info.
public static uint backColour = 0;
public static void Init()
{
var xBoot = new Cosmos.Sys.Boot();
xBoot.Execute();
for (int u = 0; u < 42; u++) // RED
{
Screen.SetPaletteEntry((int)u, (byte)(u * 6), (byte)0, (byte)0);
}
for (int u = 42; u < 84; u++) // GREEN
{
Screen.SetPaletteEntry((int)u, (byte)0, (byte)((u – 42) * 6), (byte)0);
}
for (int u = 84; u < 126; u++) // BLUE
{
Screen.SetPaletteEntry((int)u, (byte)0, (byte)0, (byte)((u – 84) * 6));
}
for (int u = 126; u < 168; u++) // YELLOW
{
Screen.SetPaletteEntry((int)u, (byte)((u – 126) * 6), (byte)((u – 126) * 6), (byte)0);
}
for (int u = 168; u < 210; u++) // CYAN
{
Screen.SetPaletteEntry((int)u, (byte)0, (byte)((u – 168) * 6), (byte)((u – 168) * 6));
}
for (int u = 210; u < 213; u++) // MAGENTA
{
Screen.SetPaletteEntry((int)u, (byte)((u – 210) * 85), (byte)0, (byte)((u – 210) * 85));
}
for (int u = 213; u < 255; u++) // GREYSCALE
{
Screen.SetPaletteEntry((int)u, (byte)((u – 213) * 6), (byte)((u – 213) * 6), (byte)((u – 213) * 6));
}
Screen.SetPaletteEntry(255, 0×00, 0×00, 0×00);
for (int zxc = 0; zxc < 512320; zxc++)
{
screenbuffer[zxc] = inviscolor;
}
Screen.SetMode320x200x8();
reDrawScreen(backColour); //where BackColour is the color of the background, again where there is nothing drawn.
while (true)
{ //main loop. Have fun making your program.
reDrawScreen(backColour);
}
}
public static void reDrawScreen(uint color)
{
for (uint xx = 0; xx < 320; xx++)
{
for (uint yy = 0; yy < 200; yy++)
{
uint num = yy * 320 + xx;
if ((uint)screenbuffer[num] != inviscolor)
Screen.SetPixel320x200x8(xx, yy, screenbuffer[num]); //Screen.SetPixel320x200x8(num, screenbuffer[num]);
//I can’t remember which function I added, so if the un-commented one isn’t available, use the commented one instead.
else
Screen.SetPixel320x200x8(xx, yy, color); //Screen.SetPixel320x200x8(num, color);
//I can’t remember which function I added, so if the un-commented one isn’t available, use the commented one instead.
screenbuffer[num] = inviscolor; //clears the buffer after the pixel is drawn.
}
}
}
public static void FillRectangle(uint posx, uint posy, uint sizex, uint sizey, uint colour)
{
for (uint xx = posx; xx < sizex + posx; xx++)
{
for (uint yy = posy; yy < sizey + posy; yy++)
{
if (xx <= 320 – 1 && xx >= 0)
screenbuffer[yy * 320 + xx] = colour; //This is how you add to the buffer.
}
}
}
}
}
EDIT: made it work. Sorry for those who just copied and pasted.
gr8
THANK YOU!
I cut and pasted that code into my cosmos templates and it came back with a lot of code errors. What’s up?
huh, I didn’t actually use and IDE to make this, I just cut and paste some code. :/ My bad. I’m fixing it now.
Hey I got like 250 errors. Could you email me the source or fix it
email gruntxproductions@live.com
Maybe probably grabbed the old code, I just fixed it a while ago.
Or maybe you are missing some references?