Пример #1
0
 private void CreateInternals()
 {
     this.half1  = new HalfAdder(this.PinA, this.PinB);
     this.bridge = new OrGate(this.PinC, this.PinC);
     this.half2  = new HalfAdder();
     this.orGate = new OrGate();
 }
Пример #2
0
    public override void RefreshTile(Vector3Int location, ITilemap tilemap)
    {
        if (tilemap.GetTile(location))
        {
            OrGate gate = new OrGate(location, tilemap);
            Circuit.AddComponent(location, gate);
            gate.previousTile = replacedTile;
        }
        else
        {
            Circuit.RemoveComponent(location);
        }
        tilemap.RefreshTile(location);

        if (Circuit.circuitComponents.ContainsKey(location))
        {
            CircuitComponent component = Circuit.circuitComponents[location];
            foreach (CircuitComponent inComponent in component.ins)
            {
                tilemap.RefreshTile(inComponent.location);
            }
            foreach (CircuitComponent outComponent in component.outs)
            {
                tilemap.RefreshTile(outComponent.location);
            }
        }
    }
Пример #3
0
        private void CreateInternals()
        {
            this.backAnd = new AndGate(this.PinA, this.PinB);
            this.backOr = new OrGate(this.PinA, this.PinB);
            this.frontAnd = new AndGate();
            this.notGate = new NotGate();

        }
Пример #4
0
        public void Test_OrGateSimulate()
        {
            LogicComponent or_gate = new OrGate();

            TestUtil.Test_TruthTable(or_gate, new bool[2, 2] {
                { false, true }, { true, true }
            });
        }
