Exemplo n.º 1
0
        public HalfAdder(TTLGateTypeEnum gateType)
        {
            var xorGate = new XorGate(gateType, 2);
            var andGate = new AndGate(gateType, 2);

            Gates.Add(xorGate);
            Gates.Add(andGate);

            Connections.Add(new Connection
            {
                Source      = A,
                Termination = xorGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = B,
                Termination = xorGate.Inputs[1]
            });

            Connections.Add(new Connection
            {
                Source      = A,
                Termination = andGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = B,
                Termination = andGate.Inputs[1]
            });
        }
Exemplo n.º 2
0
        public void Test_XorGateSimulate()
        {
            LogicComponent xor_gate = new XorGate();

            TestUtil.Test_TruthTable(xor_gate, new bool[2, 2] {
                { false, true }, { true, false }
            });
        }
Exemplo n.º 3
0
        public void XorGate()
        {
            var xg = new XorGate(t, f, t);

            Assert.IsFalse(xg[0]);

            xg.Inputs = new IInputsOutput[] { t, f, t, t };
            Assert.IsTrue(xg[0]);
        }
Exemplo n.º 4
0
        public XorGate Build()
        {
            var gate = new XorGate();

            foreach (var input in _inputs)
            {
                gate.AddInput(input);
            }

            return(gate);
        }
Exemplo n.º 5
0
        public void Result_UnevenInputsTrue_ShouldReturnTrue()
        {
            // Arrange
            XorGate Gate = new XorGate();

            Gate.In = new INode[] { HighStartPoint, LowStartPoint };

            // Act
            bool output = Gate.Result();

            // Assert
            Assert.IsTrue(output);
        }
Exemplo n.º 6
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        XorGate xgate = collision.gameObject.GetComponent <XorGate>();

        if (xgate != null)
        {
            xgate.nodes.Remove(gate);
        }
        //CircuitNode[] newNodes = new CircuitNode[nodes.Length - 1];
        //nodes.CopyTo(newNodes, 0);
        //newNodes[newNodes.Length - 1] = collision.gameObject.GetComponent<CircuitNode>();
        //nodes = newNodes;
        // nodes.nodes.Remove(collision.gameObject.GetComponent<CircuitNode>());
    }
Exemplo n.º 7
0
        public void perfect_gate_logic_test(double input1, double input2, double expectedOutput)
        {
            var xorGate = new XorGate(TTLGateTypeEnum.Perfect, 2);

            xorGate.Inputs[0].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input1, Unknown = false
            });
            xorGate.Inputs[1].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input2, Unknown = false
            });

            var result = xorGate.Output(0);

            Assert.Equal(expectedOutput, result);
        }
Exemplo n.º 8
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     // CircuitNode[] newNodes = new CircuitNode[nodes.nodes.Length + 1];
     // nodes.CopyTo(newNodes, 0);
     // newNodes[newNodes.Length - 1] = collision.gameObject.GetComponent<CircuitNode>();
     // nodes.nodes.Add(collision.gameObject.GetComponent<CircuitNode>());
     //nodes = newNodes;
     if (collision.gameObject.transform.parent.gameObject.GetComponent <BuildControl>().ready)
     {
         XorGate xgate = collision.gameObject.GetComponent <XorGate>();
         if (xgate != null)
         {
             xgate.nodes.Add(gate);
         }
     }
 }
Exemplo n.º 9
0
        public void Test_InputOutputSanityCheck()
        {
            LogicComponent xor_gate = new XorGate();

            // Assert input constraints are checked
            Assert.That(() => xor_gate.Simulate(new [] { true }), Throws.ArgumentException);
            Assert.That(() => xor_gate.Simulate(new [] { true, false }), Throws.Nothing);
            Assert.That(() => xor_gate.Simulate(new [] { true, false, true }),
                        Throws.ArgumentException);

            // Assert output constraints are checked
            Assert.That(() => xor_gate.Outputs = new List <bool> {
            }, Throws.ArgumentException);
            Assert.That(() => xor_gate.Outputs = new List <bool> {
                true
            }, Throws.Nothing);
            Assert.That(() => xor_gate.Outputs = new List <bool> {
                true, false
            },
                        Throws.ArgumentException);
        }
