mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
VGA should work now
This commit is contained in:
parent
ae8d3ef435
commit
19cffbadd1
11 changed files with 484 additions and 419 deletions
|
|
@ -15,7 +15,7 @@ namespace Cosmos.TestRunner.Full
|
|||
get
|
||||
{
|
||||
yield return RunTargetEnum.Bochs;
|
||||
yield return RunTargetEnum.VMware;
|
||||
//yield return RunTargetEnum.VMware;
|
||||
//yield return RunTargetEnum.HyperV;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@ namespace Cosmos.TestRunner.Full
|
|||
// Stable kernel types: the ones that are stable and will run in AppVeyor
|
||||
public static IEnumerable<Type> GetStableKernelTypes()
|
||||
{
|
||||
yield return typeof(BoxingTests.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.TypeSystem.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.Bcl.System.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
|
||||
yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
|
||||
yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);
|
||||
yield return typeof(SimpleStructsAndArraysTest.Kernel);
|
||||
yield return typeof(Cosmos.Kernel.Tests.DiskManager.Kernel);
|
||||
//yield return typeof(BoxingTests.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.TypeSystem.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.Bcl.System.Kernel);
|
||||
////yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
|
||||
//yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
|
||||
//yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
|
||||
//yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);
|
||||
//yield return typeof(SimpleStructsAndArraysTest.Kernel);
|
||||
//yield return typeof(Cosmos.Kernel.Tests.DiskManager.Kernel);
|
||||
|
||||
//yield return typeof(KernelGen3.Boot);
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ namespace Cosmos.TestRunner.Full
|
|||
/* 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 */
|
||||
yield return typeof(MemoryOperationsTest.Kernel);
|
||||
//yield return typeof(MemoryOperationsTest.Kernel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@ namespace GraphicTest
|
|||
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");
|
||||
|
||||
canvas = FullScreenCanvas.GetFullScreenCanvas();
|
||||
}
|
||||
|
||||
private void DoTest(Canvas aCanvas)
|
||||
|
|
@ -113,7 +110,7 @@ namespace GraphicTest
|
|||
aCanvas.DrawEllipse(pen, 100, 69, 10, 50);
|
||||
|
||||
aCanvas.Disable();
|
||||
|
||||
Console.WriteLine("Back in text mode");
|
||||
|
||||
mDebugger.Send($"Test of Canvas with mode {aCanvas.Mode} executed successfully");
|
||||
}
|
||||
|
|
@ -126,7 +123,15 @@ namespace GraphicTest
|
|||
|
||||
TestBitmaps();
|
||||
|
||||
VGACanvas vGACanvas = new VGACanvas(new Mode(320, 200, ColorDepth.ColorDepth8));
|
||||
DoTest(vGACanvas);
|
||||
vGACanvas = new VGACanvas(new Mode(720, 480, ColorDepth.ColorDepth4));
|
||||
DoTest(vGACanvas);
|
||||
vGACanvas = new VGACanvas(new Mode(320, 200, ColorDepth.ColorDepth8));
|
||||
DoTest(vGACanvas);
|
||||
|
||||
/* First test with the DefaultMode */
|
||||
canvas = FullScreenCanvas.GetFullScreenCanvas();
|
||||
DoTest(canvas);
|
||||
|
||||
DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(800, 600, ColorDepth.ColorDepth32)));
|
||||
|
|
@ -144,6 +149,36 @@ namespace GraphicTest
|
|||
}
|
||||
}
|
||||
|
||||
private void DoTest(VGACanvas vGACanvas)
|
||||
{
|
||||
mDebugger.Send($"Testing VGA Canvas with mode {vGACanvas.Mode}");
|
||||
vGACanvas.Clear();
|
||||
vGACanvas.Clear(Color.Blue);
|
||||
for (int x = 0; x < 20; x++)
|
||||
{
|
||||
for (int y = 0; y < 20; y++)
|
||||
{
|
||||
vGACanvas.DrawPoint((uint)(x % (int)vGACanvas.Mode.ColorDepth), 5 + x, 5 + y);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < 20; x++)
|
||||
{
|
||||
for (int y = 0; y < 20; y++)
|
||||
{
|
||||
vGACanvas.DrawPoint((uint)((x + 1) % (int)vGACanvas.Mode.ColorDepth), 5 + x, 5 + y);
|
||||
}
|
||||
}
|
||||
|
||||
vGACanvas.Disable();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Console.WriteLine("Back in text mode");
|
||||
}
|
||||
|
||||
mDebugger.Send($"Test of Canvas with mode {vGACanvas.Mode} executed successfully");
|
||||
}
|
||||
|
||||
private void TestBitmaps()
|
||||
{
|
||||
Assert.IsTrue(bitmap.Width == 10 && bitmap.Height == 10, "Bitmap width and height set correctly");
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ namespace Cosmos.Core.IOGroup
|
|||
public readonly IOPortRead Instat_Read = new IOPortRead(0x3DA);
|
||||
|
||||
/// <summary>
|
||||
/// 64KB at 0xA0000
|
||||
/// 256KB at 0xA0000
|
||||
/// </summary>
|
||||
public readonly MemoryBlock08 VGAMemoryBlock = new MemoryBlock08(0xA0000, 1024 * 64);
|
||||
public readonly MemoryBlock08 VGAMemoryBlock = new MemoryBlock08(0xA0000, 1024 * 256);
|
||||
|
||||
/// <summary>
|
||||
/// 32KB at 0xB0000
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//#define COSMOSDEBUG
|
||||
#define COSMOSDEBUG
|
||||
|
||||
using System;
|
||||
using Cosmos.Core.IOGroup;
|
||||
|
|
@ -8,7 +8,7 @@ namespace Cosmos.HAL.Drivers
|
|||
public class VBEDriver
|
||||
{
|
||||
|
||||
private readonly Core.IOGroup.VBE IO = Core.Global.BaseIOGroups.VBE;
|
||||
private static readonly VBE IO = Core.Global.BaseIOGroups.VBE;
|
||||
|
||||
private enum RegisterIndex
|
||||
{
|
||||
|
|
@ -44,7 +44,7 @@ namespace Cosmos.HAL.Drivers
|
|||
VBESet(xres, yres, bpp);
|
||||
}
|
||||
|
||||
private void Write(RegisterIndex index, ushort value)
|
||||
private static void VBEWrite(RegisterIndex index, ushort value)
|
||||
{
|
||||
IO.VbeIndex.Word = (ushort) index;
|
||||
IO.VbeData.Word = value;
|
||||
|
|
@ -52,10 +52,8 @@ namespace Cosmos.HAL.Drivers
|
|||
|
||||
private static ushort VBERead(RegisterIndex index)
|
||||
{
|
||||
VBE io = Core.Global.BaseIOGroups.VBE;
|
||||
|
||||
io.VbeIndex.Word = (ushort)index;
|
||||
return io.VbeIndex.Word;
|
||||
IO.VbeIndex.Word = (ushort)index;
|
||||
return IO.VbeData.Word;
|
||||
}
|
||||
public static bool Available()
|
||||
{
|
||||
|
|
@ -63,38 +61,37 @@ namespace Cosmos.HAL.Drivers
|
|||
#if false
|
||||
return HAL.PCI.GetDevice(VendorID.Bochs, DeviceID.BGA) != null;
|
||||
#endif
|
||||
return true;
|
||||
// return VBERead(RegisterIndex.DisplayID) == 0xB0C5; - this is also not working. The same problem?
|
||||
return VBERead(RegisterIndex.DisplayID) == 0xB0C5;
|
||||
}
|
||||
|
||||
public void DisableDisplay()
|
||||
{
|
||||
Global.mDebugger.SendInternal($"Disabling VBE display");
|
||||
Write(RegisterIndex.DisplayEnable, (ushort)EnableValues.Disabled);
|
||||
VBEWrite(RegisterIndex.DisplayEnable, (ushort)EnableValues.Disabled);
|
||||
}
|
||||
|
||||
private void SetXResolution(ushort xres)
|
||||
{
|
||||
Global.mDebugger.SendInternal($"VBE Setting X resolution to {xres}");
|
||||
Write(RegisterIndex.DisplayXResolution, xres);
|
||||
VBEWrite(RegisterIndex.DisplayXResolution, xres);
|
||||
}
|
||||
|
||||
private void SetYResolution(ushort yres)
|
||||
{
|
||||
Global.mDebugger.SendInternal($"VBE Setting Y resolution to {yres}");
|
||||
Write(RegisterIndex.DisplayYResolution, yres);
|
||||
VBEWrite(RegisterIndex.DisplayYResolution, yres);
|
||||
}
|
||||
|
||||
private void SetDisplayBPP(ushort bpp)
|
||||
{
|
||||
Global.mDebugger.SendInternal($"VBE Setting BPP to {bpp}");
|
||||
Write(RegisterIndex.DisplayBPP, bpp);
|
||||
VBEWrite(RegisterIndex.DisplayBPP, bpp);
|
||||
}
|
||||
|
||||
private void EnableDisplay(EnableValues EnableFlags)
|
||||
{
|
||||
//Global.mDebugger.SendInternal($"VBE Enabling display with EnableFlags (ushort){EnableFlags}");
|
||||
Write(RegisterIndex.DisplayEnable, (ushort)EnableFlags);
|
||||
VBEWrite(RegisterIndex.DisplayEnable, (ushort)EnableFlags);
|
||||
}
|
||||
|
||||
public void VBESet(ushort xres, ushort yres, ushort bpp)
|
||||
|
|
|
|||
|
|
@ -17,84 +17,89 @@ namespace Cosmos.HAL
|
|||
public class VGADriver
|
||||
{
|
||||
internal Debugger mDebugger = new Debugger("HAL", "VGA");
|
||||
private const byte NumSeqRegs = 5;
|
||||
private const byte NumCRTCRegs = 25;
|
||||
private const byte NumGCRegs = 9;
|
||||
private const byte NumACRegs = 21;
|
||||
private const byte _NumSeqRegs = 5;
|
||||
private const byte _NumCRTCRegs = 25;
|
||||
private const byte _NumGCRegs = 9;
|
||||
private const byte _NumACRegs = 21;
|
||||
|
||||
private readonly Core.IOGroup.VGA mIO = new Core.IOGroup.VGA();
|
||||
Mode _Mode;
|
||||
ScreenSize _ScreenSize;
|
||||
ColorDepth _ColorDepth;
|
||||
|
||||
private void WriteVGARegisters(byte[] registers)
|
||||
private readonly Core.IOGroup.VGA _MIO = new Core.IOGroup.VGA();
|
||||
|
||||
private void WriteVGARegisters(byte[] aRegisters)
|
||||
{
|
||||
int xIdx = 0;
|
||||
byte i;
|
||||
|
||||
/* write MISCELLANEOUS reg */
|
||||
mIO.MiscellaneousOutput_Write.Byte = registers[xIdx];
|
||||
_MIO.MiscellaneousOutput_Write.Byte = aRegisters[xIdx];
|
||||
xIdx++;
|
||||
/* write SEQUENCER regs */
|
||||
for (i = 0; i < NumSeqRegs; i++)
|
||||
for (i = 0; i < _NumSeqRegs; i++)
|
||||
{
|
||||
mIO.Sequencer_Index.Byte = i;
|
||||
mIO.Sequencer_Data.Byte = registers[xIdx];
|
||||
_MIO.Sequencer_Index.Byte = i;
|
||||
_MIO.Sequencer_Data.Byte = aRegisters[xIdx];
|
||||
xIdx++;
|
||||
}
|
||||
/* unlock CRTC registers */
|
||||
mIO.CRTController_Index.Byte = 0x03;
|
||||
mIO.CRTController_Data.Byte = (byte)(mIO.CRTController_Data.Byte | 0x80);
|
||||
mIO.CRTController_Index.Byte = 0x11;
|
||||
mIO.CRTController_Data.Byte = (byte)(mIO.CRTController_Data.Byte & 0x7F);
|
||||
_MIO.CRTController_Index.Byte = 0x03;
|
||||
_MIO.CRTController_Data.Byte = (byte)(_MIO.CRTController_Data.Byte | 0x80);
|
||||
_MIO.CRTController_Index.Byte = 0x11;
|
||||
_MIO.CRTController_Data.Byte = (byte)(_MIO.CRTController_Data.Byte & 0x7F);
|
||||
|
||||
/* make sure they remain unlocked */
|
||||
registers[0x03] |= 0x80;
|
||||
registers[0x11] &= 0x7f;
|
||||
aRegisters[0x03] |= 0x80;
|
||||
aRegisters[0x11] &= 0x7f;
|
||||
|
||||
/* write CRTC regs */
|
||||
for (i = 0; i < NumCRTCRegs; i++)
|
||||
for (i = 0; i < _NumCRTCRegs; i++)
|
||||
{
|
||||
mIO.CRTController_Index.Byte = i;
|
||||
mIO.CRTController_Data.Byte = registers[xIdx];
|
||||
_MIO.CRTController_Index.Byte = i;
|
||||
_MIO.CRTController_Data.Byte = aRegisters[xIdx];
|
||||
xIdx++;
|
||||
}
|
||||
/* write GRAPHICS CONTROLLER regs */
|
||||
for (i = 0; i < NumGCRegs; i++)
|
||||
for (i = 0; i < _NumGCRegs; i++)
|
||||
{
|
||||
mIO.GraphicsController_Index.Byte = i;
|
||||
mIO.GraphicsController_Data.Byte = registers[xIdx];
|
||||
_MIO.GraphicsController_Index.Byte = i;
|
||||
_MIO.GraphicsController_Data.Byte = aRegisters[xIdx];
|
||||
xIdx++;
|
||||
}
|
||||
/* write ATTRIBUTE CONTROLLER regs */
|
||||
for (i = 0; i < NumACRegs; i++)
|
||||
for (i = 0; i < _NumACRegs; i++)
|
||||
{
|
||||
var xDoSomething = mIO.Instat_Read.Byte;
|
||||
mIO.AttributeController_Index.Byte = i;
|
||||
mIO.AttributeController_Write.Byte = registers[xIdx];
|
||||
var _ = _MIO.Instat_Read.Byte;
|
||||
_MIO.AttributeController_Index.Byte = i;
|
||||
_MIO.AttributeController_Write.Byte = aRegisters[xIdx];
|
||||
xIdx++;
|
||||
}
|
||||
/* lock 16-color palette and unblank display */
|
||||
var xNothing = mIO.Instat_Read.Byte;
|
||||
mIO.AttributeController_Index.Byte = 0x20;
|
||||
_ = _MIO.Instat_Read.Byte;
|
||||
_MIO.AttributeController_Index.Byte = 0x20;
|
||||
mDebugger.Send("Finished writing VGA registers");
|
||||
}
|
||||
|
||||
private void SetPlane(byte p)
|
||||
private void SetPlane(byte aP)
|
||||
{
|
||||
byte pmask;
|
||||
|
||||
p &= 3;
|
||||
pmask = (byte)(1 << p);
|
||||
aP &= 3;
|
||||
pmask = (byte)(1 << aP);
|
||||
/* set read plane */
|
||||
mIO.GraphicsController_Index.Byte = 4;
|
||||
mIO.GraphicsController_Data.Byte = p;
|
||||
_MIO.GraphicsController_Index.Byte = 4;
|
||||
_MIO.GraphicsController_Data.Byte = aP;
|
||||
/* set write plane */
|
||||
mIO.Sequencer_Index.Byte = 2;
|
||||
mIO.Sequencer_Data.Byte = pmask;
|
||||
_MIO.Sequencer_Index.Byte = 2;
|
||||
_MIO.Sequencer_Data.Byte = pmask;
|
||||
}
|
||||
|
||||
//int offset = 0xb8000;
|
||||
private MemoryBlock08 GetFramebufferSegment()
|
||||
{
|
||||
mIO.GraphicsController_Index.Byte = 6;
|
||||
int seg = mIO.GraphicsController_Data.Byte;
|
||||
_MIO.GraphicsController_Index.Byte = 6;
|
||||
int seg = _MIO.GraphicsController_Data.Byte;
|
||||
mDebugger.Send($"VGA: raw seg value: {seg}");
|
||||
seg >>= 2;
|
||||
|
||||
|
|
@ -103,45 +108,45 @@ namespace Cosmos.HAL
|
|||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return mIO.VGAMemoryBlock;
|
||||
return _MIO.VGAMemoryBlock;
|
||||
case 2:
|
||||
return mIO.MonochromeTextMemoryBlock;
|
||||
return _MIO.MonochromeTextMemoryBlock;
|
||||
case 3:
|
||||
return mIO.CGATextMemoryBlock;
|
||||
return _MIO.CGATextMemoryBlock;
|
||||
}
|
||||
throw new Exception("Unable to determine memory segment!");
|
||||
}
|
||||
|
||||
private void WriteFont(byte[] font, byte font_height)
|
||||
private void WriteFont(byte[] aFont, byte aFontHeight)
|
||||
{
|
||||
byte seq2, seq4, gc4, gc5, gc6;
|
||||
|
||||
/* save registers
|
||||
set_plane() modifies GC 4 and SEQ 2, so save them as well */
|
||||
mIO.Sequencer_Index.Byte = 2;
|
||||
seq2 = mIO.Sequencer_Data.Byte;
|
||||
_MIO.Sequencer_Index.Byte = 2;
|
||||
seq2 = _MIO.Sequencer_Data.Byte;
|
||||
|
||||
mIO.Sequencer_Index.Byte = 4;
|
||||
seq4 = mIO.Sequencer_Data.Byte;
|
||||
_MIO.Sequencer_Index.Byte = 4;
|
||||
seq4 = _MIO.Sequencer_Data.Byte;
|
||||
|
||||
/* turn off even-odd addressing (set flat addressing)
|
||||
assume: chain-4 addressing already off */
|
||||
mIO.Sequencer_Data.Byte = (byte)(seq4 | 0x04);
|
||||
_MIO.Sequencer_Data.Byte = (byte)(seq4 | 0x04);
|
||||
|
||||
mIO.GraphicsController_Index.Byte = 4;
|
||||
gc4 = mIO.GraphicsController_Data.Byte;
|
||||
_MIO.GraphicsController_Index.Byte = 4;
|
||||
gc4 = _MIO.GraphicsController_Data.Byte;
|
||||
|
||||
mIO.GraphicsController_Index.Byte = 5;
|
||||
gc5 = mIO.GraphicsController_Data.Byte;
|
||||
_MIO.GraphicsController_Index.Byte = 5;
|
||||
gc5 = _MIO.GraphicsController_Data.Byte;
|
||||
|
||||
/* turn off even-odd addressing */
|
||||
mIO.GraphicsController_Data.Byte = (byte)(gc5 & ~0x10);
|
||||
_MIO.GraphicsController_Data.Byte = (byte)(gc5 & ~0x10);
|
||||
|
||||
mIO.GraphicsController_Index.Byte = 6;
|
||||
gc6 = mIO.GraphicsController_Data.Byte;
|
||||
_MIO.GraphicsController_Index.Byte = 6;
|
||||
gc6 = _MIO.GraphicsController_Data.Byte;
|
||||
|
||||
/* turn off even-odd addressing */
|
||||
mIO.GraphicsController_Data.Byte = (byte)(gc6 & ~0x02);
|
||||
_MIO.GraphicsController_Data.Byte = (byte)(gc6 & ~0x02);
|
||||
|
||||
/* write font to plane P4 */
|
||||
SetPlane(2);
|
||||
|
|
@ -152,50 +157,128 @@ namespace Cosmos.HAL
|
|||
|
||||
for (uint i = 0; i < 256; i++)
|
||||
{
|
||||
for (uint j = 0; j < font_height; j++)
|
||||
for (uint j = 0; j < aFontHeight; j++)
|
||||
{
|
||||
seg[(i * 32) + j] = font[(i * font_height) + j];
|
||||
seg[(i * 32) + j] = aFont[(i * aFontHeight) + j];
|
||||
}
|
||||
}
|
||||
|
||||
/* restore registers */
|
||||
mIO.Sequencer_Index.Byte = 2;
|
||||
mIO.Sequencer_Data.Byte = seq2;
|
||||
mIO.Sequencer_Index.Byte = 4;
|
||||
mIO.Sequencer_Data.Byte = seq4;
|
||||
mIO.GraphicsController_Index.Byte = 4;
|
||||
mIO.GraphicsController_Data.Byte = gc4;
|
||||
mIO.GraphicsController_Index.Byte = 5;
|
||||
mIO.GraphicsController_Data.Byte = gc5;
|
||||
mIO.GraphicsController_Index.Byte = 6;
|
||||
mIO.GraphicsController_Data.Byte = gc6;
|
||||
_MIO.Sequencer_Index.Byte = 2;
|
||||
_MIO.Sequencer_Data.Byte = seq2;
|
||||
_MIO.Sequencer_Index.Byte = 4;
|
||||
_MIO.Sequencer_Data.Byte = seq4;
|
||||
_MIO.GraphicsController_Index.Byte = 4;
|
||||
_MIO.GraphicsController_Data.Byte = gc4;
|
||||
_MIO.GraphicsController_Index.Byte = 5;
|
||||
_MIO.GraphicsController_Data.Byte = gc5;
|
||||
_MIO.GraphicsController_Index.Byte = 6;
|
||||
_MIO.GraphicsController_Data.Byte = gc6;
|
||||
}
|
||||
|
||||
public SetPixelDelegate SetPixel;
|
||||
public GetPixelDelegate GetPixel;
|
||||
|
||||
public VGADriver()
|
||||
{
|
||||
SetPixel = new SetPixelDelegate(SetPixelNoMode);
|
||||
GetPixel = new GetPixelDelegate(GetPixelNoMode);
|
||||
}
|
||||
|
||||
public delegate void SetPixelDelegate(uint x, uint y, uint c);
|
||||
|
||||
public delegate uint GetPixelDelegate(uint x, uint y);
|
||||
|
||||
public uint this[uint x, uint y]
|
||||
public void SetPixel(uint aX, uint aY, uint aColor)
|
||||
{
|
||||
get
|
||||
//Global.mDebugger.Send($"Setting pixel: ({x}, {y}) to {color}");
|
||||
if(_Mode == Mode.Text)
|
||||
{
|
||||
return GetPixel(x, y);
|
||||
throw new Exception("Cannot set pixel in text mode");
|
||||
}
|
||||
set
|
||||
switch (_ScreenSize)
|
||||
{
|
||||
SetPixel(x, y, value);
|
||||
case ScreenSize.Size640x480:
|
||||
switch (_ColorDepth)
|
||||
{
|
||||
case ColorDepth.BitDepth2:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth4:
|
||||
SetPixel640x480x4(aX, aY, aColor);
|
||||
break;
|
||||
case ColorDepth.BitDepth8:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth16:
|
||||
throw new NotImplementedException();
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
break;
|
||||
case ScreenSize.Size720x480:
|
||||
switch (_ColorDepth)
|
||||
{
|
||||
case ColorDepth.BitDepth2:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth4:
|
||||
SetPixel720x480x4(aX, aY, aColor);
|
||||
break;
|
||||
case ColorDepth.BitDepth8:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth16:
|
||||
throw new NotImplementedException();
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
break;
|
||||
case ScreenSize.Size320x200:
|
||||
switch (_ColorDepth)
|
||||
{
|
||||
case ColorDepth.BitDepth2:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth4:
|
||||
throw new NotImplementedException();
|
||||
case ColorDepth.BitDepth8:
|
||||
SetPixel320x200x8(aX, aY, aColor);
|
||||
break;
|
||||
case ColorDepth.BitDepth16:
|
||||
throw new NotImplementedException();
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public uint GetPixel(uint aX, uint aY)
|
||||
{
|
||||
Global.mDebugger.Send($"GetPixel: ({aX},{aY})");
|
||||
if (_Mode == Mode.Text)
|
||||
{
|
||||
throw new Exception("Cannot get pixel in text mode");
|
||||
}
|
||||
return _ScreenSize switch
|
||||
{
|
||||
ScreenSize.Size640x480 => _ColorDepth switch
|
||||
{
|
||||
ColorDepth.BitDepth2 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth4 => GetPixel640x480x4(aX, aY),
|
||||
ColorDepth.BitDepth8 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth16 => throw new NotImplementedException(),
|
||||
_ => throw new NotImplementedException(),
|
||||
},
|
||||
ScreenSize.Size720x480 => _ColorDepth switch
|
||||
{
|
||||
ColorDepth.BitDepth2 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth4 => GetPixel720x480x4(aX, aY),
|
||||
ColorDepth.BitDepth8 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth16 => throw new NotImplementedException(),
|
||||
_ => throw new NotImplementedException(),
|
||||
},
|
||||
ScreenSize.Size320x200 => _ColorDepth switch
|
||||
{
|
||||
ColorDepth.BitDepth2 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth4 => throw new NotImplementedException(),
|
||||
ColorDepth.BitDepth8 => GetPixel320x200x8(aX, aY),
|
||||
ColorDepth.BitDepth16 => throw new NotImplementedException(),
|
||||
_ => throw new NotImplementedException(),
|
||||
},
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
|
||||
public enum TextSize
|
||||
{
|
||||
Size40x25,
|
||||
|
|
@ -226,39 +309,41 @@ namespace Cosmos.HAL
|
|||
|
||||
public enum ColorDepth
|
||||
{
|
||||
BitDepth2,
|
||||
BitDepth4,
|
||||
BitDepth8,
|
||||
BitDepth16
|
||||
BitDepth2=2,
|
||||
BitDepth4=4,
|
||||
BitDepth8=8,
|
||||
BitDepth16=16
|
||||
};
|
||||
|
||||
public void SetTextMode(TextSize aSize)
|
||||
{
|
||||
mDebugger.Send("Setting TextMode:" + aSize.ToString());
|
||||
_Mode = Mode.Text;
|
||||
switch (aSize)
|
||||
{
|
||||
case TextSize.Size40x25:
|
||||
WriteVGARegisters(g_40x25_text);
|
||||
WriteFont(g_8x16_font, 16);
|
||||
WriteVGARegisters(_G_40x25_text);
|
||||
WriteFont(_G_8x16_font, 16);
|
||||
break;
|
||||
case TextSize.Size40x50:
|
||||
WriteVGARegisters(g_40x50_text);
|
||||
WriteFont(g_8x8_font, 8);
|
||||
WriteVGARegisters(_G_40x50_text);
|
||||
WriteFont(_G_8x8_font, 8);
|
||||
break;
|
||||
case TextSize.Size80x25:
|
||||
WriteVGARegisters(g_80x25_text);
|
||||
WriteFont(g_8x16_font, 16);
|
||||
WriteVGARegisters(_G_80x25_text);
|
||||
WriteFont(_G_8x16_font, 16);
|
||||
break;
|
||||
case TextSize.Size80x50:
|
||||
WriteVGARegisters(g_80x50_text);
|
||||
WriteFont(g_8x8_font, 8);
|
||||
WriteVGARegisters(_G_80x50_text);
|
||||
WriteFont(_G_8x8_font, 8);
|
||||
break;
|
||||
case TextSize.Size90x30:
|
||||
WriteVGARegisters(g_90x30_text);
|
||||
WriteFont(g_8x16_font, 16);
|
||||
WriteVGARegisters(_G_90x30_text);
|
||||
WriteFont(_G_8x16_font, 16);
|
||||
break;
|
||||
case TextSize.Size90x60:
|
||||
WriteVGARegisters(g_90x60_text);
|
||||
WriteFont(g_8x8_font, 8);
|
||||
WriteVGARegisters(_G_90x60_text);
|
||||
WriteFont(_G_8x8_font, 8);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid text size.");
|
||||
|
|
@ -267,75 +352,74 @@ namespace Cosmos.HAL
|
|||
|
||||
public void SetGraphicsMode(ScreenSize aSize, ColorDepth aDepth)
|
||||
{
|
||||
mDebugger.Send("Setting GraphicsMode:" + ((int)aSize).ToString() + " - " + ((int)aDepth).ToString());
|
||||
_ScreenSize = aSize;
|
||||
_ColorDepth = aDepth;
|
||||
_Mode = Mode.Graphical;
|
||||
switch (aSize)
|
||||
{
|
||||
case ScreenSize.Size320x200:
|
||||
if (aDepth == ColorDepth.BitDepth8)
|
||||
{
|
||||
mDebugger.Send("Setting graphic mode to 320x200@256");
|
||||
WriteVGARegisters(g_320x200x8);
|
||||
WriteVGARegisters(_G_320x200x8);
|
||||
|
||||
PixelWidth = 320;
|
||||
PixelHeight = 200;
|
||||
Colors = 256;
|
||||
SetPixel = new SetPixelDelegate(SetPixel320x200x8);
|
||||
GetPixel = new GetPixelDelegate(GetPixel320x200x8);
|
||||
}
|
||||
else if (aDepth == ColorDepth.BitDepth4)
|
||||
{
|
||||
WriteVGARegisters(g_320x200x4);
|
||||
mDebugger.Send("Setting graphic mode to 320x200@16");
|
||||
WriteVGARegisters(_G_320x200x4);
|
||||
|
||||
PixelWidth = 320;
|
||||
PixelHeight = 200;
|
||||
Colors = 16;
|
||||
//SetPixel = new SetPixelDelegate(SetPixel320x200x4);
|
||||
//GetPixel = new GetPixelDelegate(GetPixel320x200x4);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsupported color depth passed for specified screen size");
|
||||
throw new Exception($"Unsupported color depth {aDepth} passed for specified screen size");
|
||||
}
|
||||
break;
|
||||
case ScreenSize.Size640x480:
|
||||
if (aDepth == ColorDepth.BitDepth2)
|
||||
{
|
||||
WriteVGARegisters(g_640x480x2);
|
||||
mDebugger.Send("Setting graphic mode to 640x480@4");
|
||||
WriteVGARegisters(_G_640x480x2);
|
||||
|
||||
PixelWidth = 640;
|
||||
PixelHeight = 480;
|
||||
Colors = 4;
|
||||
//SetPixel = new SetPixelDelegate(SetPixel640x480x2);
|
||||
//GetPixel = new GetPixelDelegate(GetPixel640x480x2);
|
||||
}
|
||||
else if (aDepth == ColorDepth.BitDepth4)
|
||||
{
|
||||
WriteVGARegisters(g_640x480x4);
|
||||
mDebugger.Send("Setting graphic mode to 640x480@16");
|
||||
|
||||
WriteVGARegisters(_G_640x480x4);
|
||||
|
||||
PixelWidth = 640;
|
||||
PixelHeight = 480;
|
||||
Colors = 16;
|
||||
SetPixel = new SetPixelDelegate(SetPixel640x480x4);
|
||||
GetPixel = new GetPixelDelegate(GetPixel640x480x4);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsupported color depth passed for specified screen size");
|
||||
throw new Exception($"Unsupported color depth {aDepth} passed for specified screen size");
|
||||
}
|
||||
break;
|
||||
case ScreenSize.Size720x480:
|
||||
if (aDepth == ColorDepth.BitDepth4)
|
||||
{
|
||||
WriteVGARegisters(g_720x480x4);
|
||||
mDebugger.Send("Setting graphic mode to 720x480@16");
|
||||
WriteVGARegisters(_G_720x480x4);
|
||||
|
||||
PixelWidth = 720;
|
||||
PixelHeight = 480;
|
||||
Colors = 16;
|
||||
SetPixel = new SetPixelDelegate(SetPixel720x480x4);
|
||||
GetPixel = new GetPixelDelegate(GetPixel720x480x4);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsupported color depth passed for specified screen size");
|
||||
throw new Exception($"Unsupported color depth {aDepth} passed for specified screen size");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
@ -343,56 +427,52 @@ namespace Cosmos.HAL
|
|||
}
|
||||
}
|
||||
|
||||
//public void SetPixel320x200x4(uint x, uint y, uint c);
|
||||
//public uint GetPixel320x200x4(uint x, uint y);
|
||||
public void SetPixel320x200x8(uint x, uint y, uint c)
|
||||
public void SetPixel320x200x8(uint aX, uint aY, uint aC)
|
||||
{
|
||||
uint where = (y * 320) + x;
|
||||
byte color = (byte)(c & 0xFF);
|
||||
uint where = (aY * 320) + aX;
|
||||
byte color = (byte)(aC & 0xFF);
|
||||
|
||||
mDebugger.Send($"Drawing pixel at {where}, with color {color}");
|
||||
mIO.VGAMemoryBlock[where] = color;
|
||||
mDebugger.Send($"Pixel drawn but you cannot see it!");
|
||||
_MIO.VGAMemoryBlock[where] = color;
|
||||
}
|
||||
|
||||
public uint GetPixel320x200x8(uint x, uint y)
|
||||
public uint GetPixel320x200x8(uint aX, uint aY)
|
||||
{
|
||||
return mIO.VGAMemoryBlock[(y * 320) + x];
|
||||
mDebugger.Send($"GetPixel320x200x8({aX},{aY})");
|
||||
return _MIO.VGAMemoryBlock[(aY * 320) + aX];
|
||||
}
|
||||
|
||||
//public void SetPixel640x480x2(uint x, uint y, uint c);
|
||||
//public uint GetPixel640x480x2(uint x, uint y);
|
||||
|
||||
public void SetPixel640x480x4(uint x, uint y, uint c)
|
||||
public void SetPixel640x480x4(uint aX, uint aY, uint aC)
|
||||
{
|
||||
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);
|
||||
uint offset = (uint)(aX / 8 + (PixelWidth / 8) * aY);
|
||||
|
||||
x = (x & 7) * 1;
|
||||
aX = (aX & 7) * 1;
|
||||
|
||||
uint mask = (byte)(0x80 >> (int)x);
|
||||
uint mask = (byte)(0x80 >> (int)aX);
|
||||
uint pmask = 1;
|
||||
|
||||
for (byte p = 0; p < 4; p++)
|
||||
{
|
||||
SetPlane(p);
|
||||
|
||||
if ((pmask & c) != 0)
|
||||
if ((pmask & aC) != 0)
|
||||
{
|
||||
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] | mask);
|
||||
_MIO.VGAMemoryBlock[offset] = (byte)(_MIO.VGAMemoryBlock[offset] | mask);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] & ~mask);
|
||||
_MIO.VGAMemoryBlock[offset] = (byte)(_MIO.VGAMemoryBlock[offset] & ~mask);
|
||||
}
|
||||
|
||||
pmask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
public uint GetPixel640x480x4(uint x, uint y)
|
||||
public uint GetPixel640x480x4(uint aX, uint aY)
|
||||
{
|
||||
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);
|
||||
mDebugger.Send($"GetPixel640x480x4({aX},{aY})");
|
||||
uint offset = (uint)(aX / 8 + (PixelWidth / 8) * aY);
|
||||
|
||||
uint pmask = 1;
|
||||
|
||||
|
|
@ -402,7 +482,7 @@ namespace Cosmos.HAL
|
|||
{
|
||||
SetPlane(p);
|
||||
|
||||
if (mIO.VGAMemoryBlock[offset] == 255)
|
||||
if (_MIO.VGAMemoryBlock[offset] == 255)
|
||||
{
|
||||
color += pmask;
|
||||
}
|
||||
|
|
@ -413,36 +493,38 @@ namespace Cosmos.HAL
|
|||
return color;
|
||||
}
|
||||
|
||||
public void SetPixel720x480x4(uint x, uint y, uint c)
|
||||
public void SetPixel720x480x4(uint aX, uint aY, uint aC)
|
||||
{
|
||||
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);
|
||||
uint offset = (uint)(aX / 8 + (PixelWidth / 8) * aY);
|
||||
|
||||
x = (x & 7) * 1;
|
||||
aX = (aX & 7) * 1;
|
||||
|
||||
uint mask = (byte)(0x80 >> (int)x);
|
||||
uint mask = (byte)(0x80 >> (int)aX);
|
||||
uint pmask = 1;
|
||||
|
||||
for (byte p = 0; p < 4; p++)
|
||||
{
|
||||
SetPlane(p);
|
||||
|
||||
if ((pmask & c) != 0)
|
||||
if ((pmask & aC) != 0)
|
||||
{
|
||||
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] | mask);
|
||||
_MIO.VGAMemoryBlock[offset] = (byte)(_MIO.VGAMemoryBlock[offset] | mask);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] & ~mask);
|
||||
_MIO.VGAMemoryBlock[offset] = (byte)(_MIO.VGAMemoryBlock[offset] & ~mask);
|
||||
}
|
||||
|
||||
pmask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
public uint GetPixel720x480x4(uint x, uint y)
|
||||
public uint GetPixel720x480x4(uint aX, uint aY)
|
||||
{
|
||||
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);
|
||||
mDebugger.Send($"GetPixel720x480x4({aX},{aY})");
|
||||
|
||||
uint offset = (uint)(aX / 8 + (PixelWidth / 8) * aY);
|
||||
|
||||
uint pmask = 1;
|
||||
|
||||
|
|
@ -452,7 +534,7 @@ namespace Cosmos.HAL
|
|||
{
|
||||
SetPlane(p);
|
||||
|
||||
if (mIO.VGAMemoryBlock[offset] == 255)
|
||||
if (_MIO.VGAMemoryBlock[offset] == 255)
|
||||
{
|
||||
color += pmask;
|
||||
}
|
||||
|
|
@ -463,16 +545,6 @@ namespace Cosmos.HAL
|
|||
return color;
|
||||
}
|
||||
|
||||
private void SetPixelNoMode(uint x, uint y, uint c)
|
||||
{
|
||||
throw new Exception("No video mode set!");
|
||||
}
|
||||
|
||||
private uint GetPixelNoMode(uint x, uint y)
|
||||
{
|
||||
throw new Exception("No video mode set!");
|
||||
}
|
||||
|
||||
public int PixelWidth { private set; get; }
|
||||
public int PixelHeight { private set; get; }
|
||||
public int Colors { private set; get; }
|
||||
|
|
@ -500,52 +572,43 @@ namespace Cosmos.HAL
|
|||
}
|
||||
}
|
||||
|
||||
public void Clear(int color)
|
||||
public void Clear(int aColor)
|
||||
{
|
||||
//TODO: Copy more memory at once
|
||||
for (int y = 0; y < PixelHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < PixelWidth; x++)
|
||||
{
|
||||
SetPixel((uint)x, (uint)y, (uint)color);
|
||||
SetPixel((uint)x, (uint)y, (uint)aColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Enable code that uses Color when we move to .NET Core 2.1 (plug won't be needed)
|
||||
private readonly Color[] _Palette = new Color[256];
|
||||
|
||||
//private Color[] _Palette = new Color[256];
|
||||
|
||||
//public Color GetPaletteEntry(int index)
|
||||
//{
|
||||
// return _Palette[index];
|
||||
//}
|
||||
|
||||
public void SetPalette(int index, byte[] pallete)
|
||||
public Color GetPaletteEntry(int aIndex)
|
||||
{
|
||||
mIO.DACIndex_Write.Byte = (byte)index;
|
||||
for (int i = 0; i < pallete.Length; i++)
|
||||
{
|
||||
mIO.DAC_Data.Byte = (byte)(pallete[i] >> 2);
|
||||
}
|
||||
return _Palette[aIndex];
|
||||
}
|
||||
|
||||
//public void SetPaletteEntry(int index, Color color)
|
||||
//{
|
||||
// SetPaletteEntry(index, color.R, color.G, color.B);
|
||||
//}
|
||||
|
||||
public void SetPaletteEntry(int index, byte r, byte g, byte b)
|
||||
public void SetPaletteEntry(int aIndex, Color aColor)
|
||||
{
|
||||
mIO.DACIndex_Write.Byte = (byte)index;
|
||||
mIO.DAC_Data.Byte = (byte)(r >> 2);
|
||||
mIO.DAC_Data.Byte = (byte)(g >> 2);
|
||||
mIO.DAC_Data.Byte = (byte)(b >> 2);
|
||||
_Palette[aIndex] = aColor;
|
||||
SetPaletteEntry(aIndex, aColor.R, aColor.G, aColor.B);
|
||||
}
|
||||
|
||||
public void SetPaletteEntry(int aIndex, byte aR, byte aG, byte aB)
|
||||
{
|
||||
_MIO.DACIndex_Write.Byte = (byte)aIndex;
|
||||
_MIO.DAC_Data.Byte = (byte)(aR >> 2);
|
||||
_MIO.DAC_Data.Byte = (byte)(aG >> 2);
|
||||
_MIO.DAC_Data.Byte = (byte)(aB >> 2);
|
||||
}
|
||||
|
||||
|
||||
#region FONTS
|
||||
|
||||
private static byte[] g_8x8_font = new byte[]
|
||||
private static readonly byte[] _G_8x8_font = new byte[]
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E,
|
||||
|
|
@ -805,7 +868,7 @@ namespace Cosmos.HAL
|
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
private static byte[] g_8x16_font = new byte[]
|
||||
private static readonly byte[] _G_8x16_font = new byte[]
|
||||
{
|
||||
|
||||
// juptitor
|
||||
|
|
@ -1078,7 +1141,7 @@ namespace Cosmos.HAL
|
|||
|
||||
#region MODES
|
||||
|
||||
private static byte[] g_640x480x4 = new byte[]
|
||||
private static readonly byte[] _G_640x480x4 = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0xE3,
|
||||
|
|
@ -1098,7 +1161,7 @@ namespace Cosmos.HAL
|
|||
0x01, 0x00, 0x0F, 0x00, 0x00
|
||||
};
|
||||
|
||||
private static byte[] g_320x200x8 = new byte[]
|
||||
private static readonly byte[] _G_320x200x8 = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x63,
|
||||
|
|
@ -1118,7 +1181,7 @@ namespace Cosmos.HAL
|
|||
0x41, 0x00, 0x0F, 0x00, 0x00
|
||||
};
|
||||
|
||||
private static byte[] g_80x50_text = new byte[]
|
||||
private static readonly byte[] _G_80x50_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x67,
|
||||
|
|
@ -1138,7 +1201,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_720x480x4 = new byte[]
|
||||
private static readonly byte[] _G_720x480x4 = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0xE7,
|
||||
|
|
@ -1158,7 +1221,7 @@ namespace Cosmos.HAL
|
|||
0x01, 0x00, 0x0F, 0x00, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_90x30_text = new byte[]
|
||||
private static readonly byte[] _G_90x30_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0xE7,
|
||||
|
|
@ -1178,7 +1241,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_90x60_text = new byte[]
|
||||
private static readonly byte[] _G_90x60_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0xE7,
|
||||
|
|
@ -1198,7 +1261,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_40x25_text = new byte[]
|
||||
private static readonly byte[] _G_40x25_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x67,
|
||||
|
|
@ -1218,7 +1281,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_40x50_text = new byte[]
|
||||
private static readonly byte[] _G_40x50_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x67,
|
||||
|
|
@ -1238,7 +1301,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00,
|
||||
};
|
||||
|
||||
private static byte[] g_80x25_text = new byte[]
|
||||
private static readonly byte[] _G_80x25_text = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x67,
|
||||
|
|
@ -1258,7 +1321,7 @@ namespace Cosmos.HAL
|
|||
0x0C, 0x00, 0x0F, 0x08, 0x00
|
||||
};
|
||||
|
||||
private static byte[] g_320x200x4 = new byte[]
|
||||
private static readonly byte[] _G_320x200x4 = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0x63,
|
||||
|
|
@ -1278,7 +1341,7 @@ namespace Cosmos.HAL
|
|||
0x01, 0x00, 0x03, 0x00, 0x00
|
||||
};
|
||||
|
||||
private static byte[] g_640x480x2 = new byte[]
|
||||
private static readonly byte[] _G_640x480x2 = new byte[]
|
||||
{
|
||||
/* MISC */
|
||||
0xE3,
|
||||
|
|
@ -1299,5 +1362,7 @@ namespace Cosmos.HAL
|
|||
};
|
||||
|
||||
#endregion
|
||||
|
||||
private enum Mode { Text, Graphical}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,27 +133,12 @@ namespace Cosmos.HAL
|
|||
|
||||
public static bool Exists(PCIDevice pciDevice)
|
||||
{
|
||||
if (GetDevice((VendorID) pciDevice.VendorID, (DeviceID) pciDevice.DeviceID) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return GetDevice((VendorID)pciDevice.VendorID, (DeviceID)pciDevice.DeviceID) != null;
|
||||
}
|
||||
|
||||
public static bool Exists(VendorID aVendorID, DeviceID aDeviceID)
|
||||
{
|
||||
PCIDevice aDevice = GetDevice(aVendorID, aDeviceID);
|
||||
if (aDevice == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return GetDevice(aVendorID, aDeviceID) != null;
|
||||
}
|
||||
|
||||
public static PCIDevice GetDevice(VendorID aVendorID, DeviceID aDeviceID)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Cosmos.System.Graphics
|
|||
if (IsInUse)
|
||||
{
|
||||
_VideoDriver.Disable();
|
||||
VGAScreen.SetTextMode(VGAScreen.TextSize.Size80x25);
|
||||
VGAScreen.SetTextMode(VGADriver.TextSize.Size80x25);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ namespace Cosmos.System.Graphics
|
|||
{
|
||||
public override void Disable()
|
||||
{
|
||||
CanvasSVGADriver.Disable();
|
||||
_CanvasSVGADriver.Disable();
|
||||
}
|
||||
|
||||
internal Debugger mSVGAIIDebugger = new Debugger("System", "SVGAIIScreen");
|
||||
|
||||
private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth32);
|
||||
private static readonly Mode _DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth32);
|
||||
|
||||
private Mode _mode;
|
||||
private Mode _Mode;
|
||||
|
||||
private readonly VMWareSVGAII CanvasSVGADriver;
|
||||
private readonly VMWareSVGAII _CanvasSVGADriver;
|
||||
|
||||
public SVGAIICanvas()
|
||||
: this(DefaultMode)
|
||||
: this(_DefaultMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -33,49 +33,49 @@ namespace Cosmos.System.Graphics
|
|||
mSVGAIIDebugger.SendInternal($"Called ctor with mode {aMode}");
|
||||
ThrowIfModeIsNotValid(aMode);
|
||||
|
||||
CanvasSVGADriver = new VMWareSVGAII();
|
||||
_CanvasSVGADriver = new VMWareSVGAII();
|
||||
Mode = aMode;
|
||||
}
|
||||
|
||||
public override Mode Mode
|
||||
{
|
||||
get => _mode;
|
||||
get => _Mode;
|
||||
set
|
||||
{
|
||||
_mode = value;
|
||||
mSVGAIIDebugger.SendInternal($"Called Mode set property with mode {_mode}");
|
||||
SetGraphicsMode(_mode);
|
||||
_Mode = value;
|
||||
mSVGAIIDebugger.SendInternal($"Called Mode set property with mode {_Mode}");
|
||||
SetGraphicsMode(_Mode);
|
||||
}
|
||||
}
|
||||
|
||||
public override Mode DefaultGraphicMode => DefaultMode;
|
||||
public override Mode DefaultGraphicMode => _DefaultMode;
|
||||
|
||||
public override void DrawPoint(Pen pen, int x, int y)
|
||||
public override void DrawPoint(Pen aPen, int aX, int aY)
|
||||
{
|
||||
Color xColor = pen.Color;
|
||||
Color xColor = aPen.Color;
|
||||
|
||||
mSVGAIIDebugger.SendInternal($"Drawing point to x:{x}, y:{y} with {xColor.Name} Color");
|
||||
CanvasSVGADriver.SetPixel((uint)x, (uint)y, (uint)xColor.ToArgb());
|
||||
mSVGAIIDebugger.SendInternal($"Drawing point to x:{aX}, y:{aY} with {xColor.Name} Color");
|
||||
_CanvasSVGADriver.SetPixel((uint)aX, (uint)aY, (uint)xColor.ToArgb());
|
||||
mSVGAIIDebugger.SendInternal($"Done drawing point");
|
||||
/* No need to refresh all the screen to make the point appear on Screen! */
|
||||
//xSVGAIIDriver.Update((uint)x, (uint)y, (uint)mode.Columns, (uint)mode.Rows);
|
||||
CanvasSVGADriver.Update((uint)x, (uint)y, 1, 1);
|
||||
_CanvasSVGADriver.Update((uint)aX, (uint)aY, 1, 1);
|
||||
}
|
||||
|
||||
public override void DrawArray(Color[] colors, int x, int y, int width, int height)
|
||||
public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int aHeight)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//xSVGAIIDriver.
|
||||
}
|
||||
public override void DrawPoint(Pen pen, float x, float y)
|
||||
public override void DrawPoint(Pen aPen, float aX, float aY)
|
||||
{
|
||||
//xSVGAIIDriver.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int width, int height)
|
||||
public override void DrawFilledRectangle(Pen aPen, int aX_start, int aY_start, int aWidth, int aHeight)
|
||||
{
|
||||
CanvasSVGADriver.Fill((uint)x_start, (uint)y_start, (uint)width, (uint)height, (uint)pen.Color.ToArgb());
|
||||
_CanvasSVGADriver.Fill((uint)aX_start, (uint)aY_start, (uint)aWidth, (uint)aHeight, (uint)aPen.Color.ToArgb());
|
||||
}
|
||||
|
||||
//public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
|
||||
|
|
@ -167,44 +167,44 @@ namespace Cosmos.System.Graphics
|
|||
var xHeight = (uint)aMode.Rows;
|
||||
var xColorDepth = (uint)aMode.ColorDepth;
|
||||
|
||||
CanvasSVGADriver.SetMode(xWidth, xHeight, xColorDepth);
|
||||
_CanvasSVGADriver.SetMode(xWidth, xHeight, xColorDepth);
|
||||
}
|
||||
|
||||
public override void Clear(Color color)
|
||||
public override void Clear(Color aColor)
|
||||
{
|
||||
CanvasSVGADriver.Fill(0, 0, (uint)Mode.Columns, (uint)Mode.Rows, (uint)color.ToArgb());
|
||||
_CanvasSVGADriver.Fill(0, 0, (uint)Mode.Columns, (uint)Mode.Rows, (uint)aColor.ToArgb());
|
||||
}
|
||||
|
||||
public Color GetPixel(int aX, int aY)
|
||||
{
|
||||
var xColorARGB = CanvasSVGADriver.GetPixel((uint)aX, (uint)aX);
|
||||
var xColorARGB = _CanvasSVGADriver.GetPixel((uint)aX, (uint)aY);
|
||||
return Color.FromArgb((int)xColorARGB);
|
||||
}
|
||||
|
||||
public void SetCursor(bool aVisible, int aX, int aY)
|
||||
{
|
||||
CanvasSVGADriver.SetCursor(aVisible, (uint)aX, (uint)aY);
|
||||
_CanvasSVGADriver.SetCursor(aVisible, (uint)aX, (uint)aY);
|
||||
}
|
||||
|
||||
public void CreateCursor()
|
||||
{
|
||||
CanvasSVGADriver.DefineCursor();
|
||||
_CanvasSVGADriver.DefineCursor();
|
||||
}
|
||||
|
||||
public void CopyPixel(int aX, int aY, int aNewX, int aNewY, int aWidth = 1, int aHeight = 1)
|
||||
{
|
||||
CanvasSVGADriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, (uint)aWidth, (uint)aHeight);
|
||||
_CanvasSVGADriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, (uint)aWidth, (uint)aHeight);
|
||||
}
|
||||
|
||||
public void MovePixel(int aX, int aY, int aNewX, int aNewY)
|
||||
{
|
||||
CanvasSVGADriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, 1, 1);
|
||||
CanvasSVGADriver.SetPixel((uint)aX, (uint)aY, 0);
|
||||
_CanvasSVGADriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, 1, 1);
|
||||
_CanvasSVGADriver.SetPixel((uint)aX, (uint)aY, 0);
|
||||
}
|
||||
|
||||
public override Color GetPointColor(int x, int y)
|
||||
public override Color GetPointColor(int aX, int aY)
|
||||
{
|
||||
return Color.FromArgb((int)CanvasSVGADriver.GetPixel((uint)x, (uint)y));
|
||||
return Color.FromArgb((int)_CanvasSVGADriver.GetPixel((uint)aX, (uint)aY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,162 +3,189 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using Cosmos.HAL;
|
||||
using System.Drawing;
|
||||
using static Cosmos.HAL.VGADriver;
|
||||
|
||||
namespace Cosmos.System.Graphics
|
||||
{
|
||||
class VGACanvas : Canvas
|
||||
public class VGACanvas : Canvas
|
||||
{
|
||||
private VGADriver VGADriver;
|
||||
private readonly VGADriver _VGADriver;
|
||||
|
||||
public VGACanvas(Mode mode) : base()
|
||||
public VGACanvas(Mode aMode) : base()
|
||||
{
|
||||
|
||||
Global.mDebugger.Send("Creating VGACanvas with mode");
|
||||
_VGADriver = new VGADriver();
|
||||
_VGADriver.SetGraphicsMode(ModeToScreenSize(aMode), (VGADriver.ColorDepth)(int)aMode.ColorDepth);
|
||||
Mode = aMode;
|
||||
}
|
||||
|
||||
public VGACanvas() : base()
|
||||
{
|
||||
|
||||
Mode = DefaultGraphicMode;
|
||||
Global.mDebugger.Send("Creating VGACanvas with standard mode");
|
||||
_VGADriver = new VGADriver();
|
||||
_VGADriver.SetGraphicsMode(ModeToScreenSize(DefaultGraphicMode), (VGADriver.ColorDepth)(int)DefaultGraphicMode.ColorDepth);
|
||||
}
|
||||
|
||||
public override Mode Mode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public override Mode Mode { get; set; }
|
||||
|
||||
public override void Clear(Color color)
|
||||
public override void Clear(Color aColor)
|
||||
{
|
||||
base.Clear(color);
|
||||
base.Clear(aColor);
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
Clear();
|
||||
VGAScreen.SetTextMode(VGAScreen.TextSize.Size80x25);
|
||||
VGAScreen.SetTextMode(TextSize.Size80x25);
|
||||
}
|
||||
|
||||
public override void DrawArray(Color[] colors, Point point, int width, int height)
|
||||
public override void DrawArray(Color[] aColors, Point aPoint, int aWidth, int aHeight)
|
||||
{
|
||||
base.DrawArray(colors, point, width, height);
|
||||
base.DrawArray(aColors, aPoint, aWidth, aHeight);
|
||||
}
|
||||
|
||||
public override void DrawArray(Color[] colors, int x, int y, int width, int height)
|
||||
public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int aHeight)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void DrawCircle(Pen pen, int x_center, int y_center, int radius)
|
||||
public override void DrawCircle(Pen aPen, int aXCenter, int aYCenter, int aRadius)
|
||||
{
|
||||
base.DrawCircle(pen, x_center, y_center, radius);
|
||||
base.DrawCircle(aPen, aXCenter, aYCenter, aRadius);
|
||||
}
|
||||
|
||||
public override void DrawCircle(Pen pen, Point point, int radius)
|
||||
public override void DrawCircle(Pen aPen, Point aPoint, int aRadius)
|
||||
{
|
||||
base.DrawCircle(pen, point, radius);
|
||||
base.DrawCircle(aPen, aPoint, aRadius);
|
||||
}
|
||||
|
||||
public override void DrawEllipse(Pen pen, int x_center, int y_center, int x_radius, int y_radius)
|
||||
public override void DrawEllipse(Pen aPen, int aXCenter, int aYCenter, int aXRadius, int aYRadius)
|
||||
{
|
||||
base.DrawEllipse(pen, x_center, y_center, x_radius, y_radius);
|
||||
base.DrawEllipse(aPen, aXCenter, aYCenter, aXRadius, aYRadius);
|
||||
}
|
||||
|
||||
public override void DrawEllipse(Pen pen, Point point, int x_radius, int y_radius)
|
||||
public override void DrawEllipse(Pen aPen, Point aPoint, int aXRadius, int aYRadius)
|
||||
{
|
||||
base.DrawEllipse(pen, point, x_radius, y_radius);
|
||||
base.DrawEllipse(aPen, aPoint, aXRadius, aYRadius);
|
||||
}
|
||||
|
||||
public override void DrawFilledCircle(Pen pen, int x0, int y0, int radius)
|
||||
public override void DrawFilledCircle(Pen aPen, int aX0, int aY0, int aRadius)
|
||||
{
|
||||
base.DrawFilledCircle(pen, x0, y0, radius);
|
||||
base.DrawFilledCircle(aPen, aX0, aY0, aRadius);
|
||||
}
|
||||
|
||||
public override void DrawFilledCircle(Pen pen, Point point, int radius)
|
||||
public override void DrawFilledCircle(Pen aPen, Point aPoint, int aRadius)
|
||||
{
|
||||
base.DrawFilledCircle(pen, point, radius);
|
||||
base.DrawFilledCircle(aPen, aPoint, aRadius);
|
||||
}
|
||||
|
||||
public override void DrawFilledEllipse(Pen pen, Point point, int height, int width)
|
||||
public override void DrawFilledEllipse(Pen aPen, Point aPoint, int aHeight, int aWidth)
|
||||
{
|
||||
base.DrawFilledEllipse(pen, point, height, width);
|
||||
base.DrawFilledEllipse(aPen, aPoint, aHeight, aWidth);
|
||||
}
|
||||
|
||||
public override void DrawFilledEllipse(Pen pen, int x, int y, int height, int width)
|
||||
public override void DrawFilledEllipse(Pen aPen, int aX, int aY, int aHeight, int aWidth)
|
||||
{
|
||||
base.DrawFilledEllipse(pen, x, y, height, width);
|
||||
base.DrawFilledEllipse(aPen, aX, aY, aHeight, aWidth);
|
||||
}
|
||||
|
||||
public override void DrawFilledRectangle(Pen pen, Point point, int width, int height)
|
||||
public override void DrawFilledRectangle(Pen aPen, Point aPoint, int aWidth, int aHeight)
|
||||
{
|
||||
base.DrawFilledRectangle(pen, point, width, height);
|
||||
base.DrawFilledRectangle(aPen, aPoint, aWidth, aHeight);
|
||||
}
|
||||
|
||||
public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int width, int height)
|
||||
public override void DrawFilledRectangle(Pen aPen, int aXStart, int aYStart, int aWidth, int aHeight)
|
||||
{
|
||||
base.DrawFilledRectangle(pen, x_start, y_start, width, height);
|
||||
base.DrawFilledRectangle(aPen, aXStart, aYStart, aWidth, aHeight);
|
||||
}
|
||||
|
||||
public override void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
|
||||
public override void DrawLine(Pen aPen, int aX1, int aY1, int aX2, int aY2)
|
||||
{
|
||||
base.DrawLine(pen, x1, y1, x2, y2);
|
||||
base.DrawLine(aPen, aX1, aY1, aX2, aY2);
|
||||
}
|
||||
|
||||
public override void DrawPoint(Pen pen, int x, int y)
|
||||
public override void DrawPoint(Pen aPen, int aX, int aY)
|
||||
{
|
||||
DrawPoint((uint)aPen.Color.ToArgb(), aX, aY);
|
||||
}
|
||||
|
||||
public void DrawPoint(uint aColor, int aX, int aY)
|
||||
{
|
||||
_VGADriver.SetPixel((uint)aX, (uint)aY, aColor);
|
||||
}
|
||||
|
||||
public override void DrawPoint(Pen aPen, float aX, float aY)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void DrawPoint(Pen pen, float x, float y)
|
||||
public override void DrawPolygon(Pen aPen, params Point[] aPoints)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
base.DrawPolygon(aPen, aPoints);
|
||||
}
|
||||
|
||||
public override void DrawPolygon(Pen pen, params Point[] points)
|
||||
public override void DrawRectangle(Pen aPen, Point aPoint, int aWidth, int aHeight)
|
||||
{
|
||||
base.DrawPolygon(pen, points);
|
||||
base.DrawRectangle(aPen, aPoint, aWidth, aHeight);
|
||||
}
|
||||
|
||||
public override void DrawRectangle(Pen pen, Point point, int width, int height)
|
||||
public override void DrawRectangle(Pen aPen, int aX, int aY, int aWidth, int aHeight)
|
||||
{
|
||||
base.DrawRectangle(pen, point, width, height);
|
||||
base.DrawRectangle(aPen, aX, aY, aWidth, aHeight);
|
||||
}
|
||||
|
||||
public override void DrawRectangle(Pen pen, int x, int y, int width, int height)
|
||||
public override void DrawSquare(Pen aPen, Point aPoint, int aSize)
|
||||
{
|
||||
base.DrawRectangle(pen, x, y, width, height);
|
||||
base.DrawSquare(aPen, aPoint, aSize);
|
||||
}
|
||||
|
||||
public override void DrawSquare(Pen pen, Point point, int size)
|
||||
public override void DrawSquare(Pen aPen, int aX, int aY, int aSize)
|
||||
{
|
||||
base.DrawSquare(pen, point, size);
|
||||
base.DrawSquare(aPen, aX, aY, aSize);
|
||||
}
|
||||
|
||||
public override void DrawSquare(Pen pen, int x, int y, int size)
|
||||
public override void DrawTriangle(Pen aPen, Point aPoint0, Point aPoint1, Point aPoint2)
|
||||
{
|
||||
base.DrawSquare(pen, x, y, size);
|
||||
base.DrawTriangle(aPen, aPoint0, aPoint1, aPoint2);
|
||||
}
|
||||
|
||||
public override void DrawTriangle(Pen pen, Point point0, Point point1, Point point2)
|
||||
public override void DrawTriangle(Pen aPen, int aV1x, int aV1y, int aV2x, int aV2y, int aV3x, int aV3y)
|
||||
{
|
||||
base.DrawTriangle(pen, point0, point1, point2);
|
||||
base.DrawTriangle(aPen, aV1x, aV1y, aV2x, aV2y, aV3x, aV3y);
|
||||
}
|
||||
|
||||
public override void DrawTriangle(Pen pen, int v1x, int v1y, int v2x, int v2y, int v3x, int v3y)
|
||||
private static readonly List<Mode> _AvailableModes = new List<Mode>
|
||||
{
|
||||
base.DrawTriangle(pen, v1x, v1y, v2x, v2y, v3x, v3y);
|
||||
new Mode(640, 480, ColorDepth.ColorDepth4),
|
||||
new Mode(720, 480, ColorDepth.ColorDepth4),
|
||||
new Mode(320, 200, ColorDepth.ColorDepth8)
|
||||
};
|
||||
|
||||
public override List<Mode> AvailableModes => _AvailableModes;
|
||||
|
||||
public override Color GetPointColor(int aX, int aY)
|
||||
{
|
||||
return Color.FromArgb((int)(_VGADriver.GetPixel((uint)aX, (uint)aY)));
|
||||
}
|
||||
|
||||
public override List<Mode> AvailableModes
|
||||
public override Mode DefaultGraphicMode => new Mode(640, 480, ColorDepth.ColorDepth4);
|
||||
|
||||
private ScreenSize ModeToScreenSize(Mode aMode)
|
||||
{
|
||||
get
|
||||
if (aMode.Columns == 320 && aMode.Rows == 200)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return ScreenSize.Size320x200;
|
||||
}
|
||||
}
|
||||
|
||||
public override Color GetPointColor(int x, int y)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Mode DefaultGraphicMode
|
||||
{
|
||||
get
|
||||
else if (aMode.Columns == 640 && aMode.Rows == 200)
|
||||
{
|
||||
return ScreenSize.Size640x480;
|
||||
}
|
||||
else if (aMode.Columns == 720 && aMode.Rows == 480)
|
||||
{
|
||||
return ScreenSize.Size720x480;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,128 +1,84 @@
|
|||
using System;
|
||||
using Cosmos.HAL;
|
||||
using static Cosmos.HAL.VGADriver;
|
||||
|
||||
namespace Cosmos.System.Graphics
|
||||
{
|
||||
public class VGAScreen
|
||||
{
|
||||
public enum TextSize { Size40x25, Size40x50, Size80x25, Size80x50, Size90x30, Size90x60 };
|
||||
|
||||
public enum ScreenSize
|
||||
private static readonly VGADriver _Screen = new VGADriver();
|
||||
|
||||
public static void SetGraphicsMode(ScreenSize aScreenSize, ColorDepth aColorDepth)
|
||||
{
|
||||
Size640x480,
|
||||
Size720x480,
|
||||
Size320x200
|
||||
};
|
||||
|
||||
public enum ColorDepth
|
||||
{
|
||||
BitDepth2, BitDepth4, BitDepth8, BitDepth16
|
||||
};
|
||||
|
||||
private static VGADriver mScreen = new VGADriver();
|
||||
|
||||
public static void SetGraphicsMode(ScreenSize screenSize, ColorDepth colorDepth)
|
||||
{
|
||||
VGADriver.ScreenSize ScrSize = VGADriver.ScreenSize.Size320x200;
|
||||
VGADriver.ColorDepth ClrDepth = VGADriver.ColorDepth.BitDepth8;
|
||||
|
||||
switch (screenSize)
|
||||
var vgaColorDepth = aColorDepth switch
|
||||
{
|
||||
case ScreenSize.Size320x200:
|
||||
ScrSize = VGADriver.ScreenSize.Size320x200;
|
||||
break;
|
||||
case ScreenSize.Size640x480:
|
||||
ScrSize = VGADriver.ScreenSize.Size640x480;
|
||||
break;
|
||||
case ScreenSize.Size720x480:
|
||||
ScrSize = VGADriver.ScreenSize.Size720x480;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("This situation is not implemented!");
|
||||
}
|
||||
|
||||
switch (colorDepth)
|
||||
{
|
||||
case ColorDepth.BitDepth2:
|
||||
ClrDepth = VGADriver.ColorDepth.BitDepth2;
|
||||
break;
|
||||
case ColorDepth.BitDepth4:
|
||||
ClrDepth = VGADriver.ColorDepth.BitDepth4;
|
||||
break;
|
||||
case ColorDepth.BitDepth8:
|
||||
ClrDepth = VGADriver.ColorDepth.BitDepth8;
|
||||
break;
|
||||
case ColorDepth.BitDepth16:
|
||||
ClrDepth = VGADriver.ColorDepth.BitDepth16;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("This situation is not implemented!");
|
||||
}
|
||||
|
||||
mScreen.SetGraphicsMode(ScrSize, ClrDepth);
|
||||
ColorDepth.ColorDepth4 => VGADriver.ColorDepth.BitDepth4,
|
||||
ColorDepth.ColorDepth8 => VGADriver.ColorDepth.BitDepth8,
|
||||
ColorDepth.ColorDepth16 => VGADriver.ColorDepth.BitDepth16,
|
||||
ColorDepth.ColorDepth24 => throw new NotImplementedException(),
|
||||
ColorDepth.ColorDepth32 => throw new NotImplementedException(),
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
_Screen.SetGraphicsMode(aScreenSize, vgaColorDepth);
|
||||
}
|
||||
|
||||
public static void SetPixel(uint X, uint Y, uint Color)
|
||||
public static void SetPixel(uint aX, uint aY, uint aColor)
|
||||
{
|
||||
mScreen.SetPixel(X, Y, Color);
|
||||
_Screen.SetPixel(aX, aY, aColor);
|
||||
}
|
||||
|
||||
public static void Clear(int Color)
|
||||
public static void Clear(int aColor)
|
||||
{
|
||||
mScreen.Clear(Color);
|
||||
_Screen.Clear(aColor);
|
||||
}
|
||||
|
||||
public static void TestMode320x200x8()
|
||||
{
|
||||
mScreen.TestMode320x200x8();
|
||||
_Screen.TestMode320x200x8();
|
||||
}
|
||||
|
||||
public static void SetPalette(int Index, byte[] Palette)
|
||||
public static void SetPaletteEntry(int aIndex, byte aR, byte aG, byte aB)
|
||||
{
|
||||
mScreen.SetPalette(Index, Palette);
|
||||
_Screen.SetPaletteEntry(aIndex, aR, aG, aB);
|
||||
}
|
||||
|
||||
public static void SetPaletteEntry(int Index, byte R, byte G, byte B)
|
||||
public static uint GetPixel(uint aX, uint aY)
|
||||
{
|
||||
mScreen.SetPaletteEntry(Index, R, G, B);
|
||||
return _Screen.GetPixel(aX, aY);
|
||||
}
|
||||
|
||||
public static uint GetPixel(uint X, uint Y)
|
||||
public static void SetTextMode(TextSize aSize)
|
||||
{
|
||||
return mScreen.GetPixel(X, Y);
|
||||
}
|
||||
|
||||
public static void SetTextMode(TextSize Size)
|
||||
{
|
||||
switch (Size)
|
||||
switch (aSize)
|
||||
{
|
||||
case TextSize.Size40x25:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size40x25);
|
||||
_Screen.SetTextMode(TextSize.Size40x25);
|
||||
break;
|
||||
case TextSize.Size40x50:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size40x50);
|
||||
_Screen.SetTextMode(TextSize.Size40x50);
|
||||
break;
|
||||
case TextSize.Size80x25:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size80x25);
|
||||
_Screen.SetTextMode(TextSize.Size80x25);
|
||||
break;
|
||||
case TextSize.Size80x50:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size80x50);
|
||||
_Screen.SetTextMode(TextSize.Size80x50);
|
||||
break;
|
||||
case TextSize.Size90x30:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size90x30);
|
||||
_Screen.SetTextMode(TextSize.Size90x30);
|
||||
break;
|
||||
case TextSize.Size90x60:
|
||||
mScreen.SetTextMode(VGADriver.TextSize.Size90x60);
|
||||
_Screen.SetTextMode(TextSize.Size90x60);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("This situation is not implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
public static int PixelHeight = mScreen.PixelHeight;
|
||||
public static int PixelHeight = _Screen.PixelHeight;
|
||||
|
||||
public static int PixelWidth = mScreen.PixelWidth;
|
||||
public static int PixelWidth = _Screen.PixelWidth;
|
||||
|
||||
public static int Colors = mScreen.Colors;
|
||||
public static int Colors = _Screen.Colors;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue