Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGS Update (part 2) #3034

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4de75d
Drawing Raw Point (raw argb)
Szymekk44 Jun 20, 2024
f6937c9
Faster DrawRectangle
Szymekk44 Jun 20, 2024
4b3ee4d
GetRawPoint & Basic GetImage
Szymekk44 Jun 20, 2024
e47e504
Finished GetRawColor and faster SVGAII GetImage
Szymekk44 Jun 20, 2024
5d9e075
VBE DrawImage change and added CroppedDrawImage
Szymekk44 Jun 20, 2024
2feb8c1
Merge branch 'CosmosOS:master' into master
Szymekk44 Jun 20, 2024
dda9df1
More summaries, alpha rectangles
Szymekk44 Jul 8, 2024
7bad71f
Merge branch 'master' into master
MishaProductions Jul 10, 2024
289270e
added preventOffBoundPixels in summary
Szymekk44 Jul 12, 2024
a3540b0
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Szymekk44 Jul 12, 2024
f064006
Fixed VBE getimage()
Szymekk44 Jul 28, 2024
2036880
Faster VBE GetImage
Szymekk44 Jul 29, 2024
f1bedae
Fixed SVGAII image drawing (x and y < 0)
Szymekk44 Jul 29, 2024
d290822
Merge branch 'master' into master
MishaProductions Aug 9, 2024
6f38e13
New DrawArray methods, VBE bugfix
Szymekk44 Aug 9, 2024
da5e7ac
Small VBE bugfix
Szymekk44 Aug 12, 2024
b00577e
Added PCIE
Samma2009 Aug 13, 2024
8d6fa08
Update PCIExpress.cs
Samma2009 Aug 13, 2024
c5b44ce
Delete source/Cosmos.Debug.Kernel.Plugs.Asm/packages.lock.json
Samma2009 Aug 13, 2024
a770c34
fix power stuff
Samma2009 Aug 13, 2024
155b893
change of comments
Samma2009 Aug 13, 2024
f047cd9
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Samma2009 Aug 13, 2024
98406c5
Fixed namespaceing
Samma2009 Aug 13, 2024
01342ae
Update PCIExpress.cs
Samma2009 Aug 13, 2024
7f19fbd
Merge branch 'master' into master
Szymekk44 Aug 16, 2024
d8f0aad
Add files via upload
Samma2009 Aug 16, 2024
d117063
Update packages.lock.json
Samma2009 Aug 16, 2024
98bb00f
Update packages.lock.json
Samma2009 Aug 16, 2024
3375aab
Update packages.lock.json
Samma2009 Aug 16, 2024
ac464df
Update packages.lock.json
Samma2009 Aug 16, 2024
b84f8a4
Graphics drivers are public, FileSystemType enum
Szymekk44 Sep 21, 2024
e80d1e0
Graphics drivers are public, FilsSystemType enum
Szymekk44 Sep 21, 2024
e0e7f0b
Merge pull request #1 from Szymekk44/CGE-Update
Szymekk44 Sep 21, 2024
e58fdc5
Merge pull request #2 from Szymekk44/CGE-Update2
Szymekk44 Sep 21, 2024
fb59494
Disk format - removed FIleTypeFormat enum
Szymekk44 Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ public unsafe void Copy(ManagedMemoryBlock block)
MemoryOperations.Copy(xDest, aDataPtr, (int)block.Size);
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
public unsafe void Get(int aByteOffset, int[] aData, int aIndex, int aCount)
{
int* xSource = (int*)(Base + aByteOffset);
fixed (int* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSource, aCount);
}
}

/// <summary>
/// Move bytes array down the memory block.
/// </summary>
Expand Down
40 changes: 39 additions & 1 deletion source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public virtual void Clear(Color color)
/// <param name="y">The Y coordinate.</param>
public abstract void DrawPoint(Color color, int x, int y);

/// <summary>
/// Sets the pixel at the given coordinates to the specified <paramref name="color"/>. without ToArgb()
/// </summary>
/// <param name="color">The color to draw with (raw argb).</param>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract void DrawRawPoint(uint color, int x, int y);

/// <summary>
/// The name of the Canvas implementation.
/// </summary>
Expand All @@ -117,6 +125,13 @@ public virtual void Clear(Color color)
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract Color GetPointColor(int x, int y);

/// <summary>
/// Gets the color of the pixel at the given coordinates in ARGB.
/// </summary>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract int GetRawPointColor(int x, int y);
/// <summary>
/// Gets the index of the pixel at the given coordinates.
/// </summary>
Expand Down Expand Up @@ -598,6 +613,29 @@ public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPix
}
}

