VGA Buffering

Feb 19, 2011 at 12:32 AM

I was reading this article about VGA buffering, and was wondering is it possible in Cosmos? I tried the following code below, but it doesn't seem to work. Any tips?

 

        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            SetupPalette();
            VGAScreen.SetMode320x200x8();
            VGAScreen.Clear(0);
            Mouse2.Initialize();
            uint x = (uint)resX / 2;
            uint y = (uint)resY / 2;
            while (true)
            {
                // remove the old cursor render
                SetPixelColor(x, y, 0);
                SetPixelColor(x + 1, y, 0);
                SetPixelColor(x + 2, y, 0);
                SetPixelColor(x, y + 1, 0);
                SetPixelColor(x, y + 2, 0);
                SetPixelColor(x + 1, y + 1, 0);
                SetPixelColor(x + 2, y + 2, 0);
                SetPixelColor(x + 3, y + 3, 0);
                // render all elements (excluding the mouse)
                GUI.CreateCircle(100, 100, 50, 100);
                GUI.CreateCircle(120, 120, 70, 40);
                // render the new cursor position
                uint mx = (uint)Mouse2.X;
                uint my = (uint)Mouse2.Y;
                SetPixelColor(mx, my, 255);
                SetPixelColor(mx + 1, my, 255);
                SetPixelColor(mx + 2, my, 255);
                SetPixelColor(mx, my + 1, 255);
                SetPixelColor(mx, my + 2, 255);
                SetPixelColor(mx + 1, my + 1, 255);
                SetPixelColor(mx + 2, my + 2, 255);
                SetPixelColor(mx + 3, my + 3, 255);
                x = mx;
                y = my;
                VGA = VGAScreen.GetAddressSpace();
                VGA.CopyFrom(pixels);
            }
        }
        public static void SetPixelColor(uint x, uint y, int color)
        {
            pixels.Write32(((y << 8) + (y << 6) + x), (uint)color);
        }

Feb 25, 2011 at 3:48 PM

i dont exactly see what you are doing here... so ill ask, "huh?"

O.o

Feb 26, 2011 at 5:39 AM

I want it so instead of the pixels all being updated in live execution, they are  updated all at once, by copying over an address space to the VGA address space. I was hoping this would remove any screen flickering.

Mar 9, 2011 at 5:39 PM

Sorry for bump, but does anybody know if this is possible?

Jul 14, 2014 at 4:22 PM
There is no reason why it should not be possible, however I think what is wrong with your code is that you need to write to the pixels array at position (y * width) + x rather than (y << 8) + (y << 6) + x. This will still flicker if you clear the screen every refresh, so you should probably check to see if the pixel is already the colour you want and only update the ones that aren't rather than the whole lot.