Exemplo n.º 10
0
    private LightComponent duplicateAt(Type type, Vector2Int position, int rotation, bool flipped)
    {
        //makes a duplicate of the component passed in

        LightComponent result = null;

        if (type == typeof(AndGate))
        {
            result = new AndGate(position, rotation, flipped);
        }
        else if (type == typeof(OrGate))
        {
            result = new OrGate(position, rotation, flipped);
        }
        else if (type == typeof(NotGate))
        {
            result = new NotGate(position, rotation, flipped);
        }
        else if (type == typeof(BufferGate))
        {
            result = new BufferGate(position, rotation, flipped);
        }
        else if (type == typeof(NandGate))
        {
            result = new NandGate(position, rotation, flipped);
        }
        else if (type == typeof(XorGate))
        {
            result = new XorGate(position, rotation, flipped);
        }
        else if (type == typeof(XnorGate))
        {
            result = new XnorGate(position, rotation, flipped);
        }
        else if (type == typeof(NorGate))
        {
            result = new NorGate(position, rotation, flipped);
        }
        else if (type == typeof(Splitter))
        {
            result = new Splitter(position, rotation, flipped);
        }
        else if (type == typeof(Reflector))
        {
            result = new Reflector(position, rotation, flipped);
        }
        else if (type == typeof(GraphOutput))
        {
            result = new GraphOutput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
        }
        else if (type == typeof(GraphInput))
        {
            result = new GraphInput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
        }
        else
        {
            throw new System.Exception(type + " was not found when selecting the from the logic graph editor");
        }

        return(result);
    }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            NandGate nand = new NandGate();
            AndGate  and  = new AndGate();
            OrGate   or   = new OrGate();
            XorGate  xor  = new XorGate();

            Gate[] gates = { nand, and, or, xor };
            foreach (Gate gate in gates)
            {
                Console.WriteLine(gate.ToTable());
            }

            NandGate      nand3 = new NandGate();
            NandGate      nand5 = new NandGate();
            AndGate       and1  = new AndGate();
            AndGate       and9  = new AndGate();
            AndGate       and7  = new AndGate();
            OrGate        or2   = new OrGate();
            OrGate        or6   = new OrGate();
            OrGate        or10  = new OrGate();
            XorGate       xor4  = new XorGate();
            XorGate       xor8  = new XorGate();
            StringBuilder sb    = new StringBuilder();

            bool[] opts = { true, false };
            sb.AppendLine("A  B  C  D  O");
            foreach (bool A in opts)
            {
                foreach (bool B in opts)
                {
                    foreach (bool C in opts)
                    {
                        foreach (bool D in opts)
                        {
                            and1.Set(A, A);
                            and1.Latch();

                            or2.Set(A, B);
                            or2.Latch();

                            nand3.Set(B, C);
                            nand3.Latch();

                            xor4.Set(C, nand3.getOutput());
                            xor4.Latch();

                            nand5.Set(and1.getOutput(), or2.getOutput());
                            nand5.Latch();

                            or6.Set(and1.getOutput(), nand5.getOutput());
                            or6.Latch();

                            and7.Set(or2.getOutput(), xor4.getOutput());
                            and7.Latch();

                            xor8.Set(D, xor4.getOutput());
                            xor8.Latch();

                            and9.Set(or6.getOutput(), and7.getOutput());
                            and9.Latch();

                            or10.Set(and9.getOutput(), xor8.getOutput());
                            or10.Latch();

                            sb.AppendLine(Convert.ToInt16(A) + "  " + Convert.ToInt16(B) + "  " + Convert.ToInt16(C) + "  " + Convert.ToInt16(D) + "  " + Convert.ToInt16(or10.getOutput()));
                        }
                    }
                }
            }
            Console.WriteLine(sb.ToString());
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            WireSet ws  = new WireSet(9);
            WireSet ws2 = new WireSet(9);
            WireSet ws3 = new WireSet(9);
            OrGate  or  = new OrGate();

            XorGate xor = new XorGate();

            MultiBitAndGate mbag3 = new MultiBitAndGate(3);
            MultiBitAndGate mbag4 = new MultiBitAndGate(4);
            MultiBitAndGate mbag5 = new MultiBitAndGate(5);
            MultiBitAndGate mbag6 = new MultiBitAndGate(6);
            MultiBitAndGate mbag7 = new MultiBitAndGate(7);
            MultiBitAndGate mbag8 = new MultiBitAndGate(8);

            MultiBitOrGate mbog3 = new MultiBitOrGate(3);
            MultiBitOrGate mbog4 = new MultiBitOrGate(4);
            MultiBitOrGate mbog5 = new MultiBitOrGate(5);
            MultiBitOrGate mbog6 = new MultiBitOrGate(6);
            MultiBitOrGate mbog7 = new MultiBitOrGate(7);
            MultiBitOrGate mbog8 = new MultiBitOrGate(8);

            MuxGate mg  = new MuxGate();
            Demux   dmg = new Demux();

            BitwiseOrGate bwog0 = new BitwiseOrGate(0);
            BitwiseOrGate bwog1 = new BitwiseOrGate(1);
            BitwiseOrGate bwog2 = new BitwiseOrGate(2);
            BitwiseOrGate bwog3 = new BitwiseOrGate(3);
            BitwiseOrGate bwog4 = new BitwiseOrGate(4);
            BitwiseOrGate bwog5 = new BitwiseOrGate(5);
            BitwiseOrGate bwog6 = new BitwiseOrGate(6);
            BitwiseOrGate bwog7 = new BitwiseOrGate(7);

            BitwiseAndGate bwag2 = new BitwiseAndGate(2);
            BitwiseAndGate bwag3 = new BitwiseAndGate(3);
            BitwiseAndGate bwag4 = new BitwiseAndGate(4);

            BitwiseNotGate bwng2 = new BitwiseNotGate(2);
            BitwiseNotGate bwng3 = new BitwiseNotGate(3);
            BitwiseNotGate bwng4 = new BitwiseNotGate(4);

            BitwiseDemux bwdm2 = new BitwiseDemux(2);
            BitwiseDemux bwdm3 = new BitwiseDemux(3);
            BitwiseDemux bwdm4 = new BitwiseDemux(4);

            BitwiseMux bwmx2 = new BitwiseMux(2);
            BitwiseMux bwmx3 = new BitwiseMux(3);
            BitwiseMux bwmx4 = new BitwiseMux(4);

            BitwiseMultiwayMux   bwmwm  = new BitwiseMultiwayMux(3, 3);
            BitwiseMultiwayDemux bwmwdm = new BitwiseMultiwayDemux(3, 3);

            HalfAdder     ha  = new HalfAdder();
            FullAdder     fa  = new FullAdder();
            MultiBitAdder mba = new MultiBitAdder(4);
            ALU           alu = new ALU(4);

            System.Console.WriteLine(or.TestGate().ToString());

            System.Console.WriteLine(xor.TestGate().ToString());

            System.Console.WriteLine(mbag3.TestGate().ToString());
            System.Console.WriteLine(mbag4.TestGate().ToString());
            System.Console.WriteLine(mbag5.TestGate().ToString());
            System.Console.WriteLine(mbag6.TestGate().ToString());
            System.Console.WriteLine(mbag7.TestGate().ToString());
            System.Console.WriteLine(mbag8.TestGate().ToString());

            System.Console.WriteLine(mbog3.TestGate().ToString());
            System.Console.WriteLine(mbog4.TestGate().ToString());
            System.Console.WriteLine(mbog5.TestGate().ToString());
            System.Console.WriteLine(mbog6.TestGate().ToString());
            System.Console.WriteLine(mbog7.TestGate().ToString());
            System.Console.WriteLine(mbog8.TestGate().ToString());

            System.Console.WriteLine(mg.TestGate().ToString());
            System.Console.WriteLine(dmg.TestGate().ToString());

            System.Console.WriteLine(bwag2.TestGate().ToString());
            System.Console.WriteLine(bwag3.TestGate().ToString());
            System.Console.WriteLine(bwag4.TestGate().ToString());

            System.Console.WriteLine(bwog0.TestGate().ToString());
            System.Console.WriteLine(bwog1.TestGate().ToString());
            System.Console.WriteLine(bwog2.TestGate().ToString());
            System.Console.WriteLine(bwog3.TestGate().ToString());
            System.Console.WriteLine(bwog4.TestGate().ToString());
            System.Console.WriteLine(bwog5.TestGate().ToString());
            System.Console.WriteLine(bwog6.TestGate().ToString());
            System.Console.WriteLine(bwog7.TestGate().ToString());

            ws.Set2sComplement(-5);
            System.Console.WriteLine(ws.Get2sComplement().ToString());
            int test  = 0;
            int test2 = 0;

            for (int i = 1; i < 50; i++)
            {
                ws2.SetValue(i);
                if (ws2.GetValue() != i)
                {
                    test = 10;
                }
            }
            for (int i = -34; i < 50; i++)
            {
                ws3.Set2sComplement(i);
                if (ws3.Get2sComplement() != i)
                {
                    test2 = 10;
                }
            }
            System.Console.WriteLine(test);
            System.Console.WriteLine(test2);

            System.Console.WriteLine(bwng2.TestGate().ToString());
            System.Console.WriteLine(bwng3.TestGate().ToString());
            System.Console.WriteLine(bwng4.TestGate().ToString());

            System.Console.WriteLine(bwdm2.TestGate().ToString());
            System.Console.WriteLine(bwdm3.TestGate().ToString());
            System.Console.WriteLine(bwdm4.TestGate().ToString());

            System.Console.WriteLine(bwmx2.TestGate().ToString());
            System.Console.WriteLine(bwmx3.TestGate().ToString());
            System.Console.WriteLine(bwmx4.TestGate().ToString());

            System.Console.WriteLine(bwmwm.TestGate().ToString());

            System.Console.WriteLine(bwmwdm.TestGate().ToString());

            System.Console.WriteLine(ha.TestGate().ToString());
            System.Console.WriteLine(fa.TestGate().ToString());
            System.Console.WriteLine(mba.TestGate().ToString());

            System.Console.WriteLine(alu.TestGate().ToString());
        }