Пример #5
0
        private void Build()
        {
            foreach (var line in input.Split("\r\n"))
            {
                //Console.WriteLine(line);
                var parts   = line.Split("->");
                var operand = parts[0].Trim();
                var result  = parts[1].Trim();

                Wire currentWire = GetWireByName(result);

                var operandparts = operand.Split(' ');

                IValueProvider value = null;

                if (operand.Contains("AND"))
                {
                    var obj = new AndGate();
                    obj.Input1 = GetIValueProvider(operandparts[0].Trim());
                    obj.Input2 = GetIValueProvider(operandparts[2].Trim());
                    value      = obj;
                }
                else if (operand.Contains("OR"))
                {
                    var obj = new OrGate();
                    obj.Input1 = GetIValueProvider(operandparts[0].Trim());
                    obj.Input2 = GetIValueProvider(operandparts[2].Trim());
                    value      = obj;
                }
                else if (operand.Contains("RSHIFT"))
                {
                    var obj = new RShiftGate();
                    obj.Input1      = GetIValueProvider(operandparts[0].Trim());
                    obj.ShiftAmount = ushort.Parse(operandparts[2].Trim());
                    value           = obj;
                }
                else if (operand.Contains("LSHIFT"))
                {
                    var obj = new LShiftGate();
                    obj.Input1      = GetIValueProvider(operandparts[0].Trim());
                    obj.ShiftAmount = ushort.Parse(operandparts[2].Trim());
                    value           = obj;
                }
                else if (operand.Contains("NOT"))
                {
                    var obj = new NotGate();
                    obj.Input1 = GetIValueProvider(operandparts[1].Trim());
                    value      = obj;
                }
                else if (operandparts.Length == 1)
                {
                    var obj = GetIValueProvider(operandparts[0].Trim());
                    value = obj;
                }
                gates.Add(value);
                currentWire.Input = value;
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            var test    = new NeuralNet(2, 1, 3, 5);
            var andGate = new AndGate();
            var notGate = new NotGate();
            var orGate  = new OrGate();

            test.TrainWithData(orGate, 10000);
        }
Пример #7
0
        public OrGate Build()
        {
            var gate = new OrGate();

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

            return(gate);
        }
Пример #8
0
        private void ConnectJumpWire_JGT()
        {
            m_gJLE_Or = new OrGate();
            m_gJLE_Or.Input1.ConnectInput(m_gALU.Zero);
            m_gJLE_Or.Input2.ConnectInput(m_gALU.Negative);

            m_gJGT_Not = new NotGate();
            m_gJGT_Not.ConnectInput(m_gJLE_Or.Output);

            m_wJump[JGT].ConnectInput(m_gJGT_Not.Output);
        }
Пример #9
0
        private void ConnectARegisterLoad()
        {
            m_gALoadInstructionNot = new NotGate();
            m_gALoadInstructionNot.Input.ConnectInput(Instruction[Type]);

            m_gALoadOr = new OrGate();
            m_gALoadOr.Input1.ConnectInput(m_gALoadInstructionNot.Output);
            m_gALoadOr.Input2.ConnectInput(Instruction[D1]);

            m_rA.Load.ConnectInput(m_gALoadOr.Output);
        }
Пример #10
0
        public void Write_LowLow_Low()
        {
            var uut    = new OrGate();
            var input1 = uut.AddInput().CreateConnection();
            var input2 = uut.AddInput().CreateConnection();
            var output = uut.Output.CreateConnection();

            input1.Write(DigitalLevel.Low);
            input2.Write(DigitalLevel.Low);

            uut.Output.Level.Should().Be(DigitalLevel.Low);
        }
Пример #11
0
        public void OrGate()
        {
            var or = new OrGate(t, t, t, t, f);

            Assert.IsTrue(or[0]);

            or.Inputs = new[] { f, f, f, f, f };
            Assert.IsFalse(or[0]);

            or.Inputs = new IInputsOutput[] { f, f, f, f, f, f, f, f, f, f, t };
            Assert.IsTrue(or[0]);
        }
Пример #12
0
        public void Write_HighPosEdge_High()
        {
            var uut    = new OrGate();
            var input1 = uut.AddInput().CreateConnection();
            var input2 = uut.AddInput().CreateConnection();
            var output = uut.Output.CreateConnection();

            input1.Write(DigitalLevel.High);
            input2.Write(DigitalLevel.PosEdge);

            uut.Output.Level.Should().Be(DigitalLevel.High);
        }
Пример #13
0
        public void Result_AtLeastOneInputTrue_ShouldReturnTrue()
        {
            // Arrange
            OrGate Gate = new OrGate();

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

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

            // Assert
            Assert.IsTrue(output);
        }
Пример #14
0
        public void Result_AllInputsFalse_ShouldReturnFalse()
        {
            // Arrange
            OrGate Gate = new OrGate();

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

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

            // Assert
            Assert.IsFalse(output);
        }
Пример #15
0
        public void OrGateTest00()
        {
            var g = new OrGate();

            Assert.IsNotNull(g);

            Assert.IsNotNull(g.Inputs);
            Assert.IsNotNull(g.Outputs);
            Assert.IsNotNull(g.Pins);

            Assert.IsTrue(g.Inputs.Count == 0);
            Assert.IsTrue(g.Outputs.Count == 0);
            Assert.IsTrue(g.Pins.Count == 0);
        }
Пример #16
0
        public void perfect_gate_logic_test(double input1, double input2, double expectedOutput)
        {
            var orGate = new OrGate(TTLGateTypeEnum.Perfect, 2);

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

            var result = orGate.Output(0);

            Assert.Equal(expectedOutput, result);
        }
Пример #17
0
        public void Write_HighHighLowHigh_High()
        {
            var uut    = new OrGate();
            var input1 = uut.AddInput().CreateConnection();
            var input2 = uut.AddInput().CreateConnection();
            var input3 = uut.AddInput().CreateConnection();
            var input4 = uut.AddInput().CreateConnection();
            var output = uut.Output.CreateConnection();

            input1.Write(DigitalLevel.High);
            input2.Write(DigitalLevel.High);
            input3.Write(DigitalLevel.Low);
            input4.Write(DigitalLevel.High);

            uut.Output.Level.Should().Be(DigitalLevel.High);
        }
Пример #18
0
        public void CustomXor()
        {
            // a XOR b = (a AND ¬b) OR (¬a AND b)
            Wire a = new Wire(f), b = new Wire(f);
            var  xor = new OrGate(new AndGate(a, new Inverter(b)), new AndGate(new Inverter(a), b));

            Assert.AreEqual(false ^ false, xor[0]);

            a.Inputs[0] = f; b.Inputs[0] = t;
            Assert.AreEqual(false ^ true, xor[0]);

            a.Inputs[0] = t; b.Inputs[0] = f;
            Assert.AreEqual(true ^ false, xor[0]);

            a.Inputs[0] = t; b.Inputs[0] = t;
            Assert.AreEqual(true ^ true, xor[0]);
        }
Пример #19
0
        //  can be removed; just trying out stuff
        public void BasicComposite_NoBuilders()
        {
            var notGate = new NotGate();

            notGate.SetInput(Generator.AnInactiveSignal());

            var orGate = new OrGate();

            orGate.AddInput(Generator.AnInactiveSignal());
            orGate.AddInput(Generator.AnActiveSignal());

            var andGate = new AndGate();

            andGate.AddInput(notGate);
            andGate.AddInput(orGate);

            Assert.True(andGate.Output());
        }
Пример #20
0
        public void BusDecoderInvertorOr_DecodeOr_OutputActiveWhenEnabled()
        {
            const byte Value = 0x10;

            var decoder = new BusDecoder("decoder");

            decoder.AddValue(Value);
            decoder.Input.ConnectTo(new Bus <BusData8>("bus"));
            var busInput = decoder.Input.CreateConnection();

            busInput.IsEnabled = true;

            var invertor = new InvertorGate()
            {
                Name = "inv"
            };

            invertor.Input.ConnectTo(decoder.Output);

            var or = new OrGate()
            {
                Name = "or"
            };

            or.AddInput().ConnectTo(invertor.Output);
            var enable = or.AddInput().CreateConnection();

            enable.Write(DigitalLevel.High);

            var output = or.Output.CreateConnection();

            busInput.Write(new BusData8(Value));
            decoder.Output.Level.Should().Be(DigitalLevel.High);
            invertor.Output.Level.Should().Be(DigitalLevel.Low);
            output.DigitalSignal.Level.Should().Be(DigitalLevel.High);

            enable.Write(DigitalLevel.Low);
            output.DigitalSignal.Level.Should().Be(DigitalLevel.Low);
        }
Пример #21
0
        public InputPort AddInputPort(Bus address, Bus data, ushort ioAddress, string name = null)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            var decoder = new BusDecoder(address, name + "-InputAddressDecoder");

            decoder.AddValue(ioAddress);
            AddComponent(decoder);

            var invertor = new InvertorGate()
            {
                Name = name + "-InAddressDecodeInvertor"
            };

            AddComponent(invertor);
            decoder.Output.ConnectTo(invertor.Input);

            var or = new OrGate()
            {
                Name = name + "-InPortEnableIO"
            };

            or.AddInput().ConnectTo(Model.Cpu.IoRequest);
            or.AddInput().ConnectTo(Model.Cpu.Read);
            or.AddInput().ConnectTo(invertor.Output);
            AddComponent(or);

            var inputPort = new InputPort(data, name);

            AddInputPort(inputPort);
            inputPort.PortEnable.ConnectTo(or.Output);

            return(inputPort);
        }
