// Helper Methods: private static string ToHadesString(this Component component) { return(component switch { ANDGate and => $"hades.models.gatter.And{and.NumberOfInputs} {and.Name} {and.Pos.X * 3}0 {and.Pos.Y * 3}0 @N 1001 1.0E-8", INVGate inv => $"hades.models.gatter.Inv {inv.Name} {inv.Pos.X * 3}0 {inv.Pos.Y * 3}0 @N 1001 5.0E-9", NANDGate nand => $"hades.models.gatter.Nand{nand.NumberOfInputs} {nand.Name} {nand.Pos.X * 3}0 {nand.Pos.Y * 3}0 @N 1001 1.0E-8", NORGate nor => $"hades.models.gatter.Nor{nor.NumberOfInputs} {nor.Name} {nor.Pos.X * 3}0 {nor.Pos.Y * 3}0 @N 1001 1.0E-8", ORGate or => $"hades.models.gatter.Or{or.NumberOfInputs} {or.Name} {or.Pos.X * 3}0 {or.Pos.Y * 3}0 @N 1001 1.0E-8", XNORGate xnor => $"hades.models.gatter.Xnor{xnor.NumberOfInputs} {xnor.Name} {xnor.Pos.X * 3}0 {xnor.Pos.Y * 3}0 @N 1001 1.0E-8", XORGate xor => $"hades.models.gatter.Xor{xor.NumberOfInputs} {xor.Name} {xor.Pos.X * 3}0 {xor.Pos.Y * 3}0 @N 1001 1.0E-8", InputPulse ip => $"hades.models.io.PulseSwitch {ip.Name} {ip.Pos.X * 3}0 {ip.Pos.Y * 3}0 @N 1001 0.1 null", InputClock ic => $"hades.models.io.ClockGen {ic.Name} {ic.Pos.X * 3}0 {ic.Pos.Y * 3}0 @N 1001 {InputClock.MsToSec()} 0.5 0.0", Input i => $"hades.models.io.Ipin {i.Name} {i.Pos.X * 3}0 {i.Pos.Y * 3}0 @N 1001 {i.IsActive}", Output o => $"hades.models.io.Opin {o.Name} {o.Pos.X * 3}0 {o.Pos.Y * 3}0 @N 1001 5.0E-9", _ => throw new ComponentNotFoundException(component.GetType().ToString()) });
public void AND() { PowerSupplier power1 = new PowerSupplier(); PowerSupplier power2 = new PowerSupplier(); ANDGate andGate = new ANDGate(); IndicatorLight light = new IndicatorLight(); andGate.Output.ConnectTo(light.Input); Assert.IsFalse(light.Lighting); andGate.Input1.ConnectTo(power1.Output); andGate.Input2.ConnectTo(power2.Output); Assert.IsFalse(light.Lighting); power1.On(); power2.Off(); Assert.IsFalse(light.Lighting); power1.Off(); power2.On(); Assert.IsFalse(light.Lighting); power1.On(); power2.On(); Assert.IsTrue(light.Lighting); power1.Off(); power2.Off(); Assert.IsFalse(light.Lighting); }
public Gate ToGate() { var and = new ANDGate(); and.AddInputRange(Factors.SelectMany(e => e.ToGateList())); return(and); }
public Quad_And_Gates() : base(8, 4) { Gate gateA = new ANDGate(); int indexA = AddGate(gateA); Gate gateB = new ANDGate(); int indexB = AddGate(gateB); Gate gateC = new ANDGate(); int indexC = AddGate(gateC); Gate gateD = new ANDGate(); int indexD = AddGate(gateD); // Gate A AddWire(ID, new Wire(0, 0, indexA, false)); AddWire(ID, new Wire(1, 1, indexA, false)); AddWire(gateA.ID, new Wire(0, 0, -1, true)); // Gate B AddWire(ID, new Wire(2, 0, indexB, false)); AddWire(ID, new Wire(3, 1, indexB, false)); AddWire(gateB.ID, new Wire(0, 1, -1, true)); // Gate C AddWire(ID, new Wire(4, 0, indexC, false)); AddWire(ID, new Wire(5, 1, indexC, false)); AddWire(gateC.ID, new Wire(0, 2, -1, true)); // Gate D AddWire(ID, new Wire(6, 0, indexD, false)); AddWire(ID, new Wire(7, 1, indexD, false)); AddWire(gateD.ID, new Wire(0, 3, -1, true)); }
public HalfAdder() { _andGate = new ANDGate(); _xorGate = new XORGate(); _nexus1 = new TShapedNexus(null, _andGate.Input1, _xorGate.Input1); _nexus2 = new TShapedNexus(null, _andGate.Input2, _xorGate.Input2); Number1In = _nexus1.GetEndpointAt(0); Number2In = _nexus2.GetEndpointAt(0); Sum = _xorGate.Output; CarryOut = _andGate.Output; }
public AND4Chip() : base(3, 1) { Gate gateA = new ANDGate(); int indexA = AddGate(gateA); Gate gateB = new ORGate(); int indexB = AddGate(gateB); AddWire(ID, new Wire(2, 0, indexA, false)); AddWire(ID, new Wire(1, 1, indexA, false)); AddWire(ID, new Wire(0, 1, indexB, false)); AddWire(gateA.ID, new Wire(0, 0, indexB, false)); AddWire(gateB.ID, new Wire(0, 0, -1, true)); }
public XORGate() { _orGate = new ORGate(); _nandGate = new NANDGate(); _andGate = new ANDGate(); _nexus1 = new TShapedNexus(null, _orGate.Input1, _nandGate.Input1); _nexus2 = new TShapedNexus(null, _orGate.Input2, _nandGate.Input2); _andGate.Input1.ConnectTo(_orGate.Output); _andGate.Input2.ConnectTo(_nandGate.Output); Input1 = _nexus1.GetEndpointAt(0); Input2 = _nexus2.GetEndpointAt(0); Output = _andGate.Output; }
public DTypeFlipFlopLevelTriggered() { _RSflipFlop = new RSFlipFlop(); _andGate1 = new ANDGate(); _andGate2 = new ANDGate(); _invertor = new Invertor(); _nexus1 = new TShapedNexus(_andGate1.Input1, _andGate2.Input1); _nexus2 = new TShapedNexus(_invertor.Input, _andGate2.Input2); _invertor.Output.ConnectTo(_andGate1.Input2); _andGate1.Output.ConnectTo(_RSflipFlop.Reset); _andGate2.Output.ConnectTo(_RSflipFlop.Set); Data = _nexus2.GetEndpointAt(2); Clock = _nexus1.GetEndpointAt(2); Q = _RSflipFlop.Q; QBar = _RSflipFlop.QBar; }
public TestChip3() : base(4, 1) { Gate gateA = new ORGate(); int indexA = AddGate(gateA); Gate gateB = new ORGate(); int indexB = AddGate(gateB); Gate gateC = new ANDGate(); int indexC = AddGate(gateC); AddWire(ID, new Wire(3, 0, indexA, false)); AddWire(ID, new Wire(2, 1, indexA, false)); AddWire(ID, new Wire(1, 0, indexB, false)); AddWire(ID, new Wire(0, 1, indexB, false)); AddWire(gateA.ID, new Wire(0, 0, indexC, false)); AddWire(gateB.ID, new Wire(0, 1, indexC, false)); AddWire(gateC.ID, new Wire(0, 0, -1, true)); }
public Decoder2To4() { _invertor1 = new Invertor(); _invertor2 = new Invertor(); _andGate00 = new ANDGate(); _andGate01 = new ANDGate(); _andGate10 = new ANDGate(); _andGate11 = new ANDGate(); _crossNexus1 = new CrossNexus(null, _andGate10.Input1, _invertor1.Input, _andGate11.Input1); _crossNexus2 = new CrossNexus(null, _andGate01.Input2, _invertor2.Input, _andGate11.Input2); _tshapeNexus1 = new TShapedNexus(_invertor1.Output, _andGate00.Input1, _andGate01.Input1); _tshapeNexus2 = new TShapedNexus(_invertor2.Output, _andGate00.Input2, _andGate10.Input2); Input1 = _crossNexus1.GetEndpointAt(0); Input2 = _crossNexus2.GetEndpointAt(0); Output00 = _andGate00.Output; Output01 = _andGate01.Output; Output10 = _andGate10.Output; Output11 = _andGate11.Output; }
public Full_Adder() : base(3, 2) { Gate gateA = new XORGate(); int indexA = AddGate(gateA); Gate gateB = new XORGate(); int indexB = AddGate(gateB); Gate gateC = new ANDGate(); int indexC = AddGate(gateC); Gate gateD = new ANDGate(); int indexD = AddGate(gateD); Gate gateE = new ORGate(); int indexE = AddGate(gateE); // Gate A AddWire(ID, new Wire(0, 0, indexA)); AddWire(ID, new Wire(1, 1, indexA)); AddWire(gateA.ID, new Wire(0, 0, indexB)); AddWire(gateA.ID, new Wire(0, 0, indexC)); // Gate B AddWire(ID, new Wire(2, 1, indexB)); AddWire(gateB.ID, new Wire(0, 0, -1, true)); // Gate C AddWire(ID, new Wire(2, 1, indexC)); AddWire(gateC.ID, new Wire(0, 0, indexE)); // Gate D AddWire(ID, new Wire(0, 0, indexD)); AddWire(ID, new Wire(1, 1, indexD)); AddWire(gateD.ID, new Wire(0, 1, indexE)); // Gate E AddWire(gateE.ID, new Wire(0, 1, -1, true)); }
public Decoder_3_To_8() : base(4, 8) { Gate notA = new NotGate(); int indexNotA = AddGate(notA); Gate notB = new NotGate(); int indexNotB = AddGate(notB); Gate notC = new NotGate(); int indexNotC = AddGate(notC); Gate gate0 = new ANDGate(4); int index0 = AddGate(gate0); Gate gate1 = new ANDGate(4); int index1 = AddGate(gate1); Gate gate2 = new ANDGate(4); int index2 = AddGate(gate2); Gate gate3 = new ANDGate(4); int index3 = AddGate(gate3); Gate gate4 = new ANDGate(4); int index4 = AddGate(gate4); Gate gate5 = new ANDGate(4); int index5 = AddGate(gate5); Gate gate6 = new ANDGate(4); int index6 = AddGate(gate6); Gate gate7 = new ANDGate(4); int index7 = AddGate(gate7); AddWire(ID, new Wire(0, 0, indexNotA)); AddWire(ID, new Wire(1, 0, indexNotB)); AddWire(ID, new Wire(2, 0, indexNotC)); AddWire(ID, new Wire(0, 0, index1)); AddWire(ID, new Wire(0, 0, index3)); AddWire(ID, new Wire(0, 0, index5)); AddWire(ID, new Wire(0, 0, index7)); AddWire(ID, new Wire(1, 1, index2)); AddWire(ID, new Wire(1, 1, index3)); AddWire(ID, new Wire(1, 1, index6)); AddWire(ID, new Wire(1, 1, index7)); AddWire(ID, new Wire(2, 2, index4)); AddWire(ID, new Wire(2, 2, index5)); AddWire(ID, new Wire(2, 2, index6)); AddWire(ID, new Wire(2, 2, index7)); // Enable AddWire(ID, new Wire(3, 3, index0)); AddWire(ID, new Wire(3, 3, index1)); AddWire(ID, new Wire(3, 3, index2)); AddWire(ID, new Wire(3, 3, index3)); AddWire(ID, new Wire(3, 3, index4)); AddWire(ID, new Wire(3, 3, index5)); AddWire(ID, new Wire(3, 3, index6)); AddWire(ID, new Wire(3, 3, index7)); AddWire(notA.ID, new Wire(0, 0, index0)); AddWire(notA.ID, new Wire(0, 0, index2)); AddWire(notA.ID, new Wire(0, 0, index4)); AddWire(notA.ID, new Wire(0, 0, index6)); AddWire(notB.ID, new Wire(0, 1, index0)); AddWire(notB.ID, new Wire(0, 1, index1)); AddWire(notB.ID, new Wire(0, 1, index4)); AddWire(notB.ID, new Wire(0, 1, index5)); AddWire(notC.ID, new Wire(0, 2, index0)); AddWire(notC.ID, new Wire(0, 2, index1)); AddWire(notC.ID, new Wire(0, 2, index2)); AddWire(notC.ID, new Wire(0, 2, index3)); AddWire(gate0.ID, new Wire(0, 0, -1, true)); AddWire(gate1.ID, new Wire(0, 1, -1, true)); AddWire(gate2.ID, new Wire(0, 2, -1, true)); AddWire(gate3.ID, new Wire(0, 3, -1, true)); AddWire(gate4.ID, new Wire(0, 4, -1, true)); AddWire(gate5.ID, new Wire(0, 5, -1, true)); AddWire(gate6.ID, new Wire(0, 6, -1, true)); AddWire(gate7.ID, new Wire(0, 7, -1, true)); }
public Octal_Bus_Gates() : base(18, 16) { Gate gateA = new ANDGate(); int indexA = AddGate(gateA); Gate gateB = new ANDGate(); int indexB = AddGate(gateB); Gate gateC = new NotGate(); int indexC = AddGate(gateC); Gate gateD = new NotGate(); int indexD = AddGate(gateD); Gate gateE = new ANDGate(); int indexE = AddGate(gateE); Gate gateF = new ANDGate(); int indexF = AddGate(gateF); Gate gateG = new ANDGate(); int indexG = AddGate(gateG); Gate gateH = new ANDGate(); int indexH = AddGate(gateH); Gate gateI = new ANDGate(); int indexI = AddGate(gateI); Gate gateJ = new ANDGate(); int indexJ = AddGate(gateJ); Gate gateK = new ANDGate(); int indexK = AddGate(gateK); Gate gateL = new ANDGate(); int indexL = AddGate(gateL); Gate gateM = new ANDGate(); int indexM = AddGate(gateM); Gate gateN = new ANDGate(); int indexN = AddGate(gateN); Gate gateO = new ANDGate(); int indexO = AddGate(gateO); Gate gateP = new ANDGate(); int indexP = AddGate(gateP); Gate gateQ = new ANDGate(); int indexQ = AddGate(gateQ); Gate gateR = new ANDGate(); int indexR = AddGate(gateR); Gate gateS = new ANDGate(); int indexS = AddGate(gateS); Gate gateT = new ANDGate(); int indexT = AddGate(gateT); //Inputs AddWire(ID, new Wire(0, 0, indexA, false)); AddWire(ID, new Wire(0, 0, indexC, false)); AddWire(ID, new Wire(1, 0, indexD, false)); AddWire(ID, new Wire(2, 1, indexE, false)); AddWire(ID, new Wire(3, 1, indexF, false)); AddWire(ID, new Wire(4, 1, indexG, false)); AddWire(ID, new Wire(5, 1, indexH, false)); AddWire(ID, new Wire(6, 1, indexI, false)); AddWire(ID, new Wire(7, 1, indexJ, false)); AddWire(ID, new Wire(8, 1, indexK, false)); AddWire(ID, new Wire(9, 1, indexL, false)); AddWire(ID, new Wire(10, 1, indexM, false)); AddWire(ID, new Wire(11, 1, indexN, false)); AddWire(ID, new Wire(12, 1, indexO, false)); AddWire(ID, new Wire(13, 1, indexP, false)); AddWire(ID, new Wire(14, 1, indexQ, false)); AddWire(ID, new Wire(15, 1, indexR, false)); AddWire(ID, new Wire(16, 1, indexS, false)); AddWire(ID, new Wire(17, 1, indexT, false)); //Gate A AddWire(gateA.ID, new Wire(0, 0, indexE, false)); AddWire(gateA.ID, new Wire(0, 0, indexF, false)); AddWire(gateA.ID, new Wire(0, 0, indexG, false)); AddWire(gateA.ID, new Wire(0, 0, indexH, false)); AddWire(gateA.ID, new Wire(0, 0, indexI, false)); AddWire(gateA.ID, new Wire(0, 0, indexJ, false)); AddWire(gateA.ID, new Wire(0, 0, indexK, false)); AddWire(gateA.ID, new Wire(0, 0, indexL, false)); //Gate B AddWire(gateB.ID, new Wire(0, 0, indexM, false)); AddWire(gateB.ID, new Wire(0, 0, indexN, false)); AddWire(gateB.ID, new Wire(0, 0, indexO, false)); AddWire(gateB.ID, new Wire(0, 0, indexP, false)); AddWire(gateB.ID, new Wire(0, 0, indexQ, false)); AddWire(gateB.ID, new Wire(0, 0, indexR, false)); AddWire(gateB.ID, new Wire(0, 0, indexS, false)); AddWire(gateB.ID, new Wire(0, 0, indexT, false)); //Gate C AddWire(gateC.ID, new Wire(0, 0, indexB, false)); //Gate D AddWire(gateD.ID, new Wire(0, 1, indexB, false)); AddWire(gateD.ID, new Wire(0, 1, indexA, false)); //Outputs AddWire(gateE.ID, new Wire(0, 8, -1, true)); AddWire(gateF.ID, new Wire(0, 9, -1, true)); AddWire(gateG.ID, new Wire(0, 10, -1, true)); AddWire(gateH.ID, new Wire(0, 11, -1, true)); AddWire(gateI.ID, new Wire(0, 12, -1, true)); AddWire(gateJ.ID, new Wire(0, 13, -1, true)); AddWire(gateK.ID, new Wire(0, 14, -1, true)); AddWire(gateL.ID, new Wire(0, 15, -1, true)); AddWire(gateM.ID, new Wire(0, 0, -1, true)); AddWire(gateN.ID, new Wire(0, 1, -1, true)); AddWire(gateO.ID, new Wire(0, 2, -1, true)); AddWire(gateP.ID, new Wire(0, 3, -1, true)); AddWire(gateQ.ID, new Wire(0, 4, -1, true)); AddWire(gateR.ID, new Wire(0, 5, -1, true)); AddWire(gateS.ID, new Wire(0, 6, -1, true)); AddWire(gateT.ID, new Wire(0, 7, -1, true)); }
public IEnumerator ANDTest() { SetupScene(); yield return(new WaitForSecondsRealtime(1)); GameObject ANDCHIP = Resources.Load <GameObject>("Prefabs/Lab/ANDChip"); Assert.NotNull(ANDCHIP); GameObject ANDGO = GameObject.Instantiate <GameObject>(ANDCHIP); ANDGate ANDGATE = ANDGO.GetComponent <ANDGate>(); string device_id = ANDGate.LOGIC_DEVICE_ID; yield return(new WaitForSecondsRealtime(1)); Dictionary <string, GameObject> nandNodes = ANDGATE.GetLogicDictionary(); List <GameObject> otherNodes = new List <GameObject>(); for (int i = 0; i < 14; i++) { GameObject newNode = new GameObject("OtherNODE_" + i); otherNodes.Add(newNode); } List <LogicNode> otherLogic = new List <LogicNode>(); for (int i = 0; i < 14; i++) { otherLogic.Add(otherNodes[i].AddComponent <LogicNode>()); } List <GameObject> nandNodeList = new List <GameObject>(); for (int i = 0; i < 14; i++) { GameObject DeviceNode; if (nandNodes.TryGetValue(device_id + i, out DeviceNode)) { nandNodeList.Add(DeviceNode); otherNodes[i].transform.position = nandNodeList[i].transform.position; } else { Assert.Fail(); } } yield return(new WaitForSecondsRealtime(1)); Assert.IsTrue(!ANDGATE.IsDeviceOn()); otherLogic[6].SetLogicState((int)LOGIC.LOW); otherLogic[13].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.IsTrue(!ANDGATE.IsDeviceOn()); ANDGATE.SetSnapped(true); Assert.IsTrue(ANDGATE.IsDeviceOn()); otherLogic[0].SetLogicState((int)LOGIC.LOW); otherLogic[1].SetLogicState((int)LOGIC.HIGH); otherLogic[3].SetLogicState((int)LOGIC.LOW); otherLogic[4].SetLogicState((int)LOGIC.HIGH); otherLogic[9].SetLogicState((int)LOGIC.LOW); otherLogic[8].SetLogicState((int)LOGIC.HIGH); otherLogic[12].SetLogicState((int)LOGIC.LOW); otherLogic[11].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.HIGH); otherLogic[1].SetLogicState((int)LOGIC.HIGH); otherLogic[3].SetLogicState((int)LOGIC.HIGH); otherLogic[4].SetLogicState((int)LOGIC.HIGH); otherLogic[9].SetLogicState((int)LOGIC.HIGH); otherLogic[8].SetLogicState((int)LOGIC.HIGH); otherLogic[12].SetLogicState((int)LOGIC.HIGH); otherLogic[11].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.HIGH); otherLogic[1].SetLogicState((int)LOGIC.LOW); otherLogic[3].SetLogicState((int)LOGIC.HIGH); otherLogic[4].SetLogicState((int)LOGIC.LOW); otherLogic[9].SetLogicState((int)LOGIC.HIGH); otherLogic[8].SetLogicState((int)LOGIC.LOW); otherLogic[12].SetLogicState((int)LOGIC.HIGH); otherLogic[11].SetLogicState((int)LOGIC.LOW); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.LOW); otherLogic[1].SetLogicState((int)LOGIC.LOW); otherLogic[3].SetLogicState((int)LOGIC.LOW); otherLogic[4].SetLogicState((int)LOGIC.LOW); otherLogic[9].SetLogicState((int)LOGIC.LOW); otherLogic[8].SetLogicState((int)LOGIC.LOW); otherLogic[12].SetLogicState((int)LOGIC.LOW); otherLogic[11].SetLogicState((int)LOGIC.LOW); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); yield break; }
public IEnumerator Lab1IntegrationTesting() { SceneManager.LoadScene("Scenes/Lab1Tester"); yield return(new WaitForSecondsRealtime(1)); GameObject powerSupplyGO = GameObject.Find("PowerSupply"); Assert.IsNotNull(powerSupplyGO); PowerSupplyScript powerSupply = powerSupplyGO.GetComponent <PowerSupplyScript>(); GameObject ProtoboardGO = GameObject.Find("Protoboard"); Assert.IsNotNull(ProtoboardGO); ProtoboardObject protoboardObj = ProtoboardGO.GetComponent <ProtoboardObject>(); Dictionary <string, List <GameObject> > protoboardNodes = protoboardObj.GetNodeDictionary(); GameObject ANDchip = GameObject.Find("ANDChip"); Assert.IsNotNull(ANDchip); ANDGate Andscript = ANDchip.GetComponent <ANDGate>(); GameObject ORchip = GameObject.Find("ORChip"); Assert.IsNotNull(ORchip); ORGate Orscript = ORchip.GetComponent <ORGate>(); GameObject switch1 = GameObject.Find("Switch"); Assert.IsNotNull(switch1); Switch switch1script = switch1.GetComponent <Switch>(); GameObject switch2 = GameObject.Find("Switch (1)"); Assert.IsNotNull(switch2); Switch switch2script = switch2.GetComponent <Switch>(); GameObject switch3 = GameObject.Find("Switch (2)"); Assert.IsNotNull(switch3); Switch switch3script = switch3.GetComponent <Switch>(); GameObject led = GameObject.Find("LEDChip"); Assert.IsNotNull(led); LEDScript ledScript = led.GetComponent <LEDScript>(); GameObject InputA = GameObject.Find("InputA"); Assert.IsNotNull(InputA); CheckerTagScript aScript = InputA.GetComponent <CheckerTagScript>(); GameObject InputB = GameObject.Find("InputB"); Assert.IsNotNull(InputB); CheckerTagScript bScript = InputA.GetComponent <CheckerTagScript>(); GameObject InputC = GameObject.Find("InputC"); Assert.IsNotNull(InputC); CheckerTagScript cScript = InputA.GetComponent <CheckerTagScript>(); GameObject OutputF = GameObject.Find("OutputF"); Assert.IsNotNull(OutputF); CheckerTagScript fScript = InputA.GetComponent <CheckerTagScript>(); yield return(new WaitForSecondsRealtime(.1f)); Andscript.OnMouseUp(); Orscript.OnMouseUp(); switch1script.OnMouseUp(); switch2script.OnMouseUp(); switch3script.OnMouseUp(); aScript.OnMouseUp(); bScript.OnMouseUp(); cScript.OnMouseUp(); fScript.OnMouseUp(); ledScript.OnMouseUp(); yield return(new WaitForSecondsRealtime(.1f)); Assert.IsTrue(Andscript.isSnapped()); Assert.IsTrue(Orscript.isSnapped()); Assert.IsTrue(ledScript.isSnapped()); Assert.IsTrue(switch1script.isSnapped()); Assert.IsTrue(switch2script.isSnapped()); Assert.IsTrue(switch3script.isSnapped()); Assert.IsTrue(aScript.isSnapped()); Assert.IsTrue(bScript.isSnapped()); Assert.IsTrue(cScript.isSnapped()); Assert.IsTrue(fScript.isSnapped()); Wire wire1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1); List <GameObject> leftList; protoboardNodes.TryGetValue("leftlogicnode_LEFT", out leftList); Assert.IsNotNull(leftList); GameObject topLeftNode = leftList[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1.SetNodePositions(powerSupply.GetVccNode().transform.position, topLeftNode.transform.position); Wire wire2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire2); List <GameObject> rightList; protoboardNodes.TryGetValue("leftlogicnode_RIGHT", out rightList); Assert.IsNotNull(rightList); GameObject topRightNode = rightList[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2.SetNodePositions(powerSupply.GetGndNode().transform.position, topRightNode.transform.position); Wire wire1switch1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist; protoboardNodes.TryGetValue("m_farleftnode_0", out farleftnodetoplist); Assert.IsNotNull(rightList); GameObject farleftnodetop = farleftnodetoplist[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch1.SetNodePositions(leftList[1].transform.position, farleftnodetop.transform.position); Wire wire2switch1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist2; protoboardNodes.TryGetValue("m_farleftnode_2", out farleftnodetoplist2); Assert.IsNotNull(rightList); GameObject farleftnodetop2 = farleftnodetoplist2[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch1.SetNodePositions(rightList[1].transform.position, farleftnodetop2.transform.position); Wire wire1switch2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist4; protoboardNodes.TryGetValue("m_farleftnode_4", out farleftnodetoplist4); Assert.IsNotNull(rightList); GameObject farleftnodetop4 = farleftnodetoplist4[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch2.SetNodePositions(leftList[2].transform.position, farleftnodetop4.transform.position); Wire wire2switch2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist6; protoboardNodes.TryGetValue("m_farleftnode_6", out farleftnodetoplist6); Assert.IsNotNull(rightList); GameObject farleftnodetop6 = farleftnodetoplist6[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch2.SetNodePositions(rightList[2].transform.position, farleftnodetop6.transform.position); Wire wire1switch3 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist8; protoboardNodes.TryGetValue("m_farleftnode_8", out farleftnodetoplist8); Assert.IsNotNull(rightList); GameObject farleftnodetop8 = farleftnodetoplist8[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch3.SetNodePositions(leftList[2].transform.position, farleftnodetop8.transform.position); Wire wire2switch3 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist10; protoboardNodes.TryGetValue("m_farleftnode_10", out farleftnodetoplist10); Assert.IsNotNull(rightList); GameObject farleftnodetop10 = farleftnodetoplist10[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch3.SetNodePositions(rightList[2].transform.position, farleftnodetop10.transform.position); //ledground Wire wire2ledgnd = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farfarrightnodelist; protoboardNodes.TryGetValue("rightlogicnode_LEFT", out farfarrightnodelist); Assert.IsNotNull(rightList); GameObject farfarrightnode = farfarrightnodelist[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch3.SetNodePositions(rightList[3].transform.position, farfarrightnode.transform.position); //Setupchips Wire wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node1list, node2list; protoboardNodes.TryGetValue("m_farleftnode_1", out node1list); protoboardNodes.TryGetValue("m_leftnode_0", out node2list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); GameObject node1, node2; node1 = node1list[0]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node3list, node4list; protoboardNodes.TryGetValue("m_farleftnode_9", out node3list); protoboardNodes.TryGetValue("m_leftnode_1", out node4list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node3list[0]; node2 = node4list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node5list, node6list; protoboardNodes.TryGetValue("m_leftnode_2", out node5list); protoboardNodes.TryGetValue("m_leftnode_10", out node6list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node5list[0]; node2 = node6list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node7list, node8list; protoboardNodes.TryGetValue("m_farleftnode_5", out node7list); protoboardNodes.TryGetValue("m_leftnode_11", out node8list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node7list[0]; node2 = node8list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node9list, node10list; protoboardNodes.TryGetValue("m_farrightnode_21", out node9list); protoboardNodes.TryGetValue("m_leftnode_12", out node10list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node9list[0]; node2 = node10list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_leftnode_6", out node2list); Assert.IsNotNull(node2list); node1 = rightList[5]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_leftnode_16", out node2list); Assert.IsNotNull(rightList); node1 = rightList[6]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_rightnode_0", out node2list); Assert.IsNotNull(rightList); node1 = leftList[6]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_rightnode_10", out node2list); Assert.IsNotNull(rightList); node1 = leftList[7]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(10)); yield break; }
public Bcd_To_Dec() : base(4, 10) { Gate notA = new NotGate(); int indexNotA = AddGate(notA); Gate notB = new NotGate(); int indexNotB = AddGate(notB); Gate notC = new NotGate(); int indexNotC = AddGate(notC); Gate notD = new NotGate(); int indexNotD = AddGate(notD); Gate gate0 = new ANDGate(4); int index0 = AddGate(gate0); Gate gate1 = new ANDGate(4); int index1 = AddGate(gate1); Gate gate2 = new ANDGate(4); int index2 = AddGate(gate2); Gate gate3 = new ANDGate(4); int index3 = AddGate(gate3); Gate gate4 = new ANDGate(4); int index4 = AddGate(gate4); Gate gate5 = new ANDGate(4); int index5 = AddGate(gate5); Gate gate6 = new ANDGate(4); int index6 = AddGate(gate6); Gate gate7 = new ANDGate(4); int index7 = AddGate(gate7); Gate gate8 = new ANDGate(4); int index8 = AddGate(gate8); Gate gate9 = new ANDGate(4); int index9 = AddGate(gate9); AddWire(ID, new Wire(0, 0, indexNotA)); AddWire(ID, new Wire(1, 0, indexNotB)); AddWire(ID, new Wire(2, 0, indexNotC)); AddWire(ID, new Wire(3, 0, indexNotD)); AddWire(ID, new Wire(0, 0, index1)); AddWire(ID, new Wire(0, 0, index3)); AddWire(ID, new Wire(0, 0, index5)); AddWire(ID, new Wire(0, 0, index7)); AddWire(ID, new Wire(0, 0, index9)); AddWire(ID, new Wire(1, 1, index2)); AddWire(ID, new Wire(1, 1, index3)); AddWire(ID, new Wire(1, 1, index6)); AddWire(ID, new Wire(1, 1, index7)); AddWire(ID, new Wire(2, 2, index4)); AddWire(ID, new Wire(2, 2, index5)); AddWire(ID, new Wire(2, 2, index6)); AddWire(ID, new Wire(2, 2, index7)); AddWire(ID, new Wire(3, 3, index8)); AddWire(ID, new Wire(3, 3, index9)); AddWire(notA.ID, new Wire(0, 0, index0)); AddWire(notA.ID, new Wire(0, 0, index2)); AddWire(notA.ID, new Wire(0, 0, index4)); AddWire(notA.ID, new Wire(0, 0, index6)); AddWire(notA.ID, new Wire(0, 0, index8)); AddWire(notB.ID, new Wire(0, 1, index0)); AddWire(notB.ID, new Wire(0, 1, index1)); AddWire(notB.ID, new Wire(0, 1, index4)); AddWire(notB.ID, new Wire(0, 1, index5)); AddWire(notB.ID, new Wire(0, 1, index8)); AddWire(notB.ID, new Wire(0, 1, index9)); AddWire(notC.ID, new Wire(0, 2, index0)); AddWire(notC.ID, new Wire(0, 2, index1)); AddWire(notC.ID, new Wire(0, 2, index2)); AddWire(notC.ID, new Wire(0, 2, index3)); AddWire(notC.ID, new Wire(0, 2, index8)); AddWire(notC.ID, new Wire(0, 2, index9)); AddWire(notD.ID, new Wire(0, 3, index0)); AddWire(notD.ID, new Wire(0, 3, index1)); AddWire(notD.ID, new Wire(0, 3, index2)); AddWire(notD.ID, new Wire(0, 3, index3)); AddWire(notD.ID, new Wire(0, 3, index4)); AddWire(notD.ID, new Wire(0, 3, index5)); AddWire(notD.ID, new Wire(0, 3, index6)); AddWire(notD.ID, new Wire(0, 3, index7)); AddWire(gate0.ID, new Wire(0, 0, -1, true)); AddWire(gate1.ID, new Wire(0, 1, -1, true)); AddWire(gate2.ID, new Wire(0, 2, -1, true)); AddWire(gate3.ID, new Wire(0, 3, -1, true)); AddWire(gate4.ID, new Wire(0, 4, -1, true)); AddWire(gate5.ID, new Wire(0, 5, -1, true)); AddWire(gate6.ID, new Wire(0, 6, -1, true)); AddWire(gate7.ID, new Wire(0, 7, -1, true)); AddWire(gate8.ID, new Wire(0, 8, -1, true)); AddWire(gate9.ID, new Wire(0, 9, -1, true)); }
/// <summary> /// Composes two gates with the logical AND operator. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns>The resulting gate.</returns> public static IGate ComposeAND(IGate a, IGate b) { IGate result; DecomposeExchange(ref a, ref b); if (a.Type == GateType.Fixed && b.Type == GateType.Fixed) { if (a is TrueGate && b is TrueGate) { result = new TrueGate(); } else { result = new FalseGate(); } } else if (b.Type == GateType.Fixed) { if (b is TrueGate) { result = a; } else { result = new FalseGate(); } } else if (a.Type == GateType.OR && b.Type == GateType.OR) { result = Multiply(a.GetInputs(), b.GetInputs()); } else if (a.Type == GateType.OR) { result = Multiply(a.GetInputs(), b); } else if (a.Type == GateType.AND && b.Type == GateType.AND) { // compose var r = new ANDGate(); r.AddInputRange(a.GetInputs()); r.AddInputRange(b.GetInputs()); result = r; } else if (a.Type == GateType.AND) { // compose var r = new ANDGate(); r.AddInputRange(a.GetInputs()); r.AddInput(b); result = r; } else { var r = new ANDGate(); r.AddInput(a); r.AddInput(b); result = r; } // simplify and cache result = Simplify(result); TraceCompose(a, b, result, "AND"); return(result); }
/// <summary> /// Data = 0-7, /// Clk = 8, /// OE = 9 /// /// Q = 0-7 /// </summary> public Octal_D_FlipFlop() : base(10, 8) { D_FlipFlop_Re chip1 = new D_FlipFlop_Re(); int index1 = AddChip(chip1); D_FlipFlop_Re chip2 = new D_FlipFlop_Re(); int index2 = AddChip(chip2); D_FlipFlop_Re chip3 = new D_FlipFlop_Re(); int index3 = AddChip(chip3); D_FlipFlop_Re chip4 = new D_FlipFlop_Re(); int index4 = AddChip(chip4); D_FlipFlop_Re chip5 = new D_FlipFlop_Re(); int index5 = AddChip(chip5); D_FlipFlop_Re chip6 = new D_FlipFlop_Re(); int index6 = AddChip(chip6); D_FlipFlop_Re chip7 = new D_FlipFlop_Re(); int index7 = AddChip(chip7); D_FlipFlop_Re chip8 = new D_FlipFlop_Re(); int index8 = AddChip(chip8); ANDGate gate1 = new ANDGate(); int i1 = AddGate(gate1); ANDGate gate2 = new ANDGate(); int i2 = AddGate(gate2); ANDGate gate3 = new ANDGate(); int i3 = AddGate(gate3); ANDGate gate4 = new ANDGate(); int i4 = AddGate(gate4); ANDGate gate5 = new ANDGate(); int i5 = AddGate(gate5); ANDGate gate6 = new ANDGate(); int i6 = AddGate(gate6); ANDGate gate7 = new ANDGate(); int i7 = AddGate(gate7); ANDGate gate8 = new ANDGate(); int i8 = AddGate(gate8); Gate gateA = AddGateIndexed(new NotGate()); // OE AddInputWire(new Wire(9, 0, gateA)); // Clk AddInputWires(Wire.Create(8, 0, false, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8)); // Data AddWire(ID, new Wire(0, 1, index1, true)); AddWire(ID, new Wire(1, 1, index2, true)); AddWire(ID, new Wire(2, 1, index3, true)); AddWire(ID, new Wire(3, 1, index4, true)); AddWire(ID, new Wire(4, 1, index5, true)); AddWire(ID, new Wire(5, 1, index6, true)); AddWire(ID, new Wire(6, 1, index7, true)); AddWire(ID, new Wire(7, 1, index8, true)); // Gate A AddWires(gateA, Wire.Create(0, 1, false, gate1, gate2, gate3, gate4, gate5, gate6, gate7, gate8)); // D FF AddWire(chip1, new Wire(0, 0, i1)); AddWire(chip2, new Wire(0, 0, i2)); AddWire(chip3, new Wire(0, 0, i3)); AddWire(chip4, new Wire(0, 0, i4)); AddWire(chip5, new Wire(0, 0, i5)); AddWire(chip6, new Wire(0, 0, i6)); AddWire(chip7, new Wire(0, 0, i7)); AddWire(chip8, new Wire(0, 0, i8)); // Output AddWire(gate1, new Wire(0, 0, -1, true)); AddWire(gate2, new Wire(0, 1, -1, true)); AddWire(gate3, new Wire(0, 2, -1, true)); AddWire(gate4, new Wire(0, 3, -1, true)); AddWire(gate5, new Wire(0, 4, -1, true)); AddWire(gate6, new Wire(0, 5, -1, true)); AddWire(gate7, new Wire(0, 6, -1, true)); AddWire(gate8, new Wire(0, 7, -1, true)); }
/// <summary> /// J = 0, /// K = 1, /// CLK = 2, /// CLR = 3 /// /// Q = 0, /// Q' = 1 /// </summary> public JK_FlipFlop_Clr() : base(4, 2) { ScrubOutput = true; Gate Not = new NotGate(); int indexNot = AddGate(Not); Gate GateA = new ANDGate(3); int indexA = AddGate(GateA); Gate GateB = new ANDGate(3); int indexB = AddGate(GateB); Gate GateC = new NORGate(); int indexC = AddGate(GateC); Gate GateD = new NORGate(3); int indexD = AddGate(GateD); Gate GateE = new ANDGate(); int indexE = AddGate(GateE); Gate GateF = new ANDGate(); int indexF = AddGate(GateF); Gate GateG = new NORGate(); int indexG = AddGate(GateG); Gate GateH = new NORGate(); int indexH = AddGate(GateH); // Not AddWire(ID, new Wire(2, 0, indexNot)); AddWire(Not.ID, new Wire(0, 1, indexE)); AddWire(Not.ID, new Wire(0, 0, indexF)); // J AddWire(ID, new Wire(0, 1, indexA)); // K AddWire(ID, new Wire(1, 1, indexB)); // CLK AddWire(ID, new Wire(2, 2, indexA)); AddWire(ID, new Wire(2, 0, indexB)); // Clr AddWire(ID, new Wire(3, 2, indexD)); // A AddWire(GateA.ID, new Wire(0, 0, indexC)); // B AddWire(GateB.ID, new Wire(0, 1, indexD)); // C AddWire(GateC.ID, new Wire(0, 0, indexD)); AddWire(GateC.ID, new Wire(0, 0, indexE)); // D AddWire(GateD.ID, new Wire(0, 1, indexC)); AddWire(GateD.ID, new Wire(0, 1, indexF)); // E AddWire(GateE.ID, new Wire(0, 0, indexG)); // F AddWire(GateF.ID, new Wire(0, 1, indexH)); // G AddWire(GateG.ID, new Wire(0, 0, indexH)); AddWire(GateG.ID, new Wire(0, 2, indexB)); AddWire(GateG.ID, new Wire(0, 0, -1, true)); // H AddWire(GateH.ID, new Wire(0, 1, indexG)); AddWire(GateH.ID, new Wire(0, 0, indexA)); AddWire(GateH.ID, new Wire(0, 1, -1, true)); }
public static IGate ExtractCommonFactors(IGate gate) { var original = gate; if (gate.Type == GateType.OR) { // TraceOptimize("extract common factors from {0} ...", gate); var sop = gate.GetSOP(); // count how many times each factor appears var inmap = new Dictionary <int, IInput>(); var dict = new SortedList <int, int>(); foreach (var p in sop.GetPrimitiveFactors()) { // a gate representing the factors (may be multiple per state variable) var pg = p.ToGate(); foreach (var i in pg.GetInputs().OfType <IInput>()) { var address = i.Address; // TraceOptimize("check factor {0} @ {1:X6}", i, address); if (!inmap.ContainsKey(i.Address)) { inmap.Add(i.Address, i); } if (!dict.ContainsKey(address)) { dict[address] = 1; } else { dict[address]++; } } } var m = dict.Values.Max(); // TraceOptimize("maximum factor count {0}", m); if (m > 1) { // go for it, take the first input with maximum multiplicity, inputs are ordered. var pivotindex = dict.Where(e => e.Value == m).Select(e => e.Key).First(); var pivot = inmap[pivotindex]; var pivotlist = new List <Product>(); var otherlist = new List <Product>(); TraceOptimize("use pivot {0:X6} ...", pivot); // split sop into two groups: factor or not foreach (var p in sop) { if (p.ContainsFactor(pivot)) { p.RemoveInput(pivot); pivotlist.Add(p); } else { otherlist.Add(p); } } IGate and = new ANDGate(); and.AddInput(pivot); IGate inneror = new ORGate(); foreach (var p in pivotlist) { var z = p.ToGate().Simplify(); // Debug.Assert(z.GetInputs().Count() > 1); Trace("adding pivot {0} [{1}]", z, z.GetType().Name); inneror.AddInput(z); } inneror = ExtractCommonFactors(inneror); and.AddInput(inneror); if (otherlist.Any()) { //var rh = ExtractCommonFactors(otherlist); var or = new ORGate(); or.AddInput(and); foreach (var p in otherlist) { var z = p.ToGate(); or.AddInput(z.Simplify()); } gate = or; } else { gate = and; } } } if (gate != original && TraceFlags.ShowOptimize) { Log.TraceGateOp2(original, gate, "optimize AND"); } return(gate); }
public Quad_2_To_1_Selector() : base(10, 4) { ANDGate gateA0 = new ANDGate(3); int indexA0 = AddGate(gateA0); ANDGate gateA1 = new ANDGate(3); int indexA1 = AddGate(gateA1); ANDGate gateA2 = new ANDGate(3); int indexA2 = AddGate(gateA2); ANDGate gateA3 = new ANDGate(3); int indexA3 = AddGate(gateA3); ANDGate gateB0 = new ANDGate(3); int indexB0 = AddGate(gateB0); ANDGate gateB1 = new ANDGate(3); int indexB1 = AddGate(gateB1); ANDGate gateB2 = new ANDGate(3); int indexB2 = AddGate(gateB2); ANDGate gateB3 = new ANDGate(3); int indexB3 = AddGate(gateB3); ORGate gate0 = new ORGate(); int index0 = AddGate(gate0); ORGate gate1 = new ORGate(); int index1 = AddGate(gate1); ORGate gate2 = new ORGate(); int index2 = AddGate(gate2); ORGate gate3 = new ORGate(); int index3 = AddGate(gate3); AddWire(ID, new Wire(0, 0, indexA0)); AddWire(ID, new Wire(1, 0, indexA1)); AddWire(ID, new Wire(2, 0, indexA2)); AddWire(ID, new Wire(3, 0, indexA3)); AddWire(ID, new Wire(4, 0, indexB0)); AddWire(ID, new Wire(5, 0, indexB1)); AddWire(ID, new Wire(6, 0, indexB2)); AddWire(ID, new Wire(7, 0, indexB3)); AddWire(ID, new Wire(8, 1, indexA0, false, true)); AddWire(ID, new Wire(8, 1, indexA1, false, true)); AddWire(ID, new Wire(8, 1, indexA2, false, true)); AddWire(ID, new Wire(8, 1, indexA3, false, true)); AddWire(ID, new Wire(8, 1, indexB0)); AddWire(ID, new Wire(8, 1, indexB1)); AddWire(ID, new Wire(8, 1, indexB2)); AddWire(ID, new Wire(8, 1, indexB3)); AddWire(ID, new Wire(9, 2, indexA0, false, true)); AddWire(ID, new Wire(9, 2, indexA1, false, true)); AddWire(ID, new Wire(9, 2, indexA2, false, true)); AddWire(ID, new Wire(9, 2, indexA3, false, true)); AddWire(ID, new Wire(9, 2, indexB0, false, true)); AddWire(ID, new Wire(9, 2, indexB1, false, true)); AddWire(ID, new Wire(9, 2, indexB2, false, true)); AddWire(ID, new Wire(9, 2, indexB3, false, true)); AddWire(gateA0, new Wire(0, 0, index0)); AddWire(gateA1, new Wire(0, 0, index1)); AddWire(gateA2, new Wire(0, 0, index2)); AddWire(gateA3, new Wire(0, 0, index3)); AddWire(gateB0, new Wire(0, 1, index0)); AddWire(gateB1, new Wire(0, 1, index1)); AddWire(gateB2, new Wire(0, 1, index2)); AddWire(gateB3, new Wire(0, 1, index3)); AddWire(gate0, new Wire(0, 0, -1, true)); AddWire(gate1, new Wire(0, 1, -1, true)); AddWire(gate2, new Wire(0, 2, -1, true)); AddWire(gate3, new Wire(0, 3, -1, true)); }
public Bcd_To_Seg() : base(4, 7) { // Column 1 Gate gateA = new NotGate(); int indexA = AddGate(gateA); Gate gateB = new NotGate(); int indexB = AddGate(gateB); Gate gateC = new NotGate(); int indexC = AddGate(gateC); // Column 2 Gate gateD = new ANDGate(); int indexD = AddGate(gateD); Gate gateE = new ANDGate(); int indexE = AddGate(gateE); Gate gateF = new ANDGate(); int indexF = AddGate(gateF); Gate gateG = new ANDGate(); int indexG = AddGate(gateG); Gate gateH = new ANDGate(); int indexH = AddGate(gateH); Gate gateI = new ANDGate(); int indexI = AddGate(gateI); Gate gateJ = new ANDGate(3); int indexJ = AddGate(gateJ); Gate gateK = new ANDGate(); int indexK = AddGate(gateK); Gate gateL = new ANDGate(); int indexL = AddGate(gateL); // Column 3 Gate gateM = new ORGate(4); int indexM = AddGate(gateM); Gate gateN = new ORGate(4); int indexN = AddGate(gateN); Gate gateO = new ORGate(4); int indexO = AddGate(gateO); Gate gateP = new ORGate(5); int indexP = AddGate(gateP); Gate gateQ = new ORGate(); int indexQ = AddGate(gateQ); Gate gateR = new ORGate(4); int indexR = AddGate(gateR); Gate gateS = new ORGate(4); int indexS = AddGate(gateS); //Input A AddWire(ID, new Wire(0, 0, indexM, false)); AddWire(ID, new Wire(0, 0, indexN, false)); AddWire(ID, new Wire(0, 0, indexO, false)); AddWire(ID, new Wire(0, 0, indexP, false)); AddWire(ID, new Wire(0, 0, indexR, false)); AddWire(ID, new Wire(0, 0, indexS, false)); //Input B AddWire(ID, new Wire(1, 0, indexA, false)); AddWire(ID, new Wire(1, 0, indexE, false)); AddWire(ID, new Wire(1, 0, indexF, false)); AddWire(ID, new Wire(1, 0, indexJ, false)); AddWire(ID, new Wire(1, 0, indexL, false)); AddWire(ID, new Wire(1, 1, indexO, false)); //Input C AddWire(ID, new Wire(2, 0, indexB, false)); AddWire(ID, new Wire(2, 0, indexG, false)); AddWire(ID, new Wire(2, 0, indexI, false)); AddWire(ID, new Wire(2, 1, indexK, false)); AddWire(ID, new Wire(2, 3, indexM, false)); //Input D AddWire(ID, new Wire(3, 0, indexC, false)); AddWire(ID, new Wire(3, 1, indexE, false)); AddWire(ID, new Wire(3, 1, indexG, false)); AddWire(ID, new Wire(3, 2, indexJ, false)); AddWire(ID, new Wire(3, 2, indexO, false)); //Gate A AddWire(gateA.ID, new Wire(0, 0, indexD, false)); AddWire(gateA.ID, new Wire(0, 1, indexN, false)); AddWire(gateA.ID, new Wire(0, 0, indexK, false)); //Gate B AddWire(gateB.ID, new Wire(0, 0, indexH, false)); AddWire(gateB.ID, new Wire(0, 1, indexJ, false)); AddWire(gateB.ID, new Wire(0, 1, indexL, false)); //Gate C AddWire(gateC.ID, new Wire(0, 1, indexD, false)); AddWire(gateC.ID, new Wire(0, 1, indexF, false)); AddWire(gateC.ID, new Wire(0, 1, indexH, false)); AddWire(gateC.ID, new Wire(0, 1, indexI, false)); //Gate D AddWire(gateD.ID, new Wire(0, 1, indexM, false)); AddWire(gateD.ID, new Wire(0, 1, indexP, false)); AddWire(gateD.ID, new Wire(0, 0, indexQ, false)); //Gate E AddWire(gateE.ID, new Wire(0, 2, indexM, false)); //Gate F AddWire(gateF.ID, new Wire(0, 1, indexR, false)); //Gate G AddWire(gateG.ID, new Wire(0, 2, indexN, false)); //Gate H AddWire(gateH.ID, new Wire(0, 3, indexN, false)); AddWire(gateH.ID, new Wire(0, 3, indexO, false)); AddWire(gateH.ID, new Wire(0, 2, indexR, false)); //Gate I AddWire(gateI.ID, new Wire(0, 2, indexP, false)); AddWire(gateI.ID, new Wire(0, 1, indexQ, false)); AddWire(gateI.ID, new Wire(0, 1, indexS, false)); //Gate J AddWire(gateJ.ID, new Wire(0, 3, indexP, false)); //Gate K AddWire(gateK.ID, new Wire(0, 4, indexP, false)); AddWire(gateK.ID, new Wire(0, 2, indexS, false)); //Gate L AddWire(gateL.ID, new Wire(0, 3, indexR, false)); AddWire(gateL.ID, new Wire(0, 3, indexS, false)); //Gate M AddWire(gateM.ID, new Wire(0, 0, -1, true)); //Gate N AddWire(gateN.ID, new Wire(0, 1, -1, true)); //Gate O AddWire(gateO.ID, new Wire(0, 2, -1, true)); //Gate P AddWire(gateP.ID, new Wire(0, 3, -1, true)); //Gate Q AddWire(gateQ.ID, new Wire(0, 4, -1, true)); //Gate R AddWire(gateR.ID, new Wire(0, 5, -1, true)); //Gate S AddWire(gateS.ID, new Wire(0, 6, -1, true)); }
/// <summary> /// OE = 0, /// RCLK = 1, /// SRCLR = 2, /// SRCLK = 3, /// SER = 4 /// </summary> public Shift_Register_8Bit() : base(6, 9) { KeepDirty = true; // Shift Latches D_FlipFlop_Re S1 = new D_FlipFlop_Re(); int indexS1 = AddChip(S1); D_FlipFlop_Re S2 = new D_FlipFlop_Re(); int indexS2 = AddChip(S2); D_FlipFlop_Re S3 = new D_FlipFlop_Re(); int indexS3 = AddChip(S3); D_FlipFlop_Re S4 = new D_FlipFlop_Re(); int indexS4 = AddChip(S4); D_FlipFlop_Re S5 = new D_FlipFlop_Re(); int indexS5 = AddChip(S5); D_FlipFlop_Re S6 = new D_FlipFlop_Re(); int indexS6 = AddChip(S6); D_FlipFlop_Re S7 = new D_FlipFlop_Re(); int indexS7 = AddChip(S7); D_FlipFlop_Re S8 = new D_FlipFlop_Re(); int indexS8 = AddChip(S8); // Register Latches D_FlipFlop_Re R1 = new D_FlipFlop_Re(); int indexR1 = AddChip(R1); D_FlipFlop_Re R2 = new D_FlipFlop_Re(); int indexR2 = AddChip(R2); D_FlipFlop_Re R3 = new D_FlipFlop_Re(); int indexR3 = AddChip(R3); D_FlipFlop_Re R4 = new D_FlipFlop_Re(); int indexR4 = AddChip(R4); D_FlipFlop_Re R5 = new D_FlipFlop_Re(); int indexR5 = AddChip(R5); D_FlipFlop_Re R6 = new D_FlipFlop_Re(); int indexR6 = AddChip(R6); D_FlipFlop_Re R7 = new D_FlipFlop_Re(); int indexR7 = AddChip(R7); D_FlipFlop_Re R8 = new D_FlipFlop_Re(); int indexR8 = AddChip(R8); // Output Enables ANDGate O1 = new ANDGate(); int indexO1 = AddGate(O1); ANDGate O2 = new ANDGate(); int indexO2 = AddGate(O2); ANDGate O3 = new ANDGate(); int indexO3 = AddGate(O3); ANDGate O4 = new ANDGate(); int indexO4 = AddGate(O4); ANDGate O5 = new ANDGate(); int indexO5 = AddGate(O5); ANDGate O6 = new ANDGate(); int indexO6 = AddGate(O6); ANDGate O7 = new ANDGate(); int indexO7 = AddGate(O7); ANDGate O8 = new ANDGate(); int indexO8 = AddGate(O8); // INs NotGate OE = new NotGate(); int indexOE = AddGate(OE); BufferGate RCLK = new BufferGate(); int indexRCLK = AddGate(RCLK); // SER AddWire(ID, new Wire(4, 1, indexS1, true)); // SRCLR AddWire(ID, new Wire(2, 2, indexS1, true, true)); AddWire(ID, new Wire(2, 2, indexS2, true, true)); AddWire(ID, new Wire(2, 2, indexS3, true, true)); AddWire(ID, new Wire(2, 2, indexS4, true, true)); AddWire(ID, new Wire(2, 2, indexS5, true, true)); AddWire(ID, new Wire(2, 2, indexS6, true, true)); AddWire(ID, new Wire(2, 2, indexS7, true, true)); AddWire(ID, new Wire(2, 2, indexS8, true, true)); AddWire(ID, new Wire(5, 3, indexS1, true)); AddWire(ID, new Wire(5, 3, indexS2, true)); AddWire(ID, new Wire(5, 3, indexS3, true)); AddWire(ID, new Wire(5, 3, indexS4, true)); AddWire(ID, new Wire(5, 3, indexS5, true)); AddWire(ID, new Wire(5, 3, indexS6, true)); AddWire(ID, new Wire(5, 3, indexS7, true)); AddWire(ID, new Wire(5, 3, indexS8, true)); AddWire(ID, new Wire(5, 3, indexR1, true)); AddWire(ID, new Wire(5, 3, indexR2, true)); AddWire(ID, new Wire(5, 3, indexR3, true)); AddWire(ID, new Wire(5, 3, indexR4, true)); AddWire(ID, new Wire(5, 3, indexR5, true)); AddWire(ID, new Wire(5, 3, indexR6, true)); AddWire(ID, new Wire(5, 3, indexR7, true)); AddWire(ID, new Wire(5, 3, indexR8, true)); // SRCLK AddWire(ID, new Wire(3, 0, indexS1, true)); AddWire(ID, new Wire(3, 0, indexS2, true)); AddWire(ID, new Wire(3, 0, indexS3, true)); AddWire(ID, new Wire(3, 0, indexS4, true)); AddWire(ID, new Wire(3, 0, indexS5, true)); AddWire(ID, new Wire(3, 0, indexS6, true)); AddWire(ID, new Wire(3, 0, indexS7, true)); AddWire(ID, new Wire(3, 0, indexS8, true)); // RCLK AddWire(ID, new Wire(1, 0, indexRCLK)); AddWire(RCLK, new Wire(0, 0, indexR1, true)); AddWire(RCLK, new Wire(0, 0, indexR2, true)); AddWire(RCLK, new Wire(0, 0, indexR3, true)); AddWire(RCLK, new Wire(0, 0, indexR4, true)); AddWire(RCLK, new Wire(0, 0, indexR5, true)); AddWire(RCLK, new Wire(0, 0, indexR6, true)); AddWire(RCLK, new Wire(0, 0, indexR7, true)); AddWire(RCLK, new Wire(0, 0, indexR8, true)); // OE AddWire(ID, new Wire(0, 0, indexOE)); AddWire(OE, new Wire(0, 1, indexO1)); AddWire(OE, new Wire(0, 1, indexO2)); AddWire(OE, new Wire(0, 1, indexO3)); AddWire(OE, new Wire(0, 1, indexO4)); AddWire(OE, new Wire(0, 1, indexO5)); AddWire(OE, new Wire(0, 1, indexO6)); AddWire(OE, new Wire(0, 1, indexO7)); AddWire(OE, new Wire(0, 1, indexO8)); // OEs AddWire(O1, new Wire(0, 0, -1, true)); AddWire(O2, new Wire(0, 1, -1, true)); AddWire(O3, new Wire(0, 2, -1, true)); AddWire(O4, new Wire(0, 3, -1, true)); AddWire(O5, new Wire(0, 4, -1, true)); AddWire(O6, new Wire(0, 5, -1, true)); AddWire(O7, new Wire(0, 6, -1, true)); AddWire(O8, new Wire(0, 7, -1, true)); //AddWire(S1, new Wire(0, 0, -1, true)); //AddWire(S2, new Wire(0, 1, -1, true)); //AddWire(S3, new Wire(0, 2, -1, true)); //AddWire(S4, new Wire(0, 3, -1, true)); //AddWire(S5, new Wire(0, 4, -1, true)); //AddWire(S6, new Wire(0, 5, -1, true)); //AddWire(S7, new Wire(0, 6, -1, true)); //AddWire(S8, new Wire(0, 7, -1, true)); //SR->R AddWire(S1, new Wire(0, 1, indexR1, true)); AddWire(S1, new Wire(0, 1, indexS2, true)); AddWire(S2, new Wire(0, 1, indexR2, true)); AddWire(S2, new Wire(0, 1, indexS3, true)); AddWire(S3, new Wire(0, 1, indexR3, true)); AddWire(S3, new Wire(0, 1, indexS4, true)); AddWire(S4, new Wire(0, 1, indexR4, true)); AddWire(S4, new Wire(0, 1, indexS5, true)); AddWire(S5, new Wire(0, 1, indexR5, true)); AddWire(S5, new Wire(0, 1, indexS6, true)); AddWire(S6, new Wire(0, 1, indexR6, true)); AddWire(S6, new Wire(0, 1, indexS7, true)); AddWire(S7, new Wire(0, 1, indexR7, true)); AddWire(S7, new Wire(0, 1, indexS8, true)); AddWire(S8, new Wire(0, 1, indexR8, true)); AddWire(S8, new Wire(1, 8, -1, true)); //R->OE AddWire(R1, new Wire(0, 0, indexO1)); AddWire(R2, new Wire(0, 0, indexO2)); AddWire(R3, new Wire(0, 0, indexO3)); AddWire(R4, new Wire(0, 0, indexO4)); AddWire(R5, new Wire(0, 0, indexO5)); AddWire(R6, new Wire(0, 0, indexO6)); AddWire(R7, new Wire(0, 0, indexO7)); AddWire(R8, new Wire(0, 0, indexO8)); }
public override void Initialize() { base.Initialize(); par = parent as ANDGate; }
public Dual_Decode_2_To_4() : base(6, 8) { // 2 to 4 Decoder ---------------------------------- NotGate notA = new NotGate(); int indexA = AddGate(notA); NotGate notB = new NotGate(); int indexB = AddGate(notB); ANDGate gate0 = new ANDGate(3); int index0 = AddGate(gate0); ANDGate gate1 = new ANDGate(3); int index1 = AddGate(gate1); ANDGate gate2 = new ANDGate(3); int index2 = AddGate(gate2); ANDGate gate3 = new ANDGate(3); int index3 = AddGate(gate3); AddWire(ID, new Wire(0, 0, indexA)); AddWire(ID, new Wire(1, 0, indexB)); // 0 AddWire(notA, new Wire(0, 0, index0)); AddWire(notB, new Wire(0, 1, index0)); AddWire(gate0, new Wire(0, 0, -1, true, true)); // 1 AddWire(ID, new Wire(0, 0, index1)); AddWire(notB, new Wire(0, 1, index1)); AddWire(gate1, new Wire(0, 1, -1, true, true)); // 2 AddWire(notA, new Wire(0, 0, index2)); AddWire(ID, new Wire(1, 1, index2)); AddWire(gate2, new Wire(0, 2, -1, true, true)); // 3 AddWire(ID, new Wire(0, 0, index3)); AddWire(ID, new Wire(1, 1, index3)); AddWire(gate3, new Wire(0, 3, -1, true, true)); // Enable AddWire(ID, new Wire(2, 2, index0, false, true)); AddWire(ID, new Wire(2, 2, index1, false, true)); AddWire(ID, new Wire(2, 2, index2, false, true)); AddWire(ID, new Wire(2, 2, index3, false, true)); // 2 to 4 Decoder ---------------------------------- NotGate notC = new NotGate(); int indexC = AddGate(notC); NotGate notD = new NotGate(); int indexD = AddGate(notD); ANDGate gate4 = new ANDGate(3); int index4 = AddGate(gate4); ANDGate gate5 = new ANDGate(3); int index5 = AddGate(gate5); ANDGate gate6 = new ANDGate(3); int index6 = AddGate(gate6); ANDGate gate7 = new ANDGate(3); int index7 = AddGate(gate7); AddWire(ID, new Wire(3, 0, indexC)); AddWire(ID, new Wire(4, 0, indexD)); // 0 AddWire(notC, new Wire(0, 0, index4)); AddWire(notD, new Wire(0, 1, index4)); AddWire(gate4, new Wire(0, 4, -1, true, true)); // 1 AddWire(ID, new Wire(3, 0, index5)); AddWire(notD, new Wire(0, 1, index5)); AddWire(gate5, new Wire(0, 5, -1, true, true)); // 2 AddWire(notC, new Wire(0, 0, index6)); AddWire(ID, new Wire(4, 1, index6)); AddWire(gate6, new Wire(0, 6, -1, true, true)); // 3 AddWire(ID, new Wire(3, 0, index7)); AddWire(ID, new Wire(4, 1, index7)); AddWire(gate7, new Wire(0, 7, -1, true, true)); // Enable AddWire(ID, new Wire(5, 2, index4, false, true)); AddWire(ID, new Wire(5, 2, index5, false, true)); AddWire(ID, new Wire(5, 2, index6, false, true)); AddWire(ID, new Wire(5, 2, index7, false, true)); }