commit 664c4d4a9005eaf6484c7e53943755a07aee9415 Author: Harald Wolff Date: Wed Jun 14 11:25:16 2017 +0200 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e82d27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/bitworks.sln b/bitworks.sln new file mode 100644 index 0000000..6a79b8b --- /dev/null +++ b/bitworks.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hwo.bitworks", "hwo.bitworks\hwo.bitworks.csproj", "{07EE5432-46BD-4FFD-85D4-04917894FD12}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {07EE5432-46BD-4FFD-85D4-04917894FD12}.Debug|x86.ActiveCfg = Debug|x86 + {07EE5432-46BD-4FFD-85D4-04917894FD12}.Debug|x86.Build.0 = Debug|x86 + {07EE5432-46BD-4FFD-85D4-04917894FD12}.Release|x86.ActiveCfg = Release|x86 + {07EE5432-46BD-4FFD-85D4-04917894FD12}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.DotNetNamingPolicy = $1 + $1.DirectoryNamespaceAssociation = PrefixedHierarchical + $1.ResourceNamePolicy = FileName + EndGlobalSection +EndGlobal diff --git a/hwo.bitworks/ADD.cs b/hwo.bitworks/ADD.cs new file mode 100644 index 0000000..c0d3c56 --- /dev/null +++ b/hwo.bitworks/ADD.cs @@ -0,0 +1,36 @@ +using System; +namespace hwo.bitworks +{ + public class ADD : MultipleBitsSource + { + + XOR xor2,xor3; + AND and12,andC; + OR or; + + public ADD(LogicBase source1,LogicBase source2,LogicBase carry) + { + and12 = new AND(source1,source2); + xor2 = new XOR(source1,source2); + andC = new AND(carry,xor2); + or = new OR(andC,and12); + + xor3 = new XOR(source1,source2,carry); + } + + public override bool bitValue(int bit) + { + switch (bit){ + case 1: + return or.value(); + case 0: + return xor3.value(); + default: + throw new IndexOutOfRangeException(String.Format("ADD supplies 2 bits, but bit #{0} requested",bit)); + } + } + + + + } +} diff --git a/hwo.bitworks/ADDX.cs b/hwo.bitworks/ADDX.cs new file mode 100644 index 0000000..374593e --- /dev/null +++ b/hwo.bitworks/ADDX.cs @@ -0,0 +1,52 @@ +using System; +namespace hwo.bitworks +{ + public class ADDX : MultipleBitsSource + { + LogicBase[] srcA,srcB; + ADD[] add; + + public ADDX(LogicBase[] sourcesA,LogicBase[] sourcesB) + { + int l = sourcesA.Length > sourcesB.Length ? sourcesA.Length : sourcesB.Length; + + srcA = new LogicBase[l]; + srcB = new LogicBase[l]; + add = new ADD[l]; + + Array.Copy(sourcesA,srcA,sourcesA.Length); + Array.Copy(sourcesB,srcB,sourcesB.Length); + + for (int n=sourcesA.Length; n < l; n++){ + srcA[n] = Constants.ZERO; + } + for (int n=sourcesB.Length; n < l; n++){ + srcB[n] = Constants.ZERO; + } + + LogicBase lb = Constants.ZERO; + + for (int n=0;n add.Length){ + throw new IndexOutOfRangeException(String.Format("ADDX supplies {0} bits, but bit #{1} requested",add.Length+1,bit)); + } else if (bit == add.Length){ + return add[bit-1].bitValue(1); + } else { + return add[bit].bitValue(0); + } + } + + } +} diff --git a/hwo.bitworks/AND.cs b/hwo.bitworks/AND.cs new file mode 100644 index 0000000..4fd0510 --- /dev/null +++ b/hwo.bitworks/AND.cs @@ -0,0 +1,22 @@ +using System; +namespace hwo.bitworks +{ + public class AND : LogicBase + { + + public AND(params LogicBase[] sources) + :base(sources){ + } + + public override bool value() + { + foreach (LogicBase source in this.sources){ + if (!source.value()){ + return false; + } + } + return true; + } + + } +} diff --git a/hwo.bitworks/BitBuffer.cs b/hwo.bitworks/BitBuffer.cs new file mode 100644 index 0000000..f989aae --- /dev/null +++ b/hwo.bitworks/BitBuffer.cs @@ -0,0 +1,41 @@ +using System; +namespace hwo.bitworks +{ + public class BitBuffer : MultipleBitsSource + { + bool[] bits; + + public BitBuffer(int len) + { + this.bits = new bool[len]; + } + + public override int getBits() + { + return bits.Length; + } + + public void zero(){ + for (int n=0;n + + + Debug + x86 + {07EE5432-46BD-4FFD-85D4-04917894FD12} + Exe + hwo.bitworks + hwo.bitworks + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file