Пример #22
0
        public void OrGateConstructor()
        {
            OrGate gate = new OrGate();

            Assert.IsNotNull(gate.A);
            Assert.IsNotNull(gate.B);
            Assert.AreEqual(gate.A.Collector, gate.B.Collector);

            gate.SetInput(0, false);
            gate.SetInput(1, false);
            Assert.AreEqual(gate.GetOutput(), false);

            gate.SetInput(0, true);
            gate.SetInput(1, false);
            Assert.AreEqual(gate.GetOutput(), true);

            gate.SetInput(0, false);
            gate.SetInput(1, true);
            Assert.AreEqual(gate.GetOutput(), true);

            gate.SetInput(0, true);
            gate.SetInput(1, true);
            Assert.AreEqual(gate.GetOutput(), true);
        }
Пример #23
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);
    }
Пример #24
0
        //private Wire wi1, wi2;

        //here we initialize and connect all the components, as in Figure 5.9 in the book
        public CPU16()
        {
            wi1      = new Wire();
            wi2      = new Wire();
            and_D    = new AndGate();
            and_MW   = new AndGate();
            and_JM0  = new AndGate();
            and_JM1  = new AndGate();
            and_JM2  = new AndGate();
            and_JMP  = new AndGate();
            not_Zero = new NotGate();
            not_Neg  = new NotGate();
            not_A    = new NotGate();
            J_0      = new Wire();
            JGT      = new Wire();
            JEQ      = new Wire();
            JGE      = new Wire();
            JLT      = new Wire();
            JNE      = new Wire();
            JLE      = new Wire();
            J_1      = new Wire();
            JMP      = new WireSet(3);
            or_A     = new OrGate();
            or_JMP   = new OrGate();

            Size = 16;

            Instruction        = new WireSet(Size);
            MemoryInput        = new WireSet(Size);
            MemoryOutput       = new WireSet(Size);
            MemoryAddress      = new WireSet(Size);
            InstructionAddress = new WireSet(Size);
            MemoryWrite        = new Wire();
            Reset = new Wire();

            m_gALU = new ALU(Size);
            m_rPC  = new Counter(Size);
            m_rA   = new MultiBitRegister(Size);
            m_rD   = new MultiBitRegister(Size);

            m_gAMux  = new BitwiseMux(Size);
            m_gMAMux = new BitwiseMux(Size);

            m_gAMux.ConnectInput1(Instruction);
            m_gAMux.ConnectInput2(m_gALU.Output);

            m_rA.ConnectInput(m_gAMux.Output);

            m_gMAMux.ConnectInput1(m_rA.Output);
            m_gMAMux.ConnectInput2(MemoryInput);
            m_gALU.InputY.ConnectInput(m_gMAMux.Output);

            m_gALU.InputX.ConnectInput(m_rD.Output);

            m_rD.ConnectInput(m_gALU.Output);

            MemoryOutput.ConnectInput(m_gALU.Output);
            MemoryAddress.ConnectInput(m_rA.Output);

            InstructionAddress.ConnectInput(m_rPC.Output);
            m_rPC.ConnectInput(m_rA.Output);
            m_rPC.ConnectReset(Reset);

            //now, we call the code that creates the control unit
            ConnectControls();
        }
