From 57c089d8784a6eacf56fdc9aea42c11bd345dfc3 Mon Sep 17 00:00:00 2001 From: Kiirx Date: Sun, 14 Jan 2024 11:56:31 +0100 Subject: [PATCH 01/18] =?UTF-8?q?=F0=9F=A9=B9=20MakeFile=20various=20tweak?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 33436bee2c..78414b0cd7 100644 --- a/Makefile +++ b/Makefile @@ -17,38 +17,47 @@ GIT = git DOTNET = dotnet GITFLAGS = clone --depth=1 -DOTNETFLAGS = -v:q -nologo +DOTNETFLAGS = -nologo -v:q -c:Debug + +GREEN = \033[0;32m +YELLOW = \033[1;33m +DEFAULT = \033[0m .PHONY: all all: $(IL2CPU_DIR) $(XSHARP_DIR) $(COMMON_DIR) + @# Elapsed time is stored in a temporary file, deleted post-install. + @date +%s > _time_$@.txt @$(MAKE) build @$(MAKE) publish @sudo $(MAKE) install @$(MAKE) nuget-install - @echo "============================================" - @echo "| Cosmos has been installed successfully! |" - @echo "============================================" + @printf "============================================\n" + @printf "| ${YELLOW}Cosmos${DEFAULT} has been installed successfully! |\n" + @printf "============================================\n" + @printf "Took ${YELLOW}$$(($$(date +%s)-$$(cat _time_$@.txt)))s${DEFAULT} to build\n" + @rm _time_$@.txt $(IL2CPU_DIR): - @echo "Cloning Cosmos/IL2CPU" - @$(GIT) $(GITFLAGS) --branch=$(IL2CPU_BRANCH) $(IL2CPU_URL) $(THISDIR)/../IL2CPU + @printf "Cloning ${GREEN}Cosmos/IL2CPU${DEFAULT}\n" + @$(GIT) $(GITFLAGS) --branch=$(IL2CPU_BRANCH) $(IL2CPU_URL) $(IL2CPU_DIR) $(XSHARP_DIR): - @echo "Cloning Cosmos/XSharp" - @$(GIT) $(GITFLAGS) --branch=$(XSHARP_BRANCH) $(XSHARP_URL) $(THISDIR)/../XSharp + @printf "Cloning ${GREEN}Cosmos/XSharp${DEFAULT}\n" + @$(GIT) $(GITFLAGS) --branch=$(XSHARP_BRANCH) $(XSHARP_URL) $(XSHARP_DIR) $(COMMON_DIR): - @echo "Cloning Cosmos/Common" - @$(GIT) $(GITFLAGS) --branch=$(COMMON_BRANCH) $(COMMON_URL) $(THISDIR)/../Common + @printf "Cloning ${GREEN}Cosmos/Common${DEFAULT}\n" + @$(GIT) $(GITFLAGS) --branch=$(COMMON_BRANCH) $(COMMON_URL) $(COMMON_DIR) + .PHONY: build build: - @echo "Building IL2CPU" + @printf "Building ${GREEN}IL2CPU${DEFAULT}\n" @$(DOTNET) clean $(IL2CPU_DIR) @$(DOTNET) build $(IL2CPU_DIR) $(DOTNETFLAGS) @$(DOTNET) pack $(IL2CPU_DIR) $(DOTNETFLAGS) - @echo "Building Cosmos" + @printf "Building ${GREEN}Cosmos${DEFAULT}\n" @$(DOTNET) clean $(THISDIR)/source/Cosmos.Common @$(DOTNET) clean $(THISDIR)/source/Cosmos.Debug.Kernel @@ -74,7 +83,7 @@ build: @$(DOTNET) pack $(THISDIR)/source/Cosmos.Build.Tasks $(DOTNETFLAGS) @$(DOTNET) pack $(THISDIR)/source/Cosmos.Plugs $(DOTNETFLAGS) - @echo "Building X#" + @printf "Building ${GREEN}X#${DEFAULT}\n" @$(DOTNET) clean $(XSHARP_DIR)/source/XSharp/XSharp @$(DOTNET) clean $(XSHARP_DIR)/source/Spruce @@ -84,23 +93,23 @@ build: .PHONY: publish publish: - @echo "Publishing IL2CPU" + @printf "Publishing ${GREEN}IL2CPU${DEFAULT}\n" $(DOTNET) publish $(IL2CPU_DIR)/source/IL2CPU -r linux-x64 --self-contained $(DOTNETFLAGS) - @echo "Publishing Cosmos" + @printf "Publishing ${GREEN}Cosmos${DEFAULT}\n" @$(DOTNET) publish $(THISDIR)/source/Cosmos.Core_Plugs $(DOTNETFLAGS) @$(DOTNET) publish $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm $(DOTNETFLAGS) @$(DOTNET) publish $(THISDIR)/source/Cosmos.HAL2 $(DOTNETFLAGS) @$(DOTNET) publish $(THISDIR)/source/Cosmos.System2_Plugs $(DOTNETFLAGS) @$(DOTNET) publish $(THISDIR)/source/Cosmos.Plugs $(DOTNETFLAGS) - @echo "Publishing X#" + @printf "Publishing ${GREEN}X#${DEFAULT}\n" @$(DOTNET) publish $(XSHARP_DIR)/source/XSharp/XSharp $(DOTNETFLAGS) @$(DOTNET) publish $(XSHARP_DIR)/source/Spruce $(DOTNETFLAGS) .PHONY: install install: - @echo "Installing to" $(DESTDIR) + @printf "Installing to ${YELLOW}$(DESTDIR)${DEFAULT}\n" @mkdir -p $(DESTDIR)/Cosmos @mkdir -p $(DESTDIR)/XSharp/DebugStub @mkdir -p $(DESTDIR)/Build/ISO @@ -126,11 +135,11 @@ install: @cp -r $(THISDIR)/Build/HyperV/*.vhdx $(DESTDIR)/Build/HyperV/ @cp -r $(THISDIR)/Build/VMWare/Workstation/* $(DESTDIR)/Build/VMware/Workstation/ @cp -r $(THISDIR)/Build/syslinux/* $(DESTDIR)/Build/ISO/ - @echo $(DESTDIR) > /etc/CosmosUserKit.cfg + @printf $(DESTDIR) > /etc/CosmosUserKit.cfg .PHONY: nuget-install nuget-install: - @echo "Installing Nuget packages" + @printf "Installing ${GREEN}Nuget packages${DEFAULT}\n" @rm -r -f ~/.nuget/packages/cosmos.*/ @rm -r -f ~/.nuget/packages/il2cpu.*/ From ec0644cca5b132192945855ad277bde7153dcb4f Mon Sep 17 00:00:00 2001 From: Kiirx Date: Wed, 20 Mar 2024 19:31:22 +0100 Subject: [PATCH 02/18] =?UTF-8?q?=E2=9E=95=20Compile=20time,=20Release=20m?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Docs/articles/Installation/DevKit.md | 12 ++++----- Makefile | 37 +++++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Docs/articles/Installation/DevKit.md b/Docs/articles/Installation/DevKit.md index b90e00697d..a0fd084fda 100644 --- a/Docs/articles/Installation/DevKit.md +++ b/Docs/articles/Installation/DevKit.md @@ -1,4 +1,4 @@ -# Dev Kit Installation +# Dev Kit Installation ## Windows @@ -6,7 +6,7 @@ * (Free) source code of Development Kit from [Cosmos on GitHub](https://github.com/CosmosOS/Cosmos) * You must clone the repository using Git. For a detailed walkthrough, [see here](https://help.github.com/articles/fork-a-repo/). -* (Free) [Visual Studio 2022 Community](https://visualstudio.microsoft.com/vs/) +* (Free) [Visual Studio 2022 Community](https://visualstudio.microsoft.com/vs/) * (Free) [InnoSetup](http://www.jrsoftware.org/isdl.php#qsp) * This is required to build the setup kit which is used to build and install the Visual Studio integration libaries for Cosmos. * During install it will ask you about optional components to install. Be sure you check "Install Inno Setup Preprocessor". @@ -53,7 +53,7 @@ This will take a while. If there is no error, you successfully installed Cosmos if you are using custom cosmos repos you will need to clone them all manually as the installer script will pull from https://github.com/CosmosOS/ -A tree diagram of the source should look like the following: +A tree diagram of the source should look like the following: @@ -71,6 +71,6 @@ you may need to clear you nuget cache try ``dotnet clean`` to clear the project if you have more then 1 version of visual studio installed this can bug this follow "dotnet Project Templates" should fix it ### dotnet Project Templates -If you are using linux or prefer not using Visual Studio for your projects, you can install the dotnet project template using `dotnet new --install ./source/templates/csharp/` assuming you are currently in the Cosmos base directory. -After installing the template use `dotnet new cosmosCSKernel -n {name}` to create a new Cosmos Kernel project. -The dotnet template can be removed at a later time using `dotnet new --uninstall ./source/templates/csharp/`. +If you are using linux or prefer not using Visual Studio for your projects, you can install the dotnet project template using `dotnet new install ./source/templates/csharp/` assuming you are currently in the Cosmos base directory. +After installing the template use `dotnet new cosmosCSKernel -n {name}` to create a new Cosmos Kernel project. +The dotnet template can be removed at a later time using `dotnet new uninstall ./source/templates/csharp/`. \ No newline at end of file diff --git a/Makefile b/Makefile index 774a84273a..fa8e798716 100644 --- a/Makefile +++ b/Makefile @@ -16,21 +16,28 @@ COMMON_DIR = $(THISDIR)/../Common GIT = git DOTNET = dotnet +BUILDMODE=Release GITFLAGS = clone --depth=1 -DOTNETFLAGS = -nologo -v:q -c:Debug - +DOTNETFLAGS = -nologo -v:q -c:$(BUILDMODE) GREEN = \033[0;32m YELLOW = \033[1;33m DEFAULT = \033[0m +date = $(date +%F%T) + .PHONY: all all: $(IL2CPU_DIR) $(XSHARP_DIR) $(COMMON_DIR) + @printf "${YELLOW}Cosmos${DEFAULT} DevKit Installer\n" + @printf "${date}\n" @# Elapsed time is stored in a temporary file, deleted post-install. @date +%s > _time_$@.txt @$(MAKE) build @$(MAKE) publish @sudo $(MAKE) install @$(MAKE) nuget-install + @$(MAKE) template-install + @printf "To create a Cosmos kernel, run \'dotnet new cosmosCSKernel -n \{name\}\'' + @printf "Build log file saved to ${GREEN}$(THISDIR)/build${date}.log${DEFAULT}\n" @printf "============================================\n" @printf "| ${YELLOW}Cosmos${DEFAULT} has been installed successfully! |\n" @printf "============================================\n" @@ -118,19 +125,19 @@ install: @mkdir -p $(DESTDIR)/Build/VMware/Workstation @mkdir -p $(DESTDIR)/Packages @mkdir -p $(DESTDIR)/Kernel - @cp -r $(IL2CPU_DIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/ - @cp -r $(THISDIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/ - @cp -r $(XSHARP_DIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/ + @cp -r $(IL2CPU_DIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/ + @cp -r $(THISDIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/ + @cp -r $(XSHARP_DIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/ @cp -r $(IL2CPU_DIR)/source/Cosmos.Core.DebugStub/*.xs $(DESTDIR)/XSharp/DebugStub/ @cp -r $(THISDIR)/Artwork/XSharp/XSharp.ico $(DESTDIR)/XSharp/ @cp -r $(THISDIR)/Artwork/Cosmos.ico $(DESTDIR)/ - @cp -r $(IL2CPU_DIR)/source/IL2CPU/bin/Debug/*/linux-x64/publish/* $(DESTDIR)/Build/IL2CPU/ - @cp -r $(THISDIR)/source/Cosmos.Core_Plugs/bin/Debug/*/publish/*.dll $(DESTDIR)/Kernel/ - @cp -r $(THISDIR)/source/Cosmos.System2_Plugs/bin/Debug/*/publish/*.dll $(DESTDIR)/Kernel/ - @cp -r $(THISDIR)/source/Cosmos.HAL2/bin/Debug/*/publish/*.dll $(DESTDIR)/Kernel/ - @cp -r $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm/bin/Debug/netstandard2.0/publish/*.dll $(DESTDIR)/Kernel/ + @cp -r $(IL2CPU_DIR)/source/IL2CPU/bin/$(BUILDMODE)/*/linux-x64/publish/* $(DESTDIR)/Build/IL2CPU/ + @cp -r $(THISDIR)/source/Cosmos.Core_Plugs/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/ + @cp -r $(THISDIR)/source/Cosmos.System2_Plugs/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/ + @cp -r $(THISDIR)/source/Cosmos.HAL2/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/ + @cp -r $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm/bin/$(BUILDMODE)/netstandard2.0/publish/*.dll $(DESTDIR)/Kernel/ @cp -r $(THISDIR)/Build/HyperV/*.vhdx $(DESTDIR)/Build/HyperV/ @cp -r $(THISDIR)/Build/VMWare/Workstation/* $(DESTDIR)/Build/VMware/Workstation/ @@ -145,4 +152,12 @@ nuget-install: @rm -r -f ~/.nuget/packages/il2cpu.*/ @$(DOTNET) nuget remove source "Cosmos Local Package Feed" || true - @$(DOTNET) nuget add source $(DESTDIR)/Packages/ -n "Cosmos Local Package Feed" \ No newline at end of file + @$(DOTNET) nuget add source $(DESTDIR)/Packages/ -n "Cosmos Local Package Feed" + +.PHONY: template-install +template-install: + @printf "Installing ${GREEN}C# Template packages${DEFAULT}\n" + @-dotnet new uninstall $(THISDIR)/source/templates/csharp/ + @printf "If the template was not installed, you can ignore this" + @dotnet new install $(THISDIR)/source/templates/csharp/ +#TODO: Uninstall \ No newline at end of file From ac00a53412e6bdafc40962675236323743a1e5af Mon Sep 17 00:00:00 2001 From: Kiirx Date: Wed, 20 Mar 2024 19:46:42 +0100 Subject: [PATCH 03/18] Remove useless date variable --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index fa8e798716..e03919f148 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,9 @@ GREEN = \033[0;32m YELLOW = \033[1;33m DEFAULT = \033[0m -date = $(date +%F%T) - .PHONY: all all: $(IL2CPU_DIR) $(XSHARP_DIR) $(COMMON_DIR) @printf "${YELLOW}Cosmos${DEFAULT} DevKit Installer\n" - @printf "${date}\n" @# Elapsed time is stored in a temporary file, deleted post-install. @date +%s > _time_$@.txt @$(MAKE) build From 769d7223a9436b3ad4063faba30ffe3f32876df6 Mon Sep 17 00:00:00 2001 From: MarcelClay <118201373+MarcelClay@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:10:24 +0200 Subject: [PATCH 04/18] Small VFS doc fix --- Docs/articles/Kernel/VFS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/articles/Kernel/VFS.md b/Docs/articles/Kernel/VFS.md index b5301e9704..ef1e3c0149 100644 --- a/Docs/articles/Kernel/VFS.md +++ b/Docs/articles/Kernel/VFS.md @@ -13,7 +13,7 @@ This is essential for using the VFS. We start with creating a global CosmosVFS, this line should appear outside of any function, and before the BeforeRun() function. ```C# -Sys.FileSystem.CosmosVFS fs = new Cosmos.FileSystem.CosmosVFS(); +Sys.FileSystem.CosmosVFS fs = new Cosmos.System.FileSystem.CosmosVFS(); ``` Next, we register our VFS at the VFS manager, this will initiate the VFS and make it usable, add this to your kernel's BeforeRun() function: From a45d515d3a8fc663d0f9ca2f74c4d03470aea832 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Wed, 1 May 2024 22:33:34 +0200 Subject: [PATCH 05/18] Fixed max disks and partitions size (issue #2954 ) --- source/Cosmos.HAL2/BlockDevice/BlockDevice.cs | 2 +- source/Cosmos.HAL2/BlockDevice/EBR.cs | 12 ++++----- source/Cosmos.HAL2/BlockDevice/GPT.cs | 12 ++++----- source/Cosmos.HAL2/BlockDevice/IDE.cs | 2 +- source/Cosmos.HAL2/BlockDevice/MBR.cs | 18 ++++++------- source/Cosmos.System2/FileSystem/Disk.cs | 26 ++++++++++--------- .../FileSystem/ManagedPartition.cs | 3 ++- 7 files changed, 39 insertions(+), 36 deletions(-) diff --git a/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs b/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs index da6128884f..7b258f3d65 100644 --- a/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs +++ b/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs @@ -24,7 +24,7 @@ public abstract class BlockDevice : Device /// /// Number of blocks to alloc. /// byte array. - public byte[] NewBlockArray(uint aBlockCount) + public byte[] NewBlockArray(ulong aBlockCount) { return new byte[aBlockCount * mBlockSize]; } diff --git a/source/Cosmos.HAL2/BlockDevice/EBR.cs b/source/Cosmos.HAL2/BlockDevice/EBR.cs index 91e96ed7ba..07ac36cabb 100644 --- a/source/Cosmos.HAL2/BlockDevice/EBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/EBR.cs @@ -13,10 +13,10 @@ public class EBR public class PartInfo { public readonly byte SystemID; - public readonly uint StartSector; - public readonly uint SectorCount; + public readonly ulong StartSector; + public readonly ulong SectorCount; - public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount) + public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount) { SystemID = aSystemID; StartSector = aStartSector; @@ -30,7 +30,7 @@ public EBR(byte[] aEBR) ParsePartition(aEBR, 462); } - protected void ParsePartition(byte[] aEBR, uint aLoc) + protected void ParsePartition(byte[] aEBR, int aLoc) { byte xSystemID = aEBR[aLoc + 4]; // SystemID = 0 means no partition @@ -41,8 +41,8 @@ protected void ParsePartition(byte[] aEBR, uint aLoc) } else if (xSystemID != 0) { - uint xStartSector = BitConverter.ToUInt32(aEBR, (int)aLoc + 8); - uint xSectorCount = BitConverter.ToUInt32(aEBR, (int)aLoc + 12); + ulong xStartSector = BitConverter.ToUInt64(aEBR, aLoc + 8); + ulong xSectorCount = BitConverter.ToUInt64(aEBR, aLoc + 12); var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount); Partitions.Add(xPartInfo); diff --git a/source/Cosmos.HAL2/BlockDevice/GPT.cs b/source/Cosmos.HAL2/BlockDevice/GPT.cs index ba7aed04f2..fb9aae8040 100644 --- a/source/Cosmos.HAL2/BlockDevice/GPT.cs +++ b/source/Cosmos.HAL2/BlockDevice/GPT.cs @@ -36,12 +36,12 @@ public GPT(BlockDevice aBlockDevice) // Start of parition entries ulong partEntryStart = BitConverter.ToUInt64(GPTHeader, 72); - uint numParitions = BitConverter.ToUInt32(GPTHeader, 80); - uint partSize = BitConverter.ToUInt32(GPTHeader, 84); + ulong numParitions = BitConverter.ToUInt32(GPTHeader, 80); + ulong partSize = BitConverter.ToUInt32(GPTHeader, 84); - uint paritionsPerSector = 512 / partSize; + ulong paritionsPerSector = 512 / partSize; - for (ulong i = 0; i < numParitions/paritionsPerSector; i++) + for (ulong i = 0; i < numParitions / paritionsPerSector; i++) { byte[] partData = new byte[512]; @@ -49,12 +49,12 @@ public GPT(BlockDevice aBlockDevice) for (uint j = 0; j < paritionsPerSector; j++) { - ParseParition(partData, j * partSize); + ParseParition(partData, j * (long)partSize); } } } - private void ParseParition(byte[] partData, uint off) + private void ParseParition(byte[] partData, long off) { byte[] guidArray = new byte[16]; diff --git a/source/Cosmos.HAL2/BlockDevice/IDE.cs b/source/Cosmos.HAL2/BlockDevice/IDE.cs index 2552a6daed..e474a59492 100644 --- a/source/Cosmos.HAL2/BlockDevice/IDE.cs +++ b/source/Cosmos.HAL2/BlockDevice/IDE.cs @@ -117,4 +117,4 @@ internal static void ScanAndInitPartitions(BlockDevice device) } } } -} \ No newline at end of file +} diff --git a/source/Cosmos.HAL2/BlockDevice/MBR.cs b/source/Cosmos.HAL2/BlockDevice/MBR.cs index 548a2a4296..32359b6c92 100644 --- a/source/Cosmos.HAL2/BlockDevice/MBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/MBR.cs @@ -19,10 +19,10 @@ public class MBR public class PartInfo { public readonly byte SystemID; - public readonly uint StartSector; - public readonly uint SectorCount; + public readonly ulong StartSector; + public readonly ulong SectorCount; - public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount) + public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount) { SystemID = aSystemID; StartSector = aStartSector; @@ -41,7 +41,7 @@ public MBR(BlockDevice device) ParsePartition(aMBR, 494); } - protected void ParsePartition(byte[] aMBR, uint aLoc) + protected void ParsePartition(byte[] aMBR, ulong aLoc) { byte xSystemID = aMBR[aLoc + 4]; // SystemID = 0 means no partition @@ -56,8 +56,8 @@ protected void ParsePartition(byte[] aMBR, uint aLoc) } else if (xSystemID != 0) { - uint xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8); - uint xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12); + ulong xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8); + ulong xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12); var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount); Partitions.Add(xPartInfo); @@ -128,11 +128,11 @@ public void WritePartitionInformation(Partition partition, byte PartitionNo) partition.Host.ReadBlock(0, 1, ref mb.memory); //TO DO: Implement the CHS starting / ending sector adresses and partition type mb.Write8((uint)(446 + (PartitionNo * 16) + 4), 0x0B); - mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint) partition.StartingSector); - mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint) partition.BlockCount); + mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint)partition.StartingSector); + mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint)partition.BlockCount); partition.Host.WriteBlock(0, 1, ref mb.memory); ParsePartition(mb.memory, 446 + (uint)(PartitionNo * 16)); - + } } } diff --git a/source/Cosmos.System2/FileSystem/Disk.cs b/source/Cosmos.System2/FileSystem/Disk.cs index f3bb292144..a69292c0f3 100644 --- a/source/Cosmos.System2/FileSystem/Disk.cs +++ b/source/Cosmos.System2/FileSystem/Disk.cs @@ -20,7 +20,7 @@ public class Disk /// /// The size of the disk in bytes. /// - public int Size { get; } + public long Size { get; } /// /// List of partitions /// @@ -30,10 +30,12 @@ public List Partitions { List converted = new(); - if (Host.Type == BlockDeviceType.RemovableCD) { + if (Host.Type == BlockDeviceType.RemovableCD) + { ManagedPartition part = new(new Partition(Host, 0, 1000000000), nameof(ISO9660FileSystemFactory)); // For some reason, BlockCount is always 0, so just put a large value here. - if (mountedPartitions[0] != null) { + if (mountedPartitions[0] != null) + { var data = mountedPartitions[0]; part.RootPath = data.RootPath; part.MountedFS = data; @@ -97,7 +99,7 @@ public Disk(BlockDevice mainBlockDevice) parts.Add(new ManagedPartition(part)); } } - Size = (int)(mainBlockDevice.BlockCount * mainBlockDevice.BlockSize); + Size = (long)(mainBlockDevice.BlockCount * mainBlockDevice.BlockSize); } /// /// Mounts all of the partitions in the disk @@ -156,10 +158,9 @@ public void CreatePartition(int size) throw new Exception("Creating partitions with GPT style not yet supported!"); } - int location; - int startingSector = 63; - uint amountOfSectors = (uint)(size * 1024 * 1024 / 512); - //TODO: Check if partition is too big + ulong location; + ulong startingSector = 63; + ulong amountOfSectors = ((ulong)size * 1024 * 1024 / 512); if (Partitions.Count == 0) { @@ -169,7 +170,7 @@ public void CreatePartition(int size) else if (Partitions.Count == 1) { location = 462; - startingSector = (int)(Partitions[0].Host.BlockSize + Partitions[0].Host.BlockCount); + startingSector = (ulong)(Partitions[0].Host.BlockSize + Partitions[0].Host.BlockCount); } else if (Partitions.Count == 2) { @@ -215,7 +216,7 @@ public void CreatePartition(int size) mbrData[510] = boot[0]; mbrData[511] = boot[1]; - Partition partion = new(Host, (ulong)startingSector, amountOfSectors); + Partition partion = new(Host, startingSector, amountOfSectors); Partition.Partitions.Add(partion); parts.Add(new ManagedPartition(partion)); @@ -299,11 +300,12 @@ public void MountPartition(int index) foreach (var item in FileSystemManager.RegisteredFileSystems) { - if(part.LimitFS != null && item.GetType().Name != part.LimitFS) { + if (part.LimitFS != null && item.GetType().Name != part.LimitFS) + { Kernel.PrintDebug("Did not mount partition " + index + " as " + item.GetType().Name + " because the partition has been limited to being a " + part.LimitFS); continue; } - + if (item.IsType(part.Host)) { Kernel.PrintDebug("Mounted partition."); diff --git a/source/Cosmos.System2/FileSystem/ManagedPartition.cs b/source/Cosmos.System2/FileSystem/ManagedPartition.cs index 8c6c5a77d4..10669305cb 100644 --- a/source/Cosmos.System2/FileSystem/ManagedPartition.cs +++ b/source/Cosmos.System2/FileSystem/ManagedPartition.cs @@ -23,7 +23,8 @@ public class ManagedPartition public string LimitFS = null; - public ManagedPartition(Partition host, string limitFS = null) { + public ManagedPartition(Partition host, string limitFS = null) + { Host = host; LimitFS = limitFS; } From 41398e1f9442a1a9e9e28279852c033c4058f80a Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Thu, 2 May 2024 10:50:20 +0200 Subject: [PATCH 06/18] Fixed EBR.cs --- source/Cosmos.HAL2/BlockDevice/EBR.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Cosmos.HAL2/BlockDevice/EBR.cs b/source/Cosmos.HAL2/BlockDevice/EBR.cs index 07ac36cabb..8c0408ccac 100644 --- a/source/Cosmos.HAL2/BlockDevice/EBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/EBR.cs @@ -30,7 +30,7 @@ public EBR(byte[] aEBR) ParsePartition(aEBR, 462); } - protected void ParsePartition(byte[] aEBR, int aLoc) + protected void ParsePartition(byte[] aEBR, ulong aLoc) { byte xSystemID = aEBR[aLoc + 4]; // SystemID = 0 means no partition From 7e5d3cba17032da7f863b03bf9546460a2697891 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Thu, 2 May 2024 13:09:47 +0200 Subject: [PATCH 07/18] Nvm, this should be int, tested --- source/Cosmos.HAL2/BlockDevice/EBR.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Cosmos.HAL2/BlockDevice/EBR.cs b/source/Cosmos.HAL2/BlockDevice/EBR.cs index 8c0408ccac..bdb4409443 100644 --- a/source/Cosmos.HAL2/BlockDevice/EBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/EBR.cs @@ -30,7 +30,7 @@ public EBR(byte[] aEBR) ParsePartition(aEBR, 462); } - protected void ParsePartition(byte[] aEBR, ulong aLoc) + protected void ParsePartition(byte[] aEBR, int aLoc) //This should be int. ToUInt64(byte[] value, int)!! { byte xSystemID = aEBR[aLoc + 4]; // SystemID = 0 means no partition From 69e596b70cd46d54381526e5357259e52110bbaf Mon Sep 17 00:00:00 2001 From: PratyushKing <83279568+PratyushKing@users.noreply.github.com> Date: Sat, 4 May 2024 00:54:25 +0530 Subject: [PATCH 08/18] Makefile short fix --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e03919f148..80610c24ed 100644 --- a/Makefile +++ b/Makefile @@ -156,5 +156,5 @@ template-install: @printf "Installing ${GREEN}C# Template packages${DEFAULT}\n" @-dotnet new uninstall $(THISDIR)/source/templates/csharp/ @printf "If the template was not installed, you can ignore this" - @dotnet new install $(THISDIR)/source/templates/csharp/ -#TODO: Uninstall \ No newline at end of file + @dotnet new -i $(THISDIR)/source/templates/csharp/ +#TODO: Uninstall From 80ecaeb7b10a650510508ea9129f1e156320f660 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Fri, 3 May 2024 23:41:49 +0200 Subject: [PATCH 09/18] Update EBR.cs --- source/Cosmos.HAL2/BlockDevice/EBR.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Cosmos.HAL2/BlockDevice/EBR.cs b/source/Cosmos.HAL2/BlockDevice/EBR.cs index bdb4409443..cdf7744776 100644 --- a/source/Cosmos.HAL2/BlockDevice/EBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/EBR.cs @@ -41,8 +41,8 @@ protected void ParsePartition(byte[] aEBR, int aLoc) //This should be int. ToUIn } else if (xSystemID != 0) { - ulong xStartSector = BitConverter.ToUInt64(aEBR, aLoc + 8); - ulong xSectorCount = BitConverter.ToUInt64(aEBR, aLoc + 12); + ulong xStartSector = BitConverter.ToUInt32(aEBR, aLoc + 8); + ulong xSectorCount = BitConverter.ToUInt32(aEBR, aLoc + 12); var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount); Partitions.Add(xPartInfo); From e08f7444b4f2e2d965734aa75bdda176dae2086b Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sun, 5 May 2024 12:10:49 +0200 Subject: [PATCH 10/18] canvas update --- .../Drivers/Video/SVGAII/VMWareSVGAII.cs | 19 +++++++++++++++++++ source/Cosmos.System2/Graphics/Canvas.cs | 5 ++++- .../Cosmos.System2/Graphics/SVGAIICanvas.cs | 8 ++++++++ source/Cosmos.System2/Graphics/VBECanvas.cs | 9 +++++---- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs index aa83af57fc..8c9cc95e8d 100644 --- a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs +++ b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs @@ -1,5 +1,6 @@ using System; using Cosmos.Core; +using Cosmos.HAL.BlockDevice.Registers; namespace Cosmos.HAL.Drivers.Video.SVGAII { @@ -163,6 +164,24 @@ public void DoubleBufferUpdate() Update(0, 0, width, height); } + public void PartUpdate(uint x, uint y, uint Width, uint Height) + { + videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); + uint Offset = y * Width + x; + for (int i = 0; i < height; i++) + { + //videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); + // videoMemory.Copy(Offset, videoMemory, i * (int)width, (int)width); + // byte* xDest = (byte*)(Base + aDest); + // byte* xSrc = (byte*)(Base + aSrc); + // MemoryOperations.Copy(xDest, xSrc, (int)aCount); + + videoMemory.Copy((uint)(i * Width) + Offset, videoMemory.ToArray(), i * (int)width, (int)width); + } + + Update(x, y, Width, Height); + } + /// /// Set pixel. /// diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 8ce2470e84..c87a1276c9 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -117,7 +117,6 @@ public virtual void Clear(Color color) /// The X coordinate. /// The Y coordinate. public abstract Color GetPointColor(int x, int y); - /// /// Gets the index of the pixel at the given coordinates. /// @@ -625,6 +624,10 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h) } } } + public virtual void UpdatePart(uint x, uint y, uint width, uint height) + { + + } /// /// Draws an image with alpha blending. diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 256769c303..541bbb7e21 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -310,6 +310,14 @@ public override Color GetPointColor(int x, int y) return Color.FromArgb((int)driver.GetPixel((uint)x, (uint)y)); } + public override void UpdatePart(uint x, uint y, uint width, uint height) + { + driver.PartUpdate(x, y, width, height); + } + + + + public override void Display() { driver.DoubleBufferUpdate(); diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index bd507873f3..bdbe85cff2 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -266,14 +266,15 @@ public override void DrawImage(Image aImage, int aX, int aY) var xWidth = (int)aImage.Width; var xHeight = (int)aImage.Height; - int xOffset = GetPointOffset(aX, aY); - + // int xOffset = GetPointOffset(aX, aY); + int xOffset = aY*(int)Mode.Width + aX; for (int i = 0; i < xHeight; i++) { - driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth); + driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth); } - } + } + #endregion public override void Display() From 6f6317e5fd2123edd02b9fe4792433c695e7e546 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sun, 5 May 2024 15:45:18 +0200 Subject: [PATCH 11/18] im done lol --- .../Drivers/Video/SVGAII/VMWareSVGAII.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs index 8c9cc95e8d..bb52a3b550 100644 --- a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs +++ b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs @@ -157,31 +157,27 @@ public void Update(uint x, uint y, uint width, uint height) /// /// Update video memory. - /// + /// S public void DoubleBufferUpdate() { videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); Update(0, 0, width, height); } - public void PartUpdate(uint x, uint y, uint Width, uint Height) + public void PartUpdate(uint x, uint y, uint UpdateWidth, uint UpdateHeight) { - videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); - uint Offset = y * Width + x; - for (int i = 0; i < height; i++) + uint Offset = y * width + x; + for (uint i = 0; i < UpdateHeight; i++) { - //videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); - // videoMemory.Copy(Offset, videoMemory, i * (int)width, (int)width); - // byte* xDest = (byte*)(Base + aDest); - // byte* xSrc = (byte*)(Base + aSrc); - // MemoryOperations.Copy(xDest, xSrc, (int)aCount); + videoMemory.MoveDown(FrameOffset + Offset, FrameSize + Offset, UpdateWidth); + Offset += UpdateHeight; - videoMemory.Copy((uint)(i * Width) + Offset, videoMemory.ToArray(), i * (int)width, (int)width); } - Update(x, y, Width, Height); + Update(x, y, UpdateWidth*2, UpdateHeight); } + /// /// Set pixel. /// From a3c3208ef0e5bd94952e3cff1b97fd2f784a3623 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sun, 5 May 2024 18:36:39 +0200 Subject: [PATCH 12/18] Fixed image drawing (out of screen) --- source/Cosmos.System2/Graphics/Canvas.cs | 20 +++++++++++-------- .../Cosmos.System2/Graphics/SVGAIICanvas.cs | 8 +++++--- source/Cosmos.System2/Graphics/VBECanvas.cs | 8 ++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index c87a1276c9..98f16dc486 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -568,10 +568,11 @@ public virtual void DrawTriangle(Color color, int v1x, int v1y, int v2x, int v2y public virtual void DrawImage(Image image, int x, int y) { Color color; - - for (int xi = 0; xi < image.Width; xi++) + var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); + var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) { - for (int yi = 0; yi < image.Height; yi++) + for (int yi = 0; yi < maxHeight; yi++) { color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); DrawPoint(color, x + xi, y + yi); @@ -615,9 +616,11 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h) Color color; int[] pixels = ScaleImage(image, w, h); - for (int xi = 0; xi < w; xi++) + var maxWidth = Math.Min(w, (int)Mode.Width - x); + var maxHeight = Math.Min(h, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) { - for (int yi = 0; yi < h; yi++) + for (int yi = 0; yi < maxHeight; yi++) { color = Color.FromArgb(pixels[xi + (yi * w)]); DrawPoint(color, x + xi, y + yi); @@ -638,10 +641,11 @@ public virtual void UpdatePart(uint x, uint y, uint width, uint height) public void DrawImageAlpha(Image image, int x, int y) { Color color; - - for (int xi = 0; xi < image.Width; xi++) + var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); + var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) { - for (int yi = 0; yi < image.Height; yi++) + for (int yi = 0; yi < maxHeight; yi++) { color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); DrawPoint(color, x + xi, y + yi); diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 541bbb7e21..7ac7e21266 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -358,12 +358,14 @@ public override void DrawImage(Image image, int x, int y) { var width = (int)image.Width; var height = (int)image.Height; + var maxWidth = Math.Min(width, (int)mode.Width - x); + var maxHeight = Math.Min(height, (int)mode.Height - y); var frameSize = (int)driver.FrameSize; var data = image.RawData; - - for (int i = 0; i < height; i++) + + for (int i = 0; i < maxHeight; i++) { - driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, width); + driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth); } } } diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index bdbe85cff2..db1372a61a 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -265,12 +265,12 @@ public override void DrawImage(Image aImage, int aX, int aY) var xBitmap = aImage.RawData; var xWidth = (int)aImage.Width; var xHeight = (int)aImage.Height; - - // int xOffset = GetPointOffset(aX, aY); + 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 < xHeight; i++) + 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); } } From 16be5bdcdcd724028260b94eda2816a39eccdbc4 Mon Sep 17 00:00:00 2001 From: Marko2155 <98662057+Marko2155@users.noreply.github.com> Date: Thu, 9 May 2024 17:45:43 +0200 Subject: [PATCH 13/18] Update DevKit.md --- Docs/articles/Installation/DevKit.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Docs/articles/Installation/DevKit.md b/Docs/articles/Installation/DevKit.md index 515e7c35dd..08f95b01c1 100644 --- a/Docs/articles/Installation/DevKit.md +++ b/Docs/articles/Installation/DevKit.md @@ -31,7 +31,7 @@ * QEMU or any other virtual machine. See [Running](https://cosmosos.github.io/articles/Installation/Running.html) for more information. ### Installation -Git cline the current source code of Cosmos. +Git clone the current source code of Cosmos. Run `make` to build Cosmos. Cosmos will clone all the required repos, build itself, and install it and its nuget packages to the system automatically. ## MacOS (Apple Silicon/Intel) @@ -39,7 +39,7 @@ It is currently difficult to build Cosmos on Apple Silicon Devices. So, we are g ### Prerequisites -* Docker (`brew cask install docker`) +* Docker (`brew install --cask docker`) * QEMU or any other virtual machine. See [Running](https://cosmosos.github.io/articles/Installation/Running.html) for more information. From ef04aeb2769b0fad49aae152d11e4dc51f355210 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Fri, 10 May 2024 23:08:26 +0200 Subject: [PATCH 14/18] CGS update (part 1) --- .../Drivers/Video/SVGAII/VMWareSVGAII.cs | 17 +---------------- source/Cosmos.System2/Graphics/Canvas.cs | 4 ---- source/Cosmos.System2/Graphics/SVGAIICanvas.cs | 15 ++++----------- source/Cosmos.System2/Graphics/VBECanvas.cs | 6 +++--- 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs index bb52a3b550..aa83af57fc 100644 --- a/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs +++ b/source/Cosmos.HAL2/Drivers/Video/SVGAII/VMWareSVGAII.cs @@ -1,6 +1,5 @@ using System; using Cosmos.Core; -using Cosmos.HAL.BlockDevice.Registers; namespace Cosmos.HAL.Drivers.Video.SVGAII { @@ -157,27 +156,13 @@ public void Update(uint x, uint y, uint width, uint height) /// /// Update video memory. - /// S + /// public void DoubleBufferUpdate() { videoMemory.MoveDown(FrameOffset, FrameSize, FrameSize); Update(0, 0, width, height); } - public void PartUpdate(uint x, uint y, uint UpdateWidth, uint UpdateHeight) - { - uint Offset = y * width + x; - for (uint i = 0; i < UpdateHeight; i++) - { - videoMemory.MoveDown(FrameOffset + Offset, FrameSize + Offset, UpdateWidth); - Offset += UpdateHeight; - - } - - Update(x, y, UpdateWidth*2, UpdateHeight); - } - - /// /// Set pixel. /// diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 98f16dc486..7ab3808a3a 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -627,10 +627,6 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h) } } } - public virtual void UpdatePart(uint x, uint y, uint width, uint height) - { - - } /// /// Draws an image with alpha blending. diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 7ac7e21266..8ec42c69d4 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -84,11 +84,12 @@ public override void DrawFilledRectangle(Color color, int xStart, int yStart, in { var argb = color.ToArgb(); var frameSize = (int)driver.FrameSize; - + width = Math.Min(width, (int)mode.Width - xStart); + height = Math.Min(height, (int)mode.Height - yStart); // For now write directly into video memory, once _xSVGADriver.Fill will be faster it will have to be changed for (int i = yStart; i < yStart + height; i++) { - driver.videoMemory.Fill(GetPointOffset(xStart, i) + (int)frameSize, width, argb); + driver.videoMemory.Fill(GetPointOffset(xStart, i) + frameSize, width, argb); } } @@ -310,14 +311,6 @@ public override Color GetPointColor(int x, int y) return Color.FromArgb((int)driver.GetPixel((uint)x, (uint)y)); } - public override void UpdatePart(uint x, uint y, uint width, uint height) - { - driver.PartUpdate(x, y, width, height); - } - - - - public override void Display() { driver.DoubleBufferUpdate(); @@ -362,7 +355,7 @@ public override void DrawImage(Image image, int x, int y) var maxHeight = Math.Min(height, (int)mode.Height - y); var frameSize = (int)driver.FrameSize; var data = image.RawData; - + for (int i = 0; i < maxHeight; i++) { driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth); diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index db1372a61a..1c658786c1 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -267,14 +267,14 @@ public override void DrawImage(Image aImage, int aX, int aY) var xHeight = (int)aImage.Height; 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; + int xOffset = aY * (int)Mode.Width + aX; for (int i = 0; i < maxHeight; i++) { - driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth); + driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth); } } - + #endregion public override void Display() From 111b7030198fe095003febdd74d975f2b79f8ee6 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sat, 11 May 2024 19:19:09 +0200 Subject: [PATCH 15/18] added bool preventOffBoundPixels yay --- source/Cosmos.System2/Graphics/Canvas.cs | 86 ++++++++++++++----- .../Cosmos.System2/Graphics/SVGAIICanvas.cs | 21 +++-- source/Cosmos.System2/Graphics/VBECanvas.cs | 20 +++-- 3 files changed, 95 insertions(+), 32 deletions(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 7ab3808a3a..4c2642e7e0 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -565,17 +565,32 @@ public virtual void DrawTriangle(Color color, int v1x, int v1y, int v2x, int v2y /// The image to draw. /// The origin X coordinate. /// The origin Y coordinate. - public virtual void DrawImage(Image image, int x, int y) + public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPixels = true) { Color color; - var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); - var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); - for (int xi = 0; xi < maxWidth; xi++) + if (preventOffBoundPixels) { - for (int yi = 0; yi < maxHeight; yi++) + var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); + var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) { - color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); - DrawPoint(color, x + xi, y + yi); + for (int yi = 0; yi < maxHeight; yi++) + { + color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); + DrawPoint(color, x + xi, y + yi); + } + } + } + else + { + var Width = image.Width; + for (int xi = 0; xi < Width; xi++) + { + for (int yi = 0; yi < image.Height; yi++) + { + color = Color.FromArgb(image.RawData[xi + (yi * Width)]); + DrawPoint(color, x + xi, y + yi); + } } } } @@ -611,19 +626,33 @@ static int[] ScaleImage(Image image, int newWidth, int newHeight) /// The Y coordinate. /// The desired width to scale the image to before drawing. /// The desired height to scale the image to before drawing - public virtual void DrawImage(Image image, int x, int y, int w, int h) + public virtual void DrawImage(Image image, int x, int y, int w, int h, bool preventOffBoundPixels = true) { Color color; int[] pixels = ScaleImage(image, w, h); - var maxWidth = Math.Min(w, (int)Mode.Width - x); - var maxHeight = Math.Min(h, (int)Mode.Height - y); - for (int xi = 0; xi < maxWidth; xi++) + if (preventOffBoundPixels) + { + var maxWidth = Math.Min(w, (int)Mode.Width - x); + var maxHeight = Math.Min(h, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) + { + for (int yi = 0; yi < maxHeight; yi++) + { + color = Color.FromArgb(pixels[xi + (yi * w)]); + DrawPoint(color, x + xi, y + yi); + } + } + } + else { - for (int yi = 0; yi < maxHeight; yi++) + for (int xi = 0; xi < w; xi++) { - color = Color.FromArgb(pixels[xi + (yi * w)]); - DrawPoint(color, x + xi, y + yi); + for (int yi = 0; yi < h; yi++) + { + color = Color.FromArgb(pixels[xi + (yi * w)]); + DrawPoint(color, x + xi, y + yi); + } } } } @@ -634,17 +663,32 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h) /// The image to draw. /// The X coordinate. /// The Y coordinate. - public void DrawImageAlpha(Image image, int x, int y) + public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true) { Color color; - var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); - var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); - for (int xi = 0; xi < maxWidth; xi++) + if (preventOffBoundPixels) + { + var maxWidth = Math.Min(image.Width, (int)Mode.Width - x); + var maxHeight = Math.Min(image.Height, (int)Mode.Height - y); + for (int xi = 0; xi < maxWidth; xi++) + { + for (int yi = 0; yi < maxHeight; yi++) + { + color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); + DrawPoint(color, x + xi, y + yi); + } + } + } + else { - for (int yi = 0; yi < maxHeight; yi++) + var Width = image.Width; + for (int xi = 0; xi < Width; xi++) { - color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); - DrawPoint(color, x + xi, y + yi); + for (int yi = 0; yi < image.Height; yi++) + { + color = Color.FromArgb(image.RawData[xi + (yi * Width)]); + DrawPoint(color, x + xi, y + yi); + } } } } diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 8ec42c69d4..3dd5f37628 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -347,18 +347,27 @@ public override void DrawChar(char c, Font font, Color color, int x, int y) } } - public override void DrawImage(Image image, int x, int y) + public override void DrawImage(Image image, int x, int y, bool preventOffBoundPixels = true) { var width = (int)image.Width; var height = (int)image.Height; - var maxWidth = Math.Min(width, (int)mode.Width - x); - var maxHeight = Math.Min(height, (int)mode.Height - y); var frameSize = (int)driver.FrameSize; var data = image.RawData; - - for (int i = 0; i < maxHeight; i++) + if(preventOffBoundPixels) { - driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth); + var maxWidth = Math.Min(width, width - x); + var maxHeight = Math.Min(height, height - y); + for (int i = 0; i < maxHeight; i++) + { + driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth); + } + } + else + { + for (int i = 0; i < height; i++) + { + driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, width); + } } } } diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index 1c658786c1..9e0605a603 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -260,17 +260,27 @@ public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidt } } - public override void DrawImage(Image aImage, int aX, int aY) + 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; - 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++) + if (preventOffBoundPixels) { - driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth); + 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, maxWidth); + } + } + else + { + for (int i = 0; i < xHeight; i++) + { + driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth); + } } } From f85b607b8e51b52b2811cee1e644d6556864cb21 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sat, 11 May 2024 21:16:55 +0200 Subject: [PATCH 16/18] preventOffBoundPixels bugfix --- source/Cosmos.System2/Graphics/Canvas.cs | 12 +++++------- source/Cosmos.System2/Graphics/SVGAIICanvas.cs | 12 ++++++------ source/Cosmos.System2/Graphics/VBECanvas.cs | 5 +++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 4c2642e7e0..7cd896d4b3 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -583,12 +583,11 @@ public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPix } else { - var Width = image.Width; - for (int xi = 0; xi < Width; xi++) + for (int xi = 0; xi < image.Width; xi++) { for (int yi = 0; yi < image.Height; yi++) { - color = Color.FromArgb(image.RawData[xi + (yi * Width)]); + color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); DrawPoint(color, x + xi, y + yi); } } @@ -681,12 +680,11 @@ public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels } else { - var Width = image.Width; - for (int xi = 0; xi < Width; xi++) + for (int xi = 0; xi < image.Width; xi++) { for (int yi = 0; yi < image.Height; yi++) { - color = Color.FromArgb(image.RawData[xi + (yi * Width)]); + color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]); DrawPoint(color, x + xi, y + yi); } } @@ -892,4 +890,4 @@ public static Color AlphaBlend(Color to, Color from, byte alpha) return Color.FromArgb(R, G, B); } } -} +} \ No newline at end of file diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 3dd5f37628..c5b0b82f7f 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -84,12 +84,11 @@ public override void DrawFilledRectangle(Color color, int xStart, int yStart, in { var argb = color.ToArgb(); var frameSize = (int)driver.FrameSize; - width = Math.Min(width, (int)mode.Width - xStart); - height = Math.Min(height, (int)mode.Height - yStart); + // For now write directly into video memory, once _xSVGADriver.Fill will be faster it will have to be changed for (int i = yStart; i < yStart + height; i++) { - driver.videoMemory.Fill(GetPointOffset(xStart, i) + frameSize, width, argb); + driver.videoMemory.Fill(GetPointOffset(xStart, i) + (int)frameSize, width, argb); } } @@ -355,8 +354,9 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi var data = image.RawData; if(preventOffBoundPixels) { - var maxWidth = Math.Min(width, width - x); - var maxHeight = Math.Min(height, height - y); + var maxWidth = Math.Min(width, (int)mode.Width - x); + var maxHeight = Math.Min(height, (int)mode.Height - y); + for (int i = 0; i < maxHeight; i++) { driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth); @@ -371,4 +371,4 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi } } } -} +} \ No newline at end of file diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index 9e0605a603..b2c7091020 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -265,11 +265,11 @@ public override void DrawImage(Image aImage, int aX, int aY, bool preventOffBoun var xBitmap = aImage.RawData; var xWidth = (int)aImage.Width; var xHeight = (int)aImage.Height; - 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++) { driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth); @@ -277,7 +277,8 @@ public override void DrawImage(Image aImage, int aX, int aY, bool preventOffBoun } else { - for (int i = 0; i < xHeight; i++) + int xOffset = aY * xHeight + aX; + for (int i = 0; i < Mode.Height; i++) { driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth); } From 7a9bb19d7834de76b0d1239c32b64cc7d30088af Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+SzymekkYT@users.noreply.github.com> Date: Sun, 12 May 2024 00:03:44 +0200 Subject: [PATCH 17/18] Fixed draw filled rectangle preventOffBoundPixels --- source/Cosmos.System2/Graphics/Canvas.cs | 8 ++++++-- source/Cosmos.System2/Graphics/SVGAIICanvas.cs | 11 ++++++++--- source/Cosmos.System2/Graphics/VBECanvas.cs | 3 ++- source/Cosmos.System2/Graphics/VGACanvas.cs | 7 ++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 7cd896d4b3..a6ac312140 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -529,13 +529,17 @@ public virtual void DrawRectangle(Color color, int x, int y, int width, int heig /// The starting point Y coordinate. /// The width of the rectangle. /// The height of the rectangle. - public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height) + public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true) { if (height == -1) { height = width; } - + if (preventOffBoundPixels) + { + width = Math.Min(width, (int)Mode.Width - xStart); + height = Math.Min(height, (int)Mode.Height - yStart); + } for (int y = yStart; y < yStart + height; y++) { DrawLine(color, xStart, y, xStart + width - 1, y); diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index c5b0b82f7f..32a01de9fe 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -80,12 +80,17 @@ public override void DrawPoint(Color color, int x, int y) driver.SetPixel((uint)x, (uint)y, (uint)color.ToArgb()); } - public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height) + public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true) { var argb = color.ToArgb(); var frameSize = (int)driver.FrameSize; + if(preventOffBoundPixels) + { + width = Math.Min(width, (int)mode.Width - xStart); + height = Math.Min(height, (int)mode.Height - yStart); + } + - // For now write directly into video memory, once _xSVGADriver.Fill will be faster it will have to be changed for (int i = yStart; i < yStart + height; i++) { driver.videoMemory.Fill(GetPointOffset(xStart, i) + (int)frameSize, width, argb); @@ -352,7 +357,7 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi var height = (int)image.Height; var frameSize = (int)driver.FrameSize; var data = image.RawData; - if(preventOffBoundPixels) + if (preventOffBoundPixels) { var maxWidth = Math.Min(width, (int)mode.Width - x); var maxHeight = Math.Min(height, (int)mode.Height - y); diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index b2c7091020..bb86dbf1be 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -248,9 +248,10 @@ public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int } } - public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidth, int aHeight) + public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidth, int aHeight, bool preventOffBoundPixels = true) { // ClearVRAM clears one uint at a time. So we clear pixelwise not byte wise. That's why we divide by 32 and not 8. + if(preventOffBoundPixels) aWidth = (int)(Math.Min(aWidth, Mode.Width - aX) * (int)Mode.ColorDepth / 32); var color = aColor.ToArgb(); diff --git a/source/Cosmos.System2/Graphics/VGACanvas.cs b/source/Cosmos.System2/Graphics/VGACanvas.cs index 50934b030a..2157e06dee 100644 --- a/source/Cosmos.System2/Graphics/VGACanvas.cs +++ b/source/Cosmos.System2/Graphics/VGACanvas.cs @@ -86,8 +86,13 @@ public override void Disable() } } - public override void DrawFilledRectangle(Color aColor, int aXStart, int aYStart, int aWidth, int aHeight) + public override void DrawFilledRectangle(Color aColor, int aXStart, int aYStart, int aWidth, int aHeight, bool preventOffBoundPixels = true) { + if (preventOffBoundPixels) + { + aWidth = Math.Min(aWidth, (int)Mode.Width - aXStart); + aHeight = Math.Min(aHeight, (int)Mode.Height - aYStart); + } driver.DrawFilledRectangle(aXStart, aYStart, aWidth, aHeight, driver.GetClosestColorInPalette(aColor)); } From 19675738c9a4c3b29f4724de55aa5cb285c45378 Mon Sep 17 00:00:00 2001 From: selkij Date: Tue, 9 Jul 2024 23:28:05 +0200 Subject: [PATCH 18/18] Fix MakeFile typos --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 80610c24ed..1db0ffe870 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ all: $(IL2CPU_DIR) $(XSHARP_DIR) $(COMMON_DIR) @sudo $(MAKE) install @$(MAKE) nuget-install @$(MAKE) template-install - @printf "To create a Cosmos kernel, run \'dotnet new cosmosCSKernel -n \{name\}\'' + @printf "To create a Cosmos kernel, run \'dotnet new cosmosCSKernel -n \{name\}\'" @printf "Build log file saved to ${GREEN}$(THISDIR)/build${date}.log${DEFAULT}\n" @printf "============================================\n" @printf "| ${YELLOW}Cosmos${DEFAULT} has been installed successfully! |\n" @@ -155,6 +155,6 @@ nuget-install: template-install: @printf "Installing ${GREEN}C# Template packages${DEFAULT}\n" @-dotnet new uninstall $(THISDIR)/source/templates/csharp/ - @printf "If the template was not installed, you can ignore this" + @printf "If the template was not installed, you can ignore this\n" @dotnet new -i $(THISDIR)/source/templates/csharp/ #TODO: Uninstall