/// <summary>
/// Draws the given image at the specified coordinates, cropped to maxWidth and maxHeight
/// </summary>
/// <param name="image">The image to draw.</param>
/// <param name="x">The origin X coordinate.</param>
/// <param name="y">The origin Y coordinate.</param>
/// <param name="maxWidth">Max image width to display</param>
/// <param name="maxHeight">Max image height to display</param>
public virtual void CroppedDrawImage(Image image, int x, int y, int maxWidth, int maxHeight)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this left empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know tho i could fix it

}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
public virtual Bitmap GetImage(int x, int y, int width, int height)
{
Bitmap bitmap = new Bitmap((uint)x, (uint)y, ColorDepth.ColorDepth32);

for (int posy = y, desty = 0; posy < y + y; posy++, desty++)
for (int posx = x, destx = 0; posx < x + x; posx++, destx++)
bitmap.RawData[desty * x + destx] = GetRawPointColor(posx, posy);
return bitmap;
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
static int[] ScaleImage(Image image, int newWidth, int newHeight)
{
int[] pixels = image.RawData;
Expand Down Expand Up @@ -666,7 +704,7 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h, bool prev
/// <param name="image">The image to draw.</param>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true)
public virtual void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true)
{
Color color;
if (preventOffBoundPixels)
Expand Down
69 changes: 69 additions & 0 deletions source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public override void DrawPoint(Color color, int x, int y)
driver.SetPixel((uint)x, (uint)y, (uint)color.ToArgb());
}

public override void DrawRawPoint(uint color, int x, int y)
{
driver.SetPixel((uint)x, (uint)y, color);
}

public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true)
{
var argb = color.ToArgb();
Expand All @@ -97,6 +102,37 @@ public override void DrawFilledRectangle(Color color, int xStart, int yStart, in
}
}

public override void DrawRectangle(Color color, int x, int y, int width, int height)
{
int rawColor = color.ToArgb();

/* Draw the top edge (A to B) */
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, y);
}

/* Draw the bottom edge (C to D) */
int newY = y + height;
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, newY);
}

/* Draw the left edge (A to C) */
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, x, posY);
}

/* Draw the right edge (B to D) */
int newX = x + width;
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, newX, posY);
}
}

//public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
/// <summary>
/// Available SVGA 2 supported video modes.
Expand Down Expand Up @@ -315,6 +351,11 @@ public override Color GetPointColor(int x, int y)
return Color.FromArgb((int)driver.GetPixel((uint)x, (uint)y));
}

public override int GetRawPointColor(int x, int y)
{
return (int)driver.GetPixel((uint)x, (uint)y);
}

public override void Display()
{
driver.DoubleBufferUpdate();
Expand Down Expand Up @@ -375,5 +416,33 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi
}
}
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
public override void CroppedDrawImage(Image image, int x, int y, int maxWidth, int maxHeight)
{
var width = maxWidth;
var height = maxHeight;
var frameSize = (int)driver.FrameSize;
var data = image.RawData;
for (int i = 0; i < height; i++)
{
driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, width);
}
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
public override Bitmap GetImage(int x, int y, int width, int height)
{
var frameSize = (int)driver.FrameSize;
int[] buffer = new int[width];
int[] all = new int[width * height];
for (int i = 0; i < height; i++)
{
driver.videoMemory.Get(GetPointOffset(x, y + i) + frameSize, buffer, 0, width);
buffer.CopyTo(all, width * i);
}
Bitmap toReturn = new Bitmap((uint)width, (uint)height, ColorDepth.ColorDepth32);
toReturn.RawData = all;

return toReturn;
}
}
}
94 changes: 85 additions & 9 deletions source/Cosmos.System2/Graphics/VBECanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,34 @@ public override void DrawPoint(Color aColor, int aX, int aY)
}
}

public override void DrawRawPoint(uint aColor, int aX, int aY)
{
uint offset;

switch (Mode.ColorDepth)
{
case ColorDepth.ColorDepth32:
offset = (uint)GetPointOffset(aX, aY);

driver.SetVRAM(offset, (byte)((aColor >> 16) & 0xFF));
driver.SetVRAM(offset + 1, (byte)((aColor >> 8) & 0xFF));
driver.SetVRAM(offset + 2, (byte)(aColor & 0xFF));
driver.SetVRAM(offset + 3, (byte)((aColor >> 24) & 0xFF));

break;
case ColorDepth.ColorDepth24:
offset = (uint)GetPointOffset(aX, aY);

driver.SetVRAM(offset, (byte)((aColor >> 16) & 0xFF));
driver.SetVRAM(offset + 1, (byte)((aColor >> 8) & 0xFF));
driver.SetVRAM(offset + 2, (byte)(aColor & 0xFF));

break;
default:
throw new NotImplementedException("Drawing pixels with color depth " + (int)Mode.ColorDepth + " is not yet supported.");
}
}

