Skip to content

Commit

Permalink
Merge pull request CosmosOS#1124 from fanoI/cgs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
quajak authored May 4, 2019
2 parents 5cade81 + b76f7e5 commit a772265
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 73 deletions.
3 changes: 1 addition & 2 deletions Tests/Cosmos.TestRunner.Full/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static IEnumerable<Type> GetStableKernelTypes()

//yield return typeof(KernelGen3.Boot);

/* Please see the notes on the kernel itself before enabling it */
//yield return typeof(GraphicTest.Kernel);
yield return typeof(GraphicTest.Kernel);
/* Please see the notes on the kernel itself before enabling it */
//yield return typeof(ConsoleTest.Kernel);
/* This is a bit slow and works only because ring check is disabled to decide if leave it enabled */
Expand Down
95 changes: 47 additions & 48 deletions Tests/Kernels/GraphicTest/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@
using Point = Cosmos.System.Graphics.Point;

/*
* Please note this is an atypical TestRunner:
* - no Assertion can be done
* - it cannot be executed automatically
*
* it exists to make easier tests while changing low level stuff (it would be better and faster to use the Demo kernel but
* sometimes it is a problem to make it see modifications done at low level)
*
* Remember to comment this test again on TestKernelSets.cs when you are ready to merge your modifications!
* It is impossible to make assertions here but it is useful in any case to have it runs automatically
* to catch stack overflows / corruptions when the CGS code is modified.
*/
namespace GraphicTest
{
Expand Down Expand Up @@ -43,64 +37,69 @@ protected override void BeforeRun()
Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");

canvas = FullScreenCanvas.GetFullScreenCanvas();

canvas.Clear(Color.Blue);
}

protected override void Run()
private void DoTest (Canvas aCanvas)
{
try
{
mDebugger.Send("Run");
mDebugger.Send($"Testing Canvas with mode {aCanvas.Mode}");
aCanvas.Clear(Color.Blue);

/* A red Point */
Pen pen = new Pen(Color.Red);
canvas.DrawPoint(pen, 69, 69);
/* A red Point */
Pen pen = new Pen(Color.Red);
aCanvas.DrawPoint(pen, 69, 69);

/* A GreenYellow horizontal line */
pen.Color = Color.GreenYellow;
canvas.DrawLine(pen, 250, 100, 400, 100);
/* A GreenYellow horizontal line */
pen.Color = Color.GreenYellow;
aCanvas.DrawLine(pen, 250, 100, 400, 100);

/* An IndianRed vertical line */
pen.Color = Color.IndianRed;
canvas.DrawLine(pen, 350, 150, 350, 250);
/* An IndianRed vertical line */
pen.Color = Color.IndianRed;
aCanvas.DrawLine(pen, 350, 150, 350, 250);

/* A MintCream diagonal line */
pen.Color = Color.MintCream;
canvas.DrawLine(pen, 250, 150, 400, 250);
/* A MintCream diagonal line */
pen.Color = Color.MintCream;
aCanvas.DrawLine(pen, 250, 150, 400, 250);

/* A PaleVioletRed rectangle */
pen.Color = Color.PaleVioletRed;
canvas.DrawRectangle(pen, 350, 350, 80, 60);
/* Rectangles of various colors */
pen.Color = Color.PaleVioletRed;
aCanvas.DrawRectangle(pen, 350, 350, 80, 60);

pen.Color = Color.Chartreuse;
canvas.DrawCircle(pen, 69, 69, 10);
pen.Color = Color.Chartreuse;
aCanvas.DrawCircle(pen, 69, 69, 10);

pen.Color = Color.DimGray;
canvas.DrawEllipse(pen, 100, 69, 10, 50);
pen.Color = Color.DimGray;
aCanvas.DrawEllipse(pen, 100, 69, 10, 50);

pen.Color = Color.MediumPurple;
canvas.DrawPolygon(pen, new Point(200, 250), new Point(250, 300), new Point(220, 350), new Point(210, 275));
pen.Color = Color.MediumPurple;
aCanvas.DrawPolygon(pen, new Point(200, 250), new Point(250, 300), new Point(220, 350), new Point(210, 275));

Console.ReadKey();
/* A LimeGreen rectangle */
pen.Color = Color.LimeGreen;
aCanvas.DrawRectangle(pen, 450, 450, 80, 60);

/* Let's try to change mode...*/
canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32);
/* A filled rectange */
pen.Color = Color.Chocolate;
aCanvas.DrawFilledRectangle(pen, 200, 150, 400, 300);

//If the background is not redrawn, it gets corrupted (this happens more in VmWare)
canvas.Clear(Color.Blue);
/* A Bitmpap image */
aCanvas.DrawImage(bitmap, new Point(0, 0));

/* A LimeGreen rectangle */
pen.Color = Color.LimeGreen;
canvas.DrawRectangle(pen, 450, 450, 80, 60);
mDebugger.Send($"Test of Canvas with mode {aCanvas.Mode} executed successfully");
}