Пример #25
0
        public static void main(string[] args)
        {
            OrGate or = new OrGate();

            or.TestGate();
        }
Пример #26
0
 // Use this for initialisation
 protected override void Awake()
 {
     base.Awake();
     LogicComponent = new OrGate();
     Canvas.Circuit.AddComponent(LogicComponent);
 }
Пример #27
0
        public void GalieloStringTest1()
        {
            // Arrange
            TopLevelEvent topLevelEvent = new TopLevelEvent
            {
                Title = "top_level_event"
            };
            AndGate andGate1 = new AndGate
            {
                Title = "and_gate_1"
            };
            Event event1 = new Event
            {
                Title = "event_1"
            };
            Event event2 = new Event
            {
                Title = "event_2"
            };
            OrGate orGate1 = new OrGate
            {
                Title = "or_gate_1"
            };
            OrGate orGate2 = new OrGate
            {
                Title = "or_gate_2"
            };
            BasicEvent basicEvent1 = new BasicEvent
            {
                Title  = "basic_event_1",
                Lambda = 0.2
            };
            BasicEvent basicEvent2 = new BasicEvent
            {
                Title  = "basic_event_2",
                Lambda = 0.1
            };
            BasicEvent basicEvent3 = new BasicEvent
            {
                Title  = "basic_event_3",
                Lambda = 0.3
            };
            BasicEvent basicEvent4 = new BasicEvent
            {
                Title  = "basic_event_4",
                Lambda = 0.1
            };

            Connection connection1 = new Connection
            {
                From = topLevelEvent,
                To   = andGate1
            };
            Connection connection2 = new Connection
            {
                From = andGate1,
                To   = event1
            };
            Connection connection3 = new Connection
            {
                From = andGate1,
                To   = event2
            };
            Connection connection4 = new Connection
            {
                From = event1,
                To   = orGate1
            };
            Connection connection5 = new Connection
            {
                From = orGate1,
                To   = basicEvent1
            };
            Connection connection6 = new Connection
            {
                From = orGate1,
                To   = basicEvent2
            };
            Connection connection7 = new Connection
            {
                From = event2,
                To   = orGate2
            };
            Connection connection8 = new Connection
            {
                From = orGate2,
                To   = basicEvent3
            };
            Connection connection9 = new Connection
            {
                From = orGate2,
                To   = basicEvent4
            };

            Project project = new Project
            {
                Title     = "TestProject",
                FaultTree = new FaultTree
                {
                    Elements = new ObservableCollection <Element>
                    {
                        topLevelEvent,
                        andGate1,
                        event1,
                        event2,
                        orGate1,
                        basicEvent1,
                        basicEvent2,
                        orGate2,
                        basicEvent3,
                        basicEvent4
                    },
                    Connections = new ObservableCollection <Connection>
                    {
                        connection1,
                        connection2,
                        connection3,
                        connection4,
                        connection5,
                        connection6,
                        connection7,
                        connection8,
                        connection9
                    }
                }
            };

            string expected = "toplevel top_level_event;" +
                              "top_level_event and event_1 event_2;" +
                              "basic_event_1 lambda = 0.2 dorm = 0;" +
                              "basic_event_2 lambda = 0.1 dorm = 0;" +
                              "basic_event_3 lambda = 0.3 dorm = 0;" +
                              "basic_event_4 lambda = 0.1 dorm = 0;" +
                              "event_1 or basic_event_1 basic_event_2;" +
                              "event_2 or basic_event_3 basic_event_4;";

            // Act
            string actual = project.FaultTree.GetGalileoString();

            // Assert
            Assert.AreEqual(expected, actual, "Galileo string is ot correct.");
        }