public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int aHeight)
{
ThrowIfCoordNotValid(aX, aY);
Expand Down Expand Up @@ -261,30 +289,72 @@ public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidt
}
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
public override void DrawRectangle(Color color, int x, int y, int width, int height)
{
int rawColor = color.ToArgb();

/* Draw the top edge (A to B) */
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, y);
}

/* Draw the bottom edge (C to D) */
int newY = y + height;
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, newY);
}

/* Draw the left edge (A to C) */
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, x, posY);
}

/* Draw the right edge (B to D) */
int newX = x + width;
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, newX, posY);
}
}

public override void DrawImage(Image aImage, int aX, int aY, bool preventOffBoundPixels = true)
{
var xBitmap = aImage.RawData;
var xWidth = (int)aImage.Width;
var xHeight = (int)aImage.Height;
if (preventOffBoundPixels)
int xOffset = aY * (int)Mode.Width + aX;

if (!preventOffBoundPixels)
{
var maxWidth = Math.Min(xWidth, (int)mode.Width - aX);
var maxHeight = Math.Min(xHeight, (int)mode.Height - aY);
int xOffset = aY * (int)Mode.Width + aX;
for (int i = 0; i < maxHeight; i++)
for (int i = 0; i < xHeight; i++)
{
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth);
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth);
}
}
else
{
int xOffset = aY * xHeight + aX;
for (int i = 0; i < Mode.Height; i++)
var maxWidth = Math.Min(xWidth, (int)mode.Width - aX);
var maxHeight = Math.Min(xHeight, (int)mode.Height - aY);
for (int i = 0; i < maxHeight; i++)
{
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth);
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth);
}
}
}

public override void CroppedDrawImage(Image aImage, int aX, int aY, int aWidth, int aHeight)
{
var xBitmap = aImage.RawData;
var xWidth = aWidth;
var xHeight = aHeight;
int xOffset = aY * xHeight + aX;
for (int i = 0; i < Mode.Height; i++)
{
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth);
}
}

#endregion
Expand All @@ -302,6 +372,12 @@ public override Color GetPointColor(int aX, int aY)
return Color.FromArgb((int)driver.GetVRAM(offset));
}

public override int GetRawPointColor(int aX, int aY)
{
uint offset = (uint)GetPointOffset(aX, aY);
return (int)driver.GetVRAM(offset);
}

#endregion

}
Expand Down
41 changes: 41 additions & 0 deletions source/Cosmos.System2/Graphics/VGACanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@ public override void DrawFilledRectangle(Color aColor, int aXStart, int aYStart,
driver.DrawFilledRectangle(aXStart, aYStart, aWidth, aHeight, driver.GetClosestColorInPalette(aColor));
}

public override void DrawRectangle(Color color, int x, int y, int width, int height)
{
int rawColor = color.ToArgb();

/* Draw the top edge (A to B) */
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, y);
}

/* Draw the bottom edge (C to D) */
int newY = y + height;
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, newY);
}

/* Draw the left edge (A to C) */
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, x, posY);
}

/* Draw the right edge (B to D) */
int newX = x + width;
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, newX, posY);
}
}

public override void DrawPoint(Color aColor, int aX, int aY)
{
driver.SetPixel((uint)aX, (uint)aY, aColor);
Expand All @@ -106,13 +137,23 @@ public void DrawPoint(uint aColor, int aX, int aY)
driver.SetPixel((uint)aX, (uint)aY, aColor);
}

public override void DrawRawPoint(uint aColor, int aX, int aY)
{
driver.SetPixel((uint)aX, (uint)aY, aColor);
}

public override List<Mode> AvailableModes => availableModes;

public override Color GetPointColor(int aX, int aY)
{
return Color.FromArgb((int)driver.GetPixel((uint)aX, (uint)aY));
}

public override int GetRawPointColor(int aX, int aY)
{
return (int)driver.GetPixel((uint)aX, (uint)aY);
}

public override Mode DefaultGraphicsMode => new Mode(640, 480, ColorDepth.ColorDepth4);

/// <summary>
Expand Down
Loading