/* A filled rectange */
pen.Color = Color.Chocolate;
canvas.DrawFilledRectangle(pen, 200, 150, 400, 300);
protected override void Run()
{
try
{
mDebugger.Send("Run");

canvas.DrawImage(bitmap, new Point(0, 0));
/* First test with the DefaulMode */
DoTest(canvas);

Console.ReadKey();
DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(800, 600, ColorDepth.ColorDepth32)));
DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1024, 768, ColorDepth.ColorDepth32)));
DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1366, 768, ColorDepth.ColorDepth32)));
DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1280, 720, ColorDepth.ColorDepth32)));

TestController.Completed();
}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Debug.Hosts/Bochs.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private void InitializeKeyValues()
string BochsDirectory = Path.GetDirectoryName(BochsSupport.BochsExe.FullName);
string default_configuration = "# configuration file generated by Bochs\n"
+ "plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1\n"
+ "config_interface: win32config\n" + "display_library: win32" + debugGui + "\n"
+ "config_interface: win32config\n" + "display_library: nogui" + debugGui + "\n"
+ "debug_symbols: file=\"%DEBUGSYMBOLSPATH%\"\n"
+ "memory: host=256, guest=256\n" + "romimage: file=\"" + BochsDirectory
+ "/BIOS-bochs-latest\"\n" + "vgaromimage: file=\"" + BochsDirectory
Expand Down
6 changes: 5 additions & 1 deletion source/Cosmos.Debug.Hosts/Bochs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;

using Cosmos.Build.Common;
using Cosmos.Debug.Common;

namespace Cosmos.Debug.Hosts
{
Expand Down Expand Up @@ -41,6 +40,11 @@ public Bochs(Dictionary<string, string> aParams, bool aUseGDB, FileInfo configur
}

InitializeKeyValues();
if (Environment.GetEnvironmentVariable("CI") == "True")
{
string debugGui = startDebugGui ? ", options=\"gui_debug\"" : "";
defaultConfigs["display_library"] = "nogui " + debugGui;
}
GenerateConfiguration(configurationFile.FullName);
_bochsConfigurationFile = configurationFile;
}
Expand Down
19 changes: 10 additions & 9 deletions source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ namespace Cosmos.System.Graphics
{
public abstract class Canvas
{
protected Canvas(Mode mode)
{
//Global.mDebugger.SendInternal($"Creating a new Canvas with Mode ${mode}");
Mode = mode;
}

public abstract IReadOnlyList<Mode> AvailableModes { get; }
/*
* IReadOnlyList<T> is not working, the Modes inside it become corrupted and then you get Stack Overflow
*/
//public abstract IReadOnlyList<Mode> AvailableModes { get; }
public abstract List<Mode> AvailableModes { get; }

public abstract Mode DefaultGraphicMode { get; }

public abstract Mode Mode { get; set; }

/// <summary>
/// Clear all the Canvas with the Black color.
/// </summary>
Expand Down Expand Up @@ -403,12 +401,15 @@ protected bool CheckIfModeIsValid(Mode mode)

foreach (var elem in AvailableModes)
{
Global.mDebugger.SendInternal($"elem is {elem} mode is {mode}");
if (elem == mode)
{
Global.mDebugger.SendInternal($"Mode {mode} found");
return true; // All OK mode does exists in availableModes
}
}

Global.mDebugger.SendInternal($"Mode {mode} found");
return false;
}

Expand All @@ -419,7 +420,7 @@ protected void ThrowIfModeIsNotValid(Mode mode)
return;
}

Global.mDebugger.SendInternal($"mode is not found! Raising exception...");
Global.mDebugger.SendInternal($"Mode {mode} is not found! Raising exception...");
/* 'mode' was not in the 'availableModes' List ==> 'mode' in NOT Valid */
throw new ArgumentOutOfRangeException(nameof(mode), $"Mode {mode} is not supported by this Driver");
}
Expand Down
3 changes: 3 additions & 0 deletions source/Cosmos.System2/Graphics/FullScreenCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ private static Canvas GetVideoDriver(Mode mode)

