Skip to content

Commit

Permalink
VGAScreen 640x480 and 720x480 is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
CSharpLover committed Nov 6, 2015
1 parent 4ffeeae commit cabe66f
Showing 1 changed file with 91 additions and 23 deletions.
114 changes: 91 additions & 23 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);

c = c & 0xf;
x = (x & 7) * 1;

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

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 @@ -1023,7 +1091,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 +1245,4 @@ public void SetPaletteEntry(int index, byte r, byte g, byte b)
};
#endregion
}
}
}

0 comments on commit cabe66f

Please sign in to comment.