This project is read-only.

Help, I keep getting errors in my GUI OS

Aug 27, 2011 at 6:14 AM
Edited Aug 28, 2011 at 3:35 AM

I know I have posted this twice, but I am getting no answers and I can't find anything on the internet. I have also uploaded the image to a new host (photobucket), so now there shouldn't be any issues.

Ok so i code my OS using Cosmos Milestone 4 and VS2010 with no errors but when I build it i keep getting these errors. I have googled it but to no avail. I have linked an image of it here. (I uploaded it to photobucket, so now it works)

My code is also provided below. If there are any problems with it, please tell. Thanks in advance.

using System;
using Cosmos.Hardware;
using Cosmos.Compiler.Builder;
using Cosmos.Kernel;

namespace MyOS
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static int screennum = 1;
        public static uint sx;
        public static uint sy;
        public static uint ScreenWidth = 320;
        public static uint ScreenHeight = 200;
        public static uint p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24;
        public static bool MenuOpenEx = false;
        public static uint Pressed = 0;
        public static Image MenuSave = new Image(50, 30);
        public static Boolean MenuOpen = false;
        public static void SaveScreenS(uint xpos, uint ypos, int width, int height, Image image, uint set)
        {
            uint n = 0;
            if (width > height)
            {
                for (uint x4 = 0; x4 < height; x4++)
                {
                    for (uint y4 = 0; y4 < width; y4++)
                    {
                        uint I = VGAScreen.GetPixel320x200x8(xpos + x4, ypos + y4);
                        image.SetPixel(xpos + x4, ypos + y4, I, n);
                        n += 1;
                    }
                }
            }
            if (width < height)
            {


                for (uint y4 = 0; y4 < width; y4++)
                {
                    for (uint x4 = 0; x4 < height; x4++)
                    {
                        uint I = VGAScreen.GetPixel320x200x8(xpos + x4, ypos + y4);
                        image.SetPixel(xpos + x4, ypos + y4, I, n);
                        n += 1;

                    }
                }
            }



        }
        public static void RestoreScreenS(uint xpos, uint ypos, int width, int height, Image image, uint set)
        {
            uint n = 0;
            if (width > height)
            {
                for (uint x4 = 0; x4 < height; x4++)
                {
                    for (uint y4 = 0; y4 < width; y4++)
                    {

                        uint I4 = image.GetPixel(xpos + x4, ypos + y4, n);
                        VGAScreen.SetPixel(xpos + x4, ypos + y4, I4);
                        n += 1;
                    }
                }
            }
            if (width < height)
            {


                for (uint y4 = 0; y4 < width; y4++)
                {
                    for (uint x4 = 0; x4 < height; x4++)
                    {
                        uint I4 = image.GetPixel(xpos + x4, ypos + y4, n);
                        VGAScreen.SetPixel(xpos + x4, ypos + y4, I4);
                        n += 1;
                    }
                }
            }


        }
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            VGAScreen.SetMode320x200x8();
            VGAScreen.SetPaletteEntry(4, 0x00, 0x3C, 0x00);//Green
            VGAScreen.SetPaletteEntry(0, 0x00, 0x00, 0x00); //Black         
            VGAScreen.SetPaletteEntry(5, 50, 50, 50);//Grey
            VGAScreen.SetPaletteEntry(6, 236, 233, 216);//window color
            VGAScreen.SetPaletteEntry(7, 255, 248, 106);//light yellow
            VGAScreen.SetPaletteEntry(8, 255, 255, 255);//white
            VGAScreen.Clear(4);//Clear the screen to green for now!
            MouseEx.Initialize();//Initialize Mouse
            //Draw All Of Our Desktop setups here
            DrawWindowsBar();
            DrawWindowsStartButton();
            SaveScreen((uint)MouseEx.X, (uint)MouseEx.Y);
            MouseEnabled();//Call the mouse loop

        }
        //Our Desktop Drawing Voids
        public static void DrawWindowsBar()
        {

            DrawRect(0, ScreenHeight - 8, ScreenWidth, 8, 5); //Make a Gray Menu Bar!
            DrawRect(0, ScreenHeight - 8, ScreenWidth, 1, 8); //Add light to the bar like windows does!
        }
        public static void DrawWindowsStartButton()
        {
            //Ok this will be a little bit harder
            DrawRect(4, ScreenHeight - 5, 25, 4, 0);//Draw our black menu button!
        }
        public static bool CheckClick(uint x, uint y, uint Length, uint Width)
        {
            for (uint bb = x; bb < x + Length; bb++)
            {
                for (uint cc = y; cc < y + Width; cc++)
                {
                    if (MouseEx.X == bb && MouseEx.Y == cc)
                    {
                        return true;   //Return true if the area is not clicked                
                    }
                }
            }
            return false;   //Return false if the area is not clicked
        }
        public static void DrawRect(uint x, uint y, uint Width, uint Height, uint color)
        {

            for (uint bb = x; bb < x + Width; bb++)
            {

                for (uint cc = y; cc < y + Height; cc++)
                {
                    VGAScreen.SetPixel320x200x8(bb, cc, color);
                }
            }
        }
        public static void MouseEnabled()
        {

            bool PointerDrawn = false;
            uint x = (uint)MouseEx.X;
            uint y = (uint)MouseEx.Y;
            uint mx;
            uint my;
            Boolean moved = false;
            while (true)
            {
                mx = (uint)MouseEx.X;
                my = (uint)MouseEx.Y;


                if (mx != x || my != y || mx == x || my == y)
                {



                    if (MouseEx.Buttons == MouseEx.MouseState.Left)
                    {
                        ProcessCMD();

                    }


                    if (mx != x & my == y) // This Checks if mouse is moving                   
                    {
                        moved = true;
                    }

                    if (mx == x & my != y)// This Checks if mouse is moving                   
                    {
                        moved = true;
                    }

                    if (mx != x & my != y)// This Checks if mouse is moving                   
                    {
                        moved = true; //Tells our code that the Mouse is not drawn.                  
                    }

                }

                if (moved == true)
                {

                    if (moved == true)// This Checks if mouse is moving                       
                    {
                        PointerDrawn = true;
                        moved = false;
                    }
                    if (PointerDrawn == true)//Is the pointer Not Drawn?                   
                    {
                        RestoreScreen();
                        x = mx;
                        y = my;
                        SaveScreen(x, y);
                        PointerDrawn = false;
                        DrawPointer(mx, my);
                    }
                    else
                    {

                        DrawPointer(mx, my);
                    }
                }
            }
        }
        public static void DrawPointer(uint x, uint y)
        {
            VGAScreen.SetPixel320x200x8(x, y, 10);
            VGAScreen.SetPixel320x200x8(x + 1, y, 10);
            VGAScreen.SetPixel320x200x8(x + 2, y, 10);
            VGAScreen.SetPixel320x200x8(x, y + 1, 10);
            VGAScreen.SetPixel320x200x8(x, y + 2, 10);
            VGAScreen.SetPixel320x200x8(x + 1, y + 1, 10);
            VGAScreen.SetPixel320x200x8(x + 2, y + 2, 10);
            VGAScreen.SetPixel320x200x8(x + 3, y + 3, 10);
        }
        public static void SaveScreen(uint x, uint y)
        {
            sx = x;
            sy = y;
            //left pixesl
            p0 = VGAScreen.GetPixel320x200x8(sx, sy);
            p1 = VGAScreen.GetPixel320x200x8(sx, sy + 1);
            p2 = VGAScreen.GetPixel320x200x8(sx, sy + 2);
            p3 = VGAScreen.GetPixel320x200x8(sx, sy + 3);
            p4 = VGAScreen.GetPixel320x200x8(sx, sy + 4);

            //Second Set of Left pixels
            p5 = VGAScreen.GetPixel320x200x8(sx + 1, sy);
            p6 = VGAScreen.GetPixel320x200x8(sx + 1, sy + 1);
            p7 = VGAScreen.GetPixel320x200x8(sx + 1, sy + 2);
            p8 = VGAScreen.GetPixel320x200x8(sx + 1, sy + 3);
            p9 = VGAScreen.GetPixel320x200x8(sx + 1, sy + 4);
            //third set of left pixels

            p10 = VGAScreen.GetPixel320x200x8(sx + 2, sy);
            p11 = VGAScreen.GetPixel320x200x8(sx + 2, sy + 1);
            p12 = VGAScreen.GetPixel320x200x8(sx + 2, sy + 2);
            p13 = VGAScreen.GetPixel320x200x8(sx + 2, sy + 3);
            p14 = VGAScreen.GetPixel320x200x8(sx + 2, sy + 4);
            //last row of pixels

            p15 = VGAScreen.GetPixel320x200x8(sx + 3, sy);
            p16 = VGAScreen.GetPixel320x200x8(sx + 3, sy + 1);
            p17 = VGAScreen.GetPixel320x200x8(sx + 3, sy + 2);
            p18 = VGAScreen.GetPixel320x200x8(sx + 3, sy + 3);
            p19 = VGAScreen.GetPixel320x200x8(sx + 3, sy + 4);

            p20 = VGAScreen.GetPixel320x200x8(sx + 4, sy);
            p21 = VGAScreen.GetPixel320x200x8(sx + 4, sy + 1);
            p22 = VGAScreen.GetPixel320x200x8(sx + 4, sy + 2);
            p23 = VGAScreen.GetPixel320x200x8(sx + 4, sy + 3);
            p24 = VGAScreen.GetPixel320x200x8(sx + 4, sy + 4);
        }
        public static void RestoreScreen()
        {

            //left pixesl
            VGAScreen.SetPixel320x200x8(sx, sy, p0);
            VGAScreen.SetPixel320x200x8(sx, sy + 1, p1);
            VGAScreen.SetPixel320x200x8(sx, sy + 2, p2);
            VGAScreen.SetPixel320x200x8(sx, sy + 3, p3);


            //Second Set of Left pixels
            VGAScreen.SetPixel320x200x8(sx + 1, sy, p5);
            VGAScreen.SetPixel320x200x8(sx + 1, sy + 1, p6);
            VGAScreen.SetPixel320x200x8(sx + 1, sy + 2, p7);
            VGAScreen.SetPixel320x200x8(sx + 1, sy + 3, p8);
            //third set of left pixels

            VGAScreen.SetPixel320x200x8(sx + 2, sy, p10);
            VGAScreen.SetPixel320x200x8(sx + 2, sy + 1, p11);
            VGAScreen.SetPixel320x200x8(sx + 2, sy + 2, p12);
            VGAScreen.SetPixel320x200x8(sx + 2, sy + 3, p13);
            //last row of pixels

            VGAScreen.SetPixel320x200x8(sx + 3, sy, p15);
            VGAScreen.SetPixel320x200x8(sx + 3, sy + 1, p16);
            VGAScreen.SetPixel320x200x8(sx + 3, sy + 2, p17);
            VGAScreen.SetPixel320x200x8(sx + 3, sy + 3, p18);

            //Extra Layer of Pixels Just incase
            VGAScreen.SetPixel320x200x8(sx + 4, sy, p20);
            VGAScreen.SetPixel320x200x8(sx + 4, sy + 1, p21);
            VGAScreen.SetPixel320x200x8(sx + 4, sy + 2, p22);
            VGAScreen.SetPixel320x200x8(sx + 4, sy + 3, p23);

        }
        public static void ProcessCMD()
        {
            if (CheckClick(4, ScreenHeight - 5, 25, 4) == true)
            {
                if (MenuOpen == false)
                {
                    DrawMenu();
                    MenuOpen = true;
                }
                else
                {
                    UnDrawMenu();
                    MenuOpen = false;
                }
            }
        }
        public static void DrawMenu()
        {
            //Save the menu before we draw it

            SaveScreenS(0, ScreenHeight - 8 - 50, 50, 30, MenuSave, 0);
            //This is a simple math thing ScreenHeight - 8 Lets you draw simple right on top of our menu bar so you then need to - the Menus height.
            DrawRect(0, ScreenHeight - 8 - 50, 30, 50, 1);

        }
        public static void UnDrawMenu()
        {
            //To get rid of it just restore the saved screen
            RestoreScreenS(0, ScreenHeight - 8 - 50, 50, 30, MenuSave, 0);

        }
    }

    class Image
    {
        private uint[] Data;
        ///
        /// The height of the image.
        ///
        private int Height;
        ///
        /// The width of the image.
        ///
        private int Width;
        public Image(int width, int height)
        {
            this.Width = width;
            this.Height = height;
            this.Data = new uint[(Height + 1) * (Width + 1)];
        }
        Image()
        {
            this.Width = 1;
            this.Height = 1;
            this.Data = new uint[(Height + 1) * (Width + 1)];
        }
        public uint GetPixel(uint x, uint y, uint n)
        {
            return this.Data[n];
        }
        public void SetPixel(uint x, uint y, uint p, uint n)
        {

            this.Data[n] = p;
        }
    }
    class MouseEx
    {
        public static int X, Y;
        public static MouseState Buttons;

        public static void Initialize()
        {

            //enable mouse
            WaitSignal();
            CPUBus.Write8(0x64, 0xA8);

            // enable interrupt
            WaitSignal();
            CPUBus.Write8(0x64, 0x20);
            WaitData();
            byte status = (byte)(CPUBus.Read8(0x60) | 2);
            WaitSignal();
            CPUBus.Write8(0x64, 0x60);
            WaitSignal();
            CPUBus.Write8(0x60, status);

            //default
            Write(0xF6);
            Read();  //Acknowledge

            //Enable the mouse
            Write(0xF4);
            Read();  //Acknowledge

            Interrupts.AddIRQHandler(12, new Interrupts.InterruptDelegate(HandleMouse));

        }

        public static byte GetMouseID()
        {
            CPUBus.Write8(0x64, 0xF2);
            return CPUBus.Read8(0x60);
        }

        private static byte Read()
        {
            WaitData();
            return CPUBus.Read8(0x60);
        }

        private static void Write(byte b)
        {
            //Wait to be able to send a command
            WaitSignal();
            //Tell the mouse we are sending a command
            CPUBus.Write8(0x64, 0xD4);
            //Wait for the final part
            WaitSignal();
            //Finally write
            CPUBus.Write8(0x60, b);
        }
        private static void WaitData()
        {
            for (int i = 0; i < 1000 & ((CPUBus.Read8(0x64) & 1) == 1); i++)
                ;

        }

        private static void WaitSignal()
        {
            for (int i = 0; i < 1000 & ((CPUBus.Read8(0x64) & 2) != 0); i++)
                ;
        }

        public enum MouseState
        {
            None = 0,
            Left = 1,
            Right = 2,
            Middle = 4
        }
        private static byte mouse_cycle = 0;
        private static int[] mouse_byte = new int[4];

        public static void HandleMouse(ref Interrupts.InterruptContext context)
        {
            switch (mouse_cycle)
            {
                case 0:
                    mouse_byte[0] = CPUBus.Read8(0x60);

                    if ((mouse_byte[0] & 0x8) == 0x8)
                        mouse_cycle++;

                    break;
                case 1:
                    mouse_byte[1] = CPUBus.Read8(0x60);
                    mouse_cycle++;
                    break;
                case 2:
                    mouse_byte[2] = CPUBus.Read8(0x60);
                    mouse_cycle = 0;

                    if ((mouse_byte[0] & 0x10) == 0x10)
                        X -= mouse_byte[1] ^ 0xff;
                    else
                        X += mouse_byte[1];

                    if ((mouse_byte[0] & 0x20) == 0x20)
                        Y += mouse_byte[2] ^ 0xff;
                    else
                        Y -= mouse_byte[2];

                    if (X < 0)
                        X = 0;
                    else if (X > 319)
                        X = 319;

                    if (Y < 0)
                        Y = 0;
                    else if (Y > 199)
                        Y = 199;

                    Buttons = (MouseState)(mouse_byte[0] & 0x7);

                    break;
            }
        }
    }

}

Aug 27, 2011 at 3:28 PM
> I know I have posted this twice, but I am getting no answers and I can't
> find anything on the internet.

The last time you posted, you posted an image which was an HTTP error
itself.
Aug 27, 2011 at 5:01 PM

Also, if you would, PLEASE find a different place to post the image to, because that site is marked as having a low security code by my router, which, as I've stated previously, is very picky about what it marks like that.