Skip to content

Commit

Permalink
Merge pull request CosmosOS#238 from CSharpLover/master
Browse files Browse the repository at this point in the history
VGAScreen 640x480 and 720x480 is working now
  • Loading branch information
mterwoord committed Nov 6, 2015
2 parents 4ffeeae + a8c886b commit 7c686a0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 28 deletions.
125 changes: 98 additions & 27 deletions source/Cosmos.HAL/Drivers/VGAScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ public void SetGraphicsMode(ScreenSize aSize, ColorDepth aDepth)
else throw new Exception("Unsupported color depth passed for specified screen size");
break;
case ScreenSize.Size720x480:
if (aDepth == ColorDepth.BitDepth16)
if (aDepth == ColorDepth.BitDepth4)
{
WriteVGARegisters(g_720x480x16);
WriteVGARegisters(g_720x480x4);

PixelWidth = 720;
PixelHeight = 480;
Colors = 0xFFFF;
//SetPixel = new SetPixelDelegate(SetPixel720x480x16);
//GetPixel = new GetPixelDelegate(GetPixel720x480x16);
Colors = 16;
SetPixel = new SetPixelDelegate(SetPixel720x480x4);
GetPixel = new GetPixelDelegate(GetPixel720x480x4);
}
else throw new Exception("Unsupported color depth passed for specified screen size");
break;
Expand All @@ -322,38 +322,106 @@ public uint GetPixel320x200x8(uint x, uint y)
}
//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)
{
var xSegment = GetFramebufferSegment();
var xOffset = (y * 32) + x >> 1;
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);

x = (x & 7) * 1;

c = c & 0xf;
uint mask = (byte)(0x80 >> (int)x);
uint pmask = 1;

if ((x & 1) == 0)
for (byte p = 0; p < 4; p++)
{
xSegment[xOffset] = (byte)((xSegment[xOffset] & 0xf) | (byte)(c << 4));
SetPlane(p);

if ((pmask & c) != 0)
{
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] | mask);
}

else
{
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] & ~mask);
}

pmask <<= 1;
}
else
}

public uint GetPixel640x480x4(uint x, uint y)
{
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);

uint pmask = 1;

uint color = 0;

for (byte p = 0; p < 4; p++)
{
xSegment[xOffset] = (byte)((xSegment[xOffset] & 0xf0) | (byte)c);
SetPlane(p);

if (mIO.VGAMemoryBlock[offset] == 255)
{
color += pmask;
}

pmask <<= 1;
}

return color;
}
public uint GetPixel640x480x4(uint x, uint y)

public void SetPixel720x480x4(uint x, uint y, uint c)
{
var xSegment = GetFramebufferSegment();
var xOffset = (y * 32) + x >> 1;
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);

if ((x & 1) == 0)
x = (x & 7) * 1;

uint mask = (byte)(0x80 >> (int)x);
uint pmask = 1;

for (byte p = 0; p < 4; p++)
{
return (byte)(xSegment[xOffset] & 0xf);
SetPlane(p);

if ((pmask & c) != 0)
{
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] | mask);
}

else
{
mIO.VGAMemoryBlock[offset] = (byte)(mIO.VGAMemoryBlock[offset] & ~mask);
}

pmask <<= 1;
}
else
}

public uint GetPixel720x480x4(uint x, uint y)
{
uint offset = (uint)(x / 8 + (PixelWidth / 8) * y);

uint pmask = 1;

uint color = 0;

for (byte p = 0; p < 4; p++)
{
return (byte)(xSegment[xOffset] & 0xf0);
SetPlane(p);

if (mIO.VGAMemoryBlock[offset] == 255)
{
color += pmask;
}

pmask <<= 1;
}

return color;
}
//public void SetPixel720x480x16(uint x, uint y, uint c);
//public uint GetPixel720x480x16(uint x, uint y);

private void SetPixelNoMode(uint x, uint y, uint c)
{
Expand Down Expand Up @@ -401,10 +469,13 @@ public void TestMode320x200x8()

public void Clear(int color)
{
var xSegment = GetFramebufferSegment();

for (uint i = 0; i < PixelHeight * PixelWidth; i++)
xSegment[i] = (byte)(color & 0xFF);
for (int y = 0; y < PixelHeight; y++)
{
for (int x = 0; x < PixelWidth; x++)
{
SetPixel((uint) x, (uint) y, (uint) color);
}
}
}
private Color[] _Palette = new Color[256];
public Color GetPaletteEntry(int index)
Expand Down Expand Up @@ -1023,7 +1094,7 @@ public void SetPaletteEntry(int index, byte r, byte g, byte b)
0x0C, 0x00, 0x0F, 0x08, 0x00,
};

private static byte[] g_720x480x16 = new byte[]
private static byte[] g_720x480x4 = new byte[]
{
/* MISC */
0xE7,
Expand Down Expand Up @@ -1177,4 +1248,4 @@ public void SetPaletteEntry(int index, byte r, byte g, byte b)
};
#endregion
}
}
}
1 change: 0 additions & 1 deletion source/Cosmos.System/VGAScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Cosmos.System
{
[Obsolete("This class has not been properly converted to the final cosmos architecture!")]
public class VGAScreen
{
public enum TextSize { Size40x25, Size40x50, Size80x25, Size80x50, Size90x30, Size90x60 };
Expand Down

0 comments on commit 7c686a0

Please sign in to comment.