Exemplo n.º 13
0
 private void CreateInternals()
 {
     this.xorGate = new XorGate(this.PinA, this.PinB);
     this.andGate = new AndGate(this.PinA, this.PinB);
 }
Exemplo n.º 14
0
 // Use this for initialisation
 protected override void Awake()
 {
     base.Awake();
     LogicComponent = new XorGate();
     Canvas.Circuit.AddComponent(LogicComponent);
 }
Exemplo n.º 15
0
        static void HalfAdderTest()
        {
            var signalGenerator1 = new SignalGenerator();
            var signalGenerator2 = new SignalGenerator();

            bool signalHigh     = true;
            bool longSignalHigh = true;

            for (int i = 0; i < 200; i++)
            {
                if (i % 20 == 0)
                {
                    signalHigh = !signalHigh;
                }

                if (i % 40 == 0)
                {
                    longSignalHigh = !longSignalHigh;
                }

                signalGenerator1.AddSample(signalHigh ? 5 : 0);
                signalGenerator2.AddSample(longSignalHigh ? 5 : 0);
            }

            var xorGate = new XorGate(TTLGateTypeEnum.Normal, 2);
            var andGate = new AndGate(TTLGateTypeEnum.Normal, 2);

            var circuit = new Circuit();

            circuit.Gates.Add(xorGate);
            circuit.Gates.Add(andGate);
            circuit.Gates.Add(signalGenerator1);
            circuit.Gates.Add(signalGenerator2);

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = xorGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = xorGate.Inputs[1]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = andGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = andGate.Inputs[1]
            });

            circuit.RunCircuit();

            for (int i = 0; i < 200; i++)
            {
                _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)}  S:{xorGate.Output(i)}  C:{andGate.Output(i)}");
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            NandGate nand = new NandGate();
              AndGate and = new AndGate();
              OrGate or = new OrGate();
              XorGate xor = new XorGate();
              Gate[] gates = { nand, and, or, xor };
              foreach (Gate gate in gates)
              {
            Console.WriteLine(gate.ToTable());
              }

              NandGate nand3 = new NandGate();
              NandGate nand5 = new NandGate();
              AndGate and1 = new AndGate();
              AndGate and9 = new AndGate();
              AndGate and7 = new AndGate();
              OrGate or2 = new OrGate();
              OrGate or6 = new OrGate();
              OrGate or10 = new OrGate();
              XorGate xor4 = new XorGate();
              XorGate xor8 = new XorGate();
              StringBuilder sb = new StringBuilder();
              bool[] opts = { true, false };
              sb.AppendLine("A  B  C  D  O");
              foreach (bool A in opts)
              {
            foreach (bool B in opts)
            {
              foreach (bool C in opts)
              {
            foreach (bool D in opts)
            {
              and1.Set(A, A);
              and1.Latch();

              or2.Set(A, B);
              or2.Latch();

              nand3.Set(B, C);
              nand3.Latch();

              xor4.Set(C, nand3.getOutput());
              xor4.Latch();

              nand5.Set(and1.getOutput(), or2.getOutput());
              nand5.Latch();

              or6.Set(and1.getOutput(), nand5.getOutput());
              or6.Latch();

              and7.Set(or2.getOutput(), xor4.getOutput());
              and7.Latch();

              xor8.Set(D, xor4.getOutput());
              xor8.Latch();

              and9.Set(or6.getOutput(), and7.getOutput());
              and9.Latch();

              or10.Set(and9.getOutput(), xor8.getOutput());
              or10.Latch();

              sb.AppendLine(Convert.ToInt16(A) + "  " + Convert.ToInt16(B) + "  " + Convert.ToInt16(C) + "  " + Convert.ToInt16(D) + "  " + Convert.ToInt16(or10.getOutput()));
            }
              }
            }
              }
              Console.WriteLine(sb.ToString());
        }