Пример #28
0
        public void Test_CircuitSimulate_SmallTree()
        {
            LogicComponent true_constant1 = new TrueConst();
            LogicComponent true_constant2 = new TrueConst();
            LogicComponent false_constant = new FalseConst();
            LogicComponent and_gate       = new AndGate();
            LogicComponent or_gate        = new OrGate();

            LogicComponent true_constant1_connection = new Connection();
            LogicComponent true_constant2_connection = new Connection();
            LogicComponent false_constant_connection = new Connection();
            LogicComponent and_gate_connection       = new Connection();

            Circuit circuit = new Circuit();

            /* Test will be 2 TRUEs connected to an AND gate.
             * This AND gate and a FALSE will then be connected to the OR gate.
             */
            circuit.AddComponent(true_constant1);
            circuit.AddComponent(true_constant2);
            circuit.AddComponent(false_constant);
            circuit.AddComponent(and_gate);
            circuit.AddComponent(or_gate);
            circuit.AddComponent(true_constant1_connection);
            circuit.AddComponent(true_constant2_connection);
            circuit.AddComponent(false_constant_connection);
            circuit.AddComponent(and_gate_connection);

            circuit.Connect(true_constant1, 0, true_constant1_connection, 0);
            circuit.Connect(true_constant2, 0, true_constant2_connection, 0);
            circuit.Connect(true_constant1_connection, 0, and_gate, 0);
            circuit.Connect(true_constant2_connection, 0, and_gate, 1);
            circuit.Connect(and_gate, 0, and_gate_connection, 0);
            circuit.Connect(false_constant, 0, false_constant_connection, 0);
            circuit.Connect(and_gate_connection, 0, or_gate, 0);
            circuit.Connect(false_constant_connection, 0, or_gate, 1);

            // Try first step: the output of the connections from the constants should change.
            circuit.Simulate();
            Assert.AreEqual(true_constant1_connection.Outputs, new List <bool>()
            {
                true
            });
            Assert.AreEqual(true_constant2_connection.Outputs, new List <bool>()
            {
                true
            });
            // Try second step: the output from the and gate should change.
            circuit.Simulate();
            Assert.AreEqual(and_gate.Outputs, new List <bool>()
            {
                true
            });
            // Try third step: the output of the connections from the and gate should change.
            circuit.Simulate();
            Assert.AreEqual(and_gate_connection.Outputs, new List <bool>()
            {
                true
            });
            // Try fourth step: the output of the or gate should change.
            circuit.Simulate();
            Assert.AreEqual(or_gate.Outputs, new List <bool>()
            {
                true
            });

            // Ensure the state has stabilized into the expected state:
            for (int i = 0; i < 100; i++)
            {
                circuit.Simulate();
                Assert.AreEqual(true_constant1_connection.Outputs, new List <bool>()
                {
                    true
                });
                Assert.AreEqual(true_constant2_connection.Outputs, new List <bool>()
                {
                    true
                });
                Assert.AreEqual(and_gate.Outputs, new List <bool>()
                {
                    true
                });
                Assert.AreEqual(and_gate_connection.Outputs, new List <bool>()
                {
                    true
                });
                Assert.AreEqual(or_gate.Outputs, new List <bool>()
                {
                    true
                });
            }
        }
