Cosmos/source/Cosmos.HAL/Drivers/Video/VBEDriver.cs
fanoI 73aa970508 CGS finally works!
Please note that this version works only with Bochs.

- To make it works was needed to renounce to all structures (a part for primitive types) so now Mode and Color are classes.
- Implemented methods of Canvas DrawPoint(), DrawLine() and DrawRect() for now only color depth of 32 bit and integer coordinates are supported
- Changed IoPort of Bochs / VBE to MemoryBlock and not MemoryBlock08 so I can write an 32 bit ARGB color in only an operation instead of 4, this will semplify the future
  work of RGB24 and RGB16 too. Changed the name to the correct one "LinearFrameBuffer".
- Made VBEDriver more object oriented (used enums instead of hardcoded values, created methods and so on...)
- Bugfix in the Pen class there was confusion in the setter / getter of the Color property
- In VBEScreen removed the old code that is not needed anymore, added check to method arguments (that throws in case of fatal errors)
2017-01-08 22:57:27 +01:00

127 lines
4 KiB
C#

//#define COSMOSDEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.HAL.Drivers
{
public class VBEDriver
{
private Core.IOGroup.VBE IO = Core.Global.BaseIOGroups.VBE;
private enum VBERegisterIndex {
VBEDisplayID = 0x00,
VBEDisplayXResolution,
VBEDisplayYResolution,
VBEDisplayBPP,
VBEDisplayEnable,
VBEDisplayBankMode,
VBEDisplayVirtualWidth,
VBEDisplayVirtualHeight,
VBEDisPlayXOffset,
VBEDislyYOffset
};
[Flags]
private enum VBEEnableValues
{
VBEDisabled = 0x00,
VBEEnabled,
VBEUseLinearFrameBuffer = 0x40,
VBENoClearMemory = 0x80,
};
/* We never want that the default empty constructor is used to create a VBEDriver */
private VBEDriver()
{
}
public VBEDriver(ushort xres, ushort yres, ushort bpp)
{
Global.mDebugger.SendInternal($"Creating VBEDriver with Mode {xres}*{yres}@{bpp}");
VBESet(xres, yres, bpp);
}
private void VBEWrite(VBERegisterIndex index, ushort value)
{
IO.VbeIndex.Word = (ushort) index;
IO.VbeData.Word = value;
}
private void VBEDisableDisplay()
{
Global.mDebugger.SendInternal($"Disabling VBE display");
VBEWrite(VBERegisterIndex.VBEDisplayEnable, (ushort)VBEEnableValues.VBEDisabled);
}
private void VBESetXResolution(ushort xres)
{
Global.mDebugger.SendInternal($"VBE Setting X resolution to {xres}");
VBEWrite(VBERegisterIndex.VBEDisplayXResolution, xres);
}
private void VBESetYResolution(ushort yres)
{
Global.mDebugger.SendInternal($"VBE Setting Y resolution to {yres}");
VBEWrite(VBERegisterIndex.VBEDisplayYResolution, yres);
}
private void VBESetDisplayBPP(ushort bpp)
{
Global.mDebugger.SendInternal($"VBE Setting BPP to {bpp}");
VBEWrite(VBERegisterIndex.VBEDisplayBPP, bpp);
}
private void VBEEnableDisplay(VBEEnableValues EnableFlags)
{
//Global.mDebugger.SendInternal($"VBE Enabling display with EnableFlags (ushort){EnableFlags}");
VBEWrite(VBERegisterIndex.VBEDisplayEnable, (ushort)EnableFlags);
}
public void VBESet(ushort xres, ushort yres, ushort bpp)
{
VBEDisableDisplay();
VBESetXResolution(xres);
VBESetYResolution(yres);
VBESetDisplayBPP(bpp);
/*
* Re-enable the Display with LinearFrameBuffer and without clearing video memory of previous value
* (this permits to change Mode without losing the previous datas)
*/
VBEEnableDisplay(VBEEnableValues.VBEEnabled | VBEEnableValues.VBEUseLinearFrameBuffer | VBEEnableValues.VBENoClearMemory);
}
public void SetVRAM(uint index, byte value)
{
Global.mDebugger.SendInternal($"Writing to driver memory in position {index} value {value} (as byte)");
IO.LinearFrameBuffer.Bytes[index] = value;
}
public void SetVRAM(uint index, ushort value)
{
Global.mDebugger.SendInternal($"Writing to driver memory in position {index} value {value} (as ushort)");
IO.LinearFrameBuffer.Words[index] = value;
}
public void SetVRAM(uint index, uint value)
{
//Global.mDebugger.SendInternal($"Writing to driver memory in position {index} value {value} (as uint)");
IO.LinearFrameBuffer.DWords[index] = value;
}
public byte GetVRAM(uint index)
{
return IO.LinearFrameBuffer.Bytes[index];
}
public void ClearVRAM(uint value)
{
IO.LinearFrameBuffer.Fill(value);
}
}
}