Skip to content

Somewhat indepth Canvas Changes explained

JamesTheMaker edited this page Mar 7, 2022 · 11 revisions

Canvas changes overview

  1. We can now Use Canvas on Real hardware due to the implementation of the VGA Driver
  2. VGAFonts have been implemented which will help in case of #3
  3. Finally we can return from Canvas to text mode!

More Explanation

With the upcoming merge of the CGSE branch we will get some long awaited features!

Lets start with the obvious: canvas on real hardware!

The standard way of adding:

public class Kernel : Sys.Kernel
{
        private Canvas canvas;
        protected override void BeforeRun()
        {
            canvas = FullScreenCanvas.GetFullScreenCanvas(new Mode(320,200,ColorDepth.ColorDepth8));   
            canvas.Clear(Color.Blue);
        }
}

Of course this still works and now supports the VGA Driver, but there is another way we can use to check that it really works:

canvas = new VGACanvas(new mode(320,200,ColorDepth.ColorDepth8)); This will specifically load the VGACanvas skipping the auto detection, however if you plan on debugging on VMWare/bochs and real hardware, it is recommended to not use this. Now you might have noticed that mode 320x200x8 is used, this is because other modes are rather slow at the current point in time. Now I am going to combine the features 2 and 3 (above) as they tie together here. in our protected override void Run() we can now do the following.

Warning:

keep in mind that when using the default font i.e: screenFont.CreateVGAFont() changing the screenFont.CharHeight WILL break the display as VGAFonts do not scale, this is meant for future implementations of font loading abilities.

if (Console.ReadKey(true).Key == ConsoleKey.H)
{
        canvas.Disable();
        PCScreenFont screenFont = new PCScreenFont();
        VGAScreen.SetFont(screenFont.CreateVGAFont(), screenFont.CharHeight);
}

While the canvas has been successfully exited, the Run won't work as intended. Here is how to fix this:

Before our protected static void BeforeRun() we will add an bool like this protected static bool enabled; Now we can fix this by setting enabled = true in our Run() after we initialized the canvas. All we have to do now is use if(enabled) { } around the ConsoleReadKey to disable the canvas, then we set the bool to false BEFORE we disable the canvas, now our console will work as expected again.

Custom Fonts:

The Text mode now Supports loading of PSF Font files, a tool to convert those to the string required has been added to the: Resources

Another useful tool to Edit/Create psf files has been updated by Quajak to Python 3 and is available here: afe If you already have python installed and get an error about wx please run pip install wxPython

Clone this wiki locally