Пример #29
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());
        }
Пример #30
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());
        }
Пример #31
0
        public void TestInitialize()
        {
            // Arrange
            TopLevelEvent topLevelEvent = new TopLevelEvent
            {
                Title = "top_level_event"
            };
            AndGate andGate1 = new AndGate
            {
                Title = "and_gate_1"
            };
            Event event1 = new Event
            {
                Title = "event_1"
            };
            Event event2 = new Event
            {
                Title = "event_2"
            };
            OrGate orGate1 = new OrGate
            {
                Title = "or_gate_1"
            };
            OrGate orGate2 = new OrGate
            {
                Title = "or_gate_2"
            };
            BasicEvent basicEvent1 = new BasicEvent
            {
                Title  = "basic_event_1",
                Lambda = 0.2
            };
            BasicEvent basicEvent2 = new BasicEvent
            {
                Title  = "basic_event_2",
                Lambda = 0.1
            };
            BasicEvent basicEvent3 = new BasicEvent
            {
                Title  = "basic_event_3",
                Lambda = 0.3
            };
            BasicEvent basicEvent4 = new BasicEvent
            {
                Title  = "basic_event_4",
                Lambda = 0.1
            };

            Connection connection1 = new Connection
            {
                From = topLevelEvent,
                To   = andGate1
            };
            Connection connection2 = new Connection
            {
                From = andGate1,
                To   = event1
            };
            Connection connection3 = new Connection
            {
                From = andGate1,
                To   = event2
            };
            Connection connection4 = new Connection
            {
                From = event1,
                To   = orGate1
            };
            Connection connection5 = new Connection
            {
                From = orGate1,
                To   = basicEvent1
            };
            Connection connection6 = new Connection
            {
                From = orGate1,
                To   = basicEvent2
            };
            Connection connection7 = new Connection
            {
                From = event2,
                To   = orGate2
            };
            Connection connection8 = new Connection
            {
                From = orGate2,
                To   = basicEvent3
            };
            Connection connection9 = new Connection
            {
                From = orGate2,
                To   = basicEvent4
            };

            topLevelEvent.Children.Add(andGate1);
            andGate1.Parents.Add(topLevelEvent);
            andGate1.Children.Add(event1);
            andGate1.Children.Add(event2);

            event1.Parents.Add(andGate1);
            event1.Children.Add(orGate1);
            event2.Parents.Add(andGate1);
            event2.Children.Add(orGate2);

            orGate1.Parents.Add(event1);
            orGate1.Children.Add(basicEvent1);
            orGate1.Children.Add(basicEvent2);
            orGate2.Parents.Add(event2);
            orGate2.Children.Add(basicEvent3);
            orGate2.Children.Add(basicEvent4);

            basicEvent1.Parents.Add(orGate1);
            basicEvent2.Parents.Add(orGate1);
            basicEvent3.Parents.Add(orGate2);
            basicEvent4.Parents.Add(orGate2);

            project = new Project
            {
                Title     = "TestProject",
                FaultTree = new FaultTree
                {
                    Elements = new ObservableCollection <Element>
                    {
                        topLevelEvent,
                        andGate1,
                        event1,
                        event2,
                        orGate1,
                        orGate2,
                        basicEvent1,
                        basicEvent2,
                        basicEvent3,
                        basicEvent4
                    },
                    Connections = new ObservableCollection <Connection>
                    {
                        connection1,
                        connection2,
                        connection3,
                        connection4,
                        connection5,
                        connection6,
                        connection7,
                        connection8,
                        connection9
                    }
                }
            };
        }
Пример #32
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());
        }