public static Canvas GetFullScreenCanvas()
{
Global.mDebugger.SendInternal($"GetFullScreenCanvas() with default mode");
if (MyVideoDriver == null)
{
Global.mDebugger.SendInternal($"MyVideoDriver is null creating new object");
return MyVideoDriver = GetVideoDriver();
}
else
{
Global.mDebugger.SendInternal($"MyVideoDriver is NOT null using the old one changing mode to DefaulMode");
MyVideoDriver.Mode = MyVideoDriver.DefaultGraphicMode;
return MyVideoDriver;
}
Expand Down
18 changes: 13 additions & 5 deletions source/Cosmos.System2/Graphics/SVGAIIScreen.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//#define COSMOSDEBUG
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -9,26 +10,26 @@ namespace Cosmos.System.Graphics
{
public class SVGAIIScreen : Canvas
{
private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth16);
private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth32);

private static readonly Debugger Debugger = new Debugger("System", "SVGAIIScreen");

private Mode _mode;

public VMWareSVGAII xSVGAIIDriver;
private readonly VMWareSVGAII xSVGAIIDriver;

public SVGAIIScreen()
: this(DefaultMode)
{
}

public SVGAIIScreen(Mode aMode)
: base(aMode)
{
Debugger.SendInternal($"Called ctor with mode {aMode}");
ThrowIfModeIsNotValid(aMode);

xSVGAIIDriver = new VMWareSVGAII();
xSVGAIIDriver.SetMode((uint)aMode.Columns, (uint)aMode.Rows, (uint)aMode.ColorDepth);
Mode = aMode;
}

public override Mode Mode
Expand All @@ -37,6 +38,7 @@ public override Mode Mode
set
{
_mode = value;
Debugger.SendInternal($"Called Mode set property with mode {_mode}");
SetGraphicsMode(_mode);
}
}
Expand Down Expand Up @@ -71,8 +73,11 @@ public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int
xSVGAIIDriver.Fill((uint)x_start, (uint)y_start, (uint)width, (uint)height, (uint)pen.Color.ToArgb());
}

public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
//public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
public override List<Mode> AvailableModes { get; } = new List<Mode>
{
/* VmWare maybe supports 16 bit resolutions but CGS not yet (we should need to do RGB32->RGB16 conversion) */
#if false
/* 16-bit Depth Resolutions*/

/* SD Resolutions */
Expand All @@ -81,6 +86,7 @@ public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int
new Mode(640, 480, ColorDepth.ColorDepth16),
new Mode(720, 480, ColorDepth.ColorDepth16),
new Mode(800, 600, ColorDepth.ColorDepth16),
new Mode(1024, 768, ColorDepth.ColorDepth16),
new Mode(1152, 768, ColorDepth.ColorDepth16),

/* Old HD-Ready Resolutions */
Expand Down Expand Up @@ -109,6 +115,7 @@ public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int
new Mode(3200, 2048, ColorDepth.ColorDepth16), // WQXGA+
new Mode(3200, 2400, ColorDepth.ColorDepth16), // QUXGA
new Mode(3840, 2400, ColorDepth.ColorDepth16), // WQUXGA
#endif

/* 32-bit Depth Resolutions*/
/* SD Resolutions */
Expand All @@ -117,6 +124,7 @@ public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int
new Mode(640, 480, ColorDepth.ColorDepth32),
new Mode(720, 480, ColorDepth.ColorDepth32),
new Mode(800, 600, ColorDepth.ColorDepth32),
new Mode(1024, 768, ColorDepth.ColorDepth32),
new Mode(1152, 768, ColorDepth.ColorDepth32),

/* Old HD-Ready Resolutions */
Expand Down
15 changes: 8 additions & 7 deletions source/Cosmos.System2/Graphics/VBEScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public VBEScreen()
}

public VBEScreen(Mode mode)
: base(mode)
{
Global.mDebugger.SendInternal($"Creating new VBEScreen() with mode {mode.Columns}x{mode.Rows}x{(uint)mode.ColorDepth}");

ThrowIfModeIsNotValid(mode);

VBEDriver = new VBEDriver((ushort)mode.Columns, (ushort)mode.Rows, (ushort)mode.ColorDepth);
Mode = mode;
}

public override Mode Mode
Expand All @@ -43,14 +43,15 @@ public override Mode Mode
}
}

#region Display
#region Display

/// <summary>
/// All the available screen modes VBE supports, I would like to query the hardware and obtain from it the list but I have
/// not yet find how to do it! For now I hardcode the most used VESA modes, VBE seems to support until HDTV resolution
/// without problems that is well... excellent :-)
/// </summary>
public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
//public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
public override List<Mode> AvailableModes { get; } = new List<Mode>
{
new Mode(320, 240, ColorDepth.ColorDepth32),
new Mode(640, 480, ColorDepth.ColorDepth32),
Expand Down Expand Up @@ -85,9 +86,9 @@ private void SetMode(Mode mode)
//set the screen
VBEDriver.VBESet(xres, yres, bpp);
}
#endregion
#endregion

#region Drawing
#region Drawing

public override void Clear(Color color)
{
Expand Down Expand Up @@ -211,7 +212,7 @@ public override void DrawImage(Image image, int x, int y)

#endregion

#region Reading
#region Reading

public override Color GetPointColor(int x, int y)
{
Expand All @@ -230,7 +231,7 @@ public override Color GetPointColor(int x, int y)
return Color.FromArgb(VBEDriver.GetVRAM(offset));
}

#endregion
#endregion

}
}

0 comments on commit a772265

Please sign in to comment.