CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.93k stars 553 forks source link

DevKit Graphics Issue - What's wrong with my VGA Driver? It's not working and only sets black pixels to the screen. #621

Closed SunderB closed 7 years ago

SunderB commented 7 years ago

I'm trying to draw a taskbar on the screen using the tutorial in the wiki, it worked in UserKit but I've switched to DevKit and when I try to use the screen, it only fills in text characters with black. In the output log it says:

Setting graphic mode to 320x200@256
Drawing pixel at 0, with color 0
Pixel drawn but you cannot see it!
Drawing pixel at 1, with color 0
Pixel drawn but you cannot see it!
Drawing pixel at 2, with color 0
Pixel drawn but you cannot see it!
Drawing pixel at 3, with color 0
Pixel drawn but you cannot see it!
Drawing pixel at 4, with color 0
Pixel drawn but you cannot see it!
Drawing pixel at 5, with color 0
Pixel drawn but you cannot see it!

I know that there is the Cosmos Graphics Subsystem, but it only works with Bochs, QEMU or VirtualBox and I don't know how to debug or compile an OS in Cosmos to work with anything other than VMware.

Here's the Display Driver, which is in a project in Ring 2 (System):

using Cosmos.HAL;
using Sys = Cosmos.System;
namespace Hardware.Drivers.Display
{
    public class DisplayDriver
    {

        protected VGAScreen screen;
        private int width, height;

        public DisplayDriver()
        {
            screen = new VGAScreen();
        }

        public void init()
        {
            screen.SetGraphicsMode(VGAScreen.ScreenSize.Size320x200, VGAScreen.ColorDepth.BitDepth8);
            screen.Clear(0);
            width = screen.PixelWidth;
            height = screen.PixelHeight;
        }

        public virtual void setPixel(int x, int y, int c)
        {
            if (screen.GetPixel320x200x8((uint)x, (uint)y) != (uint)c)
                setPixelRaw(x, y, c);
        }

        public virtual byte getPixel(int x, int y)
        {
            return (byte)screen.GetPixel320x200x8((uint)x, (uint)y);
        }

        public virtual void clear()
        {
            clear(0);
        }

        public virtual void clear(int c)
        {
            screen.Clear(c);
        }

        public virtual void step() { }

        public int getWidth()
        {
            return width;
        }

        public int getHeight()
        {
            return height;
        }

        public void setPixelRaw(int x, int y, int c)
        {

            screen.SetPixel320x200x8((uint)x, (uint)y, (uint)c);

        }
    }
}

Here's the other code which handles the GUI, which is in the main project which is in Ring 3 (User):

Kernel.cs

protected override void Run()
        {
            if (gui == 0)
            {
                Console.Write(":");
                var input = Console.ReadLine();
                if (input == "echo")
                {
                    Console.WriteLine("What do you want to echo?");
                    string echome = Console.ReadLine();
                    Console.WriteLine(echome + "                                           ");
                }
               //Console commands go here
                else if (input == "gui")
                {
                    Console.WriteLine("The display should be initialized. If you can see this, then something has gone wrong");
                    DisplayDriver display = new DisplayDriver();
                    display.init();
                    gui = 1;
                    GUIManager.Step();
                }
               //More console commands go here
                else
                {
                    Console.WriteLine("No such command. For a list of commands type 'help'");
                }
            }
            else if (gui == 1)
            {
                GUIManager.Step();
            }
            //Console.Write("Text typed: ");
            //Console.WriteLine(input);
        }

GUIManager.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hardware.Drivers.Display;

namespace ColourOS
{
    class GUIManager
    {
        public static void Step()
        {
            DisplayDriver display = new DisplayDriver();
            //Draw the taskbar
            for (int w = 0; w < 320; w++)
            {
                for (int h = 0; h < 30; h++)
                {
                    int x = w;
                    int y = 200 - h; //170 - h
                    display.setPixel(x, y, 30); //SetPixel(x,y,color)
                }
            }
        }
    }
}
dowowTeam commented 7 years ago

VGA Driver is not supported. Use VBEScreen

fanoI commented 7 years ago

Sadly it does not work with VmWare! If no one of you takes this issue: https://github.com/CosmosOS/Cosmos/issues/602 probably we (the CoreTeam) do it in future but graphic is really low priority for us...

SunderB commented 7 years ago

Is it possible to compile a Cosmos OS to work with VirtualBox?

fanoI commented 7 years ago

A Cosmos kernel could be compiled in three different ways:

  1. VmWare Image
  2. Boch Image
  3. ISO

The third one should in theory run in any VM (on VirtualBox too) and in normal PC too (but it is not advised to do this for now). So please try the third solution.

SunderB commented 7 years ago

Thanks, I've managed to get my OS working in VirtualBox and CGS works in it!

fanoI commented 7 years ago

Excellent!