Пример #33
0
        private void ConnectControls()
        {
            or       = new OrGate();
            muxArray = new MuxGate[9];
            NotGate not = new NotGate();

            JGT      = new AndGate();
            JGE      = new OrGate();
            JLE      = new OrGate();
            JNE      = new NotGate();
            notArray = new NotGate[2];

            for (int i = 0; i < notArray.Length; i++)
            {
                notArray[i] = new NotGate();
            }

            m_gJumpMux = new BitwiseMultiwayMux(1, 3);
            jump       = new WireSet(3);

            andForPCLoad = new AndGate();
            Wire PCLoad = new Wire();

            //1.
            m_gAMux.ConnectControl(Instruction[Type]);

            //2. connect control to mux 2 (selects A or M entrance to the ALU)
            m_gMAMux.ConnectControl(Instruction[A]);

            //3. consider all instruction bits only if C type instruction (MSB of instruction is 1)
            for (int i = 0; i < muxArray.Length; i++)
            {
                muxArray[i] = new MuxGate();
                muxArray[i].ConnectInput1(new Wire());
                muxArray[i].ConnectInput2(Instruction[i + 3]);
                muxArray[i].ConnectControl(Instruction[Type]);
            }
            //4. connect ALU control bits
            m_gALU.ZeroX.ConnectInput(muxArray[C1 - 3].Output);
            m_gALU.NotX.ConnectInput(muxArray[C2 - 3].Output);
            m_gALU.ZeroY.ConnectInput(muxArray[C3 - 3].Output);
            m_gALU.NotY.ConnectInput(muxArray[C4 - 3].Output);
            m_gALU.F.ConnectInput(muxArray[C5 - 3].Output);
            m_gALU.NotOutput.ConnectInput(muxArray[C6 - 3].Output);

            //5. connect control to register D (very simple)
            m_rD.Load.ConnectInput(muxArray[D2 - 3].Output);

            //6. connect control to register A (a bit more complicated)
            not.ConnectInput(Instruction[Type]);
            or.ConnectInput1(not.Output);
            or.ConnectInput2(muxArray[D1 - 3].Output);
            m_rA.Load.ConnectInput(or.Output);

            //7. connect control to MemoryWrite
            MemoryWrite.ConnectInput(muxArray[D3 - 3].Output);
            //8. create inputs for jump mux
            notArray[0].ConnectInput(m_gALU.Zero);
            notArray[1].ConnectInput(m_gALU.Negative);
            //JGT:
            JGT.ConnectInput1(notArray[0].Output);
            JGT.ConnectInput2(notArray[1].Output);
            //JGE:
            JGE.ConnectInput1(m_gALU.Zero);
            JGE.ConnectInput2(notArray[1].Output);
            //JNE:
            JNE.ConnectInput(notArray[0].Output);
            //JLE:
            JLE.ConnectInput1(m_gALU.Zero);
            JLE.ConnectInput2(m_gALU.Negative);


            WireSet JGTOut = new WireSet(1);
            WireSet JEQOut = new WireSet(1);
            WireSet JLTOut = new WireSet(1);
            WireSet JGEOut = new WireSet(1);
            WireSet JNEOut = new WireSet(1);
            WireSet JLEOut = new WireSet(1);

            JGTOut[0].ConnectInput(JGT.Output);
            JEQOut[0].ConnectInput(m_gALU.Zero);
            JLTOut[0].ConnectInput(m_gALU.Negative);
            JGEOut[0].ConnectInput(JGE.Output);
            JNEOut[0].ConnectInput(JNE.Output);
            JLEOut[0].ConnectInput(JLE.Output);

            //9. connect jump mux (this is the most complicated part)
            jump[0].ConnectInput(Instruction[J3]);
            jump[1].ConnectInput(Instruction[J2]);
            jump[2].ConnectInput(Instruction[J1]);
            m_gJumpMux.ConnectControl(jump);
            m_gJumpMux.ConnectInput(0, new WireSet(1));
            m_gJumpMux.ConnectInput(1, JGTOut);
            m_gJumpMux.ConnectInput(2, JEQOut);
            m_gJumpMux.ConnectInput(3, JGEOut);
            m_gJumpMux.ConnectInput(4, JLTOut);
            m_gJumpMux.ConnectInput(5, JNEOut);
            m_gJumpMux.ConnectInput(6, JLEOut);
            m_gJumpMux.Inputs[7].Value = 1;
            //10. connect PC load control
            andForPCLoad.ConnectInput1(m_gJumpMux.Output[0]);
            andForPCLoad.ConnectInput2(Instruction[Type]);
            m_rPC.ConnectLoad(andForPCLoad.Output);
        }