private void ConnectJumpWire_JNE() { m_gJNE_Not = new NotGate(); m_gJNE_Not.Input.ConnectInput(m_gALU.Zero); m_wJump[JNE].ConnectInput(m_gJNE_Not.Output); }
public void TestRun() { var simulation = new Simulation(10); var andGate = new AndGate(1, simulation); var notGate = new NotGate(1, simulation); Wire.Connect(andGate.Output, notGate.Input); Assert.AreEqual(Signal.Undefined, andGate.Output.Signal); Assert.AreEqual(Signal.Undefined, notGate.Output.Signal); andGate.Input1.Signal = Signal.On; andGate.Input2.Signal = Signal.Off; simulation.SimulateNextTimeframe(); // czas 0 - nie ma żadnych zdarzeń do przetworzenia simulation.SimulateNextTimeframe(); // czas 1 - zmiany sygnalu przetworzone na bramce and simulation.SimulateNextTimeframe(); // czas 2 - zmiana sygnalu przetworzona na bramce not Assert.AreEqual(Signal.Off, andGate.Output.Signal); Assert.AreEqual(Signal.On, notGate.Output.Signal); andGate.Input2.Signal = Signal.On; simulation.SimulateNextTimeframe(); // czas 3 - nie ma żadnych zdarzeń do przetworzenia simulation.SimulateNextTimeframe(); // czas 4 - zmiana sygnalu przetworzona na bramce and simulation.SimulateNextTimeframe(); // czas 5 - zmiana sygnalu przetworzona na bramce not Assert.AreEqual(Signal.On, andGate.Output.Signal); Assert.AreEqual(Signal.Off, notGate.Output.Signal); }
private void ConnectJumpWire_JGE() { m_gJGE_Not = new NotGate(); m_gJGE_Not.Input.ConnectInput(m_gALU.Negative); m_wJump[JGE].ConnectInput(m_gJGE_Not.Output); }
public void TestOutput(int inputSignal, int expectedOutputSignal) { var notGate = new NotGate(0, new ImmediateSimulation()); notGate.Input.Signal = Signal.FromInt(inputSignal); Assert.AreEqual(Signal.FromInt(expectedOutputSignal), notGate.Output.Signal); }
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(); }
public NotGate Build() { var gate = new NotGate(); gate.SetInput(_input); return(gate); }
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; } }
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); }
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); }
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); }
public void Test_NotGateSimulate() { LogicComponent not_gate = new NotGate(); // Check truth table: Assert.AreEqual(not_gate.Simulate(new [] { true }), new List <bool> { false }); Assert.AreEqual(not_gate.Simulate(new [] { false }), new List <bool> { true }); }
public void Result_InputIsFalse_ShouldReturnTrue() { // Arrange NotGate Gate = new NotGate(); Gate.In = new INode[] { LowStartPoint }; // Act bool output = Gate.Result(); // Assert Assert.IsTrue(output); }
public void Test_CircuitSimulate_SelfCycle() { LogicComponent not_gate = new NotGate(); LogicComponent connection = new Connection(); Circuit circuit = new Circuit(); /* The circuit is just a not gate whose output is connected to its own input by a wire */ circuit.AddComponent(not_gate); circuit.AddComponent(connection); circuit.Connect(not_gate, 0, connection, 0); circuit.Connect(connection, 0, not_gate, 0); /* The circuit's state should repeat every 4 simulate steps. * The expected result of each of the 4 simulate steps in order: * 1) The output of the not gate switches to True. * 2) The output of the connection switches to True. * 3) The output of the not gate switches back to False. * 4) The output of connection switches back to False. */ for (int i = 0; i < 100; i++) { // After first step, not gate should have true output: circuit.Simulate(); Assert.AreEqual(not_gate.Outputs, new List <bool>() { true }); // After second step, connection should have true output too: circuit.Simulate(); Assert.AreEqual(connection.Outputs, new List <bool>() { true }); // After third step, not gate should have false output again: circuit.Simulate(); Assert.AreEqual(not_gate.Outputs, new List <bool>() { false }); // After fourth step, connection should have false output again: circuit.Simulate(); Assert.AreEqual(connection.Outputs, new List <bool>() { false }); } }
// 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()); }
public Hex_Not_Gates() : base(6, 6) { Gate gateA = new NotGate(); int indexA = AddGate(gateA); Gate gateB = new NotGate(); int indexB = AddGate(gateB); Gate gateC = new NotGate(); int indexC = AddGate(gateC); Gate gateD = new NotGate(); int indexD = AddGate(gateD); Gate gateE = new NotGate(); int indexE = AddGate(gateE); Gate gateF = new NotGate(); int indexF = AddGate(gateF); //A AddWire(ID, new Wire(0, 0, indexA, false)); AddWire(gateA.ID, new Wire(0, 0, -1, true)); //B AddWire(ID, new Wire(1, 0, indexB, false)); AddWire(gateB.ID, new Wire(0, 1, -1, true)); //C AddWire(ID, new Wire(2, 0, indexC, false)); AddWire(gateC.ID, new Wire(0, 2, -1, true)); //D AddWire(ID, new Wire(3, 0, indexD, false)); AddWire(gateD.ID, new Wire(0, 3, -1, true)); //E AddWire(ID, new Wire(4, 0, indexE, false)); AddWire(gateE.ID, new Wire(0, 4, -1, true)); //F AddWire(ID, new Wire(5, 0, indexF, false)); AddWire(gateF.ID, new Wire(0, 5, -1, true)); }
public ChipInChip() : base(4, 1) { Chip chipA = new TestChip3(); int indexA = AddChip(chipA); Gate gateB = new NotGate(); int indexB = AddGate(gateB); AddWire(ID, new Wire(3, 3, indexA, true)); AddWire(ID, new Wire(2, 2, indexA, true)); AddWire(ID, new Wire(1, 1, indexA, true)); AddWire(ID, new Wire(0, 0, indexA, true)); AddWire(chipA.ID, new Wire(0, 0, indexB, false)); AddWire(gateB.ID, new Wire(0, 0, -1, true)); Output[0] = true; }
protected override void Awake() { base.Awake(); InConnectors.AddRange(Enumerable.Repeat <SPConnector>(null, 1)); OutConnectors.AddRange(Enumerable.Repeat <SPConnector>(null, 1)); // Set up connectors InConnector = Instantiate(SPInConnectorPrefab, gameObject.transform, false); Assert.IsNotNull(InConnector); InConnector.gameObject.name = "InConnector"; InConnector.transform.localPosition = new Vector3(-1, 0, -1); InConnector.Register(this, SPConnectorType.SPInConnector, 0); OutConnector = Instantiate(SPOutConnectorPrefab, gameObject.transform, false); Assert.IsNotNull(OutConnector); OutConnector.gameObject.name = "OutConnector"; OutConnector.transform.localPosition = new Vector3(1, 0, -1); OutConnector.Register(this, SPConnectorType.SPOutConnector, 0); LogicComponent = new NotGate(); Canvas.Circuit.AddComponent(LogicComponent); }
/// <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)); }
/// <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); NotGate gateA = new NotGate(); int indexA = AddGate(gateA); // OE AddWire(ID, new Wire(9, 0, indexA)); // Clk AddWire(ID, new Wire(8, 0, index1, true)); AddWire(ID, new Wire(8, 0, index2, true)); AddWire(ID, new Wire(8, 0, index3, true)); AddWire(ID, new Wire(8, 0, index4, true)); AddWire(ID, new Wire(8, 0, index5, true)); AddWire(ID, new Wire(8, 0, index6, true)); AddWire(ID, new Wire(8, 0, index7, true)); AddWire(ID, new Wire(8, 0, index8, true)); // 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 AddWire(gateA, new Wire(0, 1, i1)); AddWire(gateA, new Wire(0, 1, i2)); AddWire(gateA, new Wire(0, 1, i3)); AddWire(gateA, new Wire(0, 1, i4)); AddWire(gateA, new Wire(0, 1, i5)); AddWire(gateA, new Wire(0, 1, i6)); AddWire(gateA, new Wire(0, 1, i7)); AddWire(gateA, new Wire(0, 1, i8)); // 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)); }
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 void TestNegation() { AutoResetEvent autoResetEvent = new AutoResetEvent(false); bool result = false; // Create elements var source = new LogicEmitter(); var filter = new NotGate(); var sink = new LogicActionInvoker(value => { result = value; autoResetEvent.Set(); // wait for processing to finish }); // Build the graph source.AttachOutput(filter); filter.AttachOutput(sink); // Start processing source.StartProcessing(); // Test initial state Assert.IsFalse(result); // Emit and test source.EmitTrue(); autoResetEvent.WaitOne(); Assert.IsFalse(result); // Emit and test source.EmitTrue(); autoResetEvent.WaitOne(); Assert.IsFalse(result); // Emit and test source.EmitFalse(); autoResetEvent.WaitOne(); Assert.IsTrue(result); // Emit and test source.EmitFalse(); autoResetEvent.WaitOne(); Assert.IsTrue(result); // Emit and test source.EmitTrue(); autoResetEvent.WaitOne(); Assert.IsFalse(result); // Emit and test source.EmitFalse(); autoResetEvent.WaitOne(); Assert.IsTrue(result); // Emit and test source.EmitFalse(); autoResetEvent.WaitOne(); Assert.IsTrue(result); // Emit and test source.EmitTrue(); autoResetEvent.WaitOne(); Assert.IsFalse(result); }
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); }
private void CreateInternals() { this.andGate = new AndGate(this.PinA, this.PinB); this.notGate = new NotGate(); }
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)); }
/// <summary> /// Converts SaveThisObject into serializable data structures /// </summary> /// <param name="obj">The SaveThisObject to convert</param> /// <returns>A serializable Datum containing the data in the SaveThisObject</returns> public static Datum Convert(SaveThisObject obj) { bool panel = obj.ObjectType.StartsWith("Panel") || obj.ObjectType == "Through Blotter"; Datum result = null; switch (obj.ObjectType) { case "CircuitBoard": List <Datum> children = new List <Datum>(obj.transform.childCount); CircuitBoard comp = obj.GetComponent <CircuitBoard>(); foreach (Transform child in obj.transform) { SaveThisObject save = child.GetComponent <SaveThisObject>(); if (save != null) { children.Add(Convert(save)); } } Renderer renderer = obj.GetComponent <Renderer>(); result = new BoardDatum { width = comp.x, height = comp.z, children = children.ToArray(), color = renderer.material.color }; break; case "Wire": result = new WireDatum { isInputInput = obj.GetComponent <InputInputConnection>() != null, localScale = obj.transform.localScale }; break; case "Inverter": NotGate gate = obj.GetComponent <NotGate>(); result = new InverterDatum { inputOn = gate.Input.On, outputOn = gate.Output.On }; break; case "Peg": result = new PegDatum { isOn = obj.GetComponent <CircuitInput>().On }; break; case "Delayer": Delayer delayer = obj.GetComponent <Delayer>(); result = new DelayerDatum { inputOn = delayer.Input.On, outputOn = delayer.Output.On, delayCount = delayer.DelayCount }; break; case "Through Peg": CircuitInput[] inputs = obj.GetComponentsInChildren <CircuitInput>(); result = new ThroughPegDatum { isOn = inputs[0].On }; break; case "Switch": case "Panel Switch": result = new SwitchDatum { panel = panel, isOn = obj.GetComponent <Switch>().On }; break; case "Button": case "Panel Button": Button button = obj.GetComponent <Button>(); result = new ButtonDatum { panel = panel, isOn = button.output.On, downTime = button.ButtonDownTime }; break; case "Display": case "Panel Display": result = new DisplayDatum { panel = panel, isOn = obj.GetComponent <global::Display>().Input.On }; break; case "Label": case "Panel Label": Label label = obj.GetComponent <Label>(); result = new LabelDatum { panel = panel, text = label.text.text, fontSize = label.text.fontSize }; break; case "Blotter": case "Through Blotter": Blotter blotter = obj.GetComponent <Blotter>(); result = new BlotterDatum { through = panel, inputOn = blotter.Input.On, outputON = blotter.Output.On }; break; } result.localPosition = obj.transform.localPosition; result.localAngles = obj.transform.localEulerAngles; return(result); }
/// <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 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)); }
//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(); }
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)); }
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)); }
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); }
private void ConnectControls() { //1. connect control of mux 1 (selects entrance to register A) m_gAMux.ConnectControl(Instruction[Type]); // opcode //2. connect control to mux 2 (selects A or M entrance to the ALU) m_gMAMux.ConnectControl(Instruction[A]); // a/m //3. consider all instruction bits only if C type instruction (MSB of instruction is 1) //4. connect ALU control bits m_gALU.ZeroX.ConnectInput(Instruction[C1]); m_gALU.NotX.ConnectInput(Instruction[C2]); m_gALU.ZeroY.ConnectInput(Instruction[C3]); m_gALU.NotY.ConnectInput(Instruction[C4]); m_gALU.F.ConnectInput(Instruction[C5]); m_gALU.NotOutput.ConnectInput(Instruction[C6]); //5. connect control to register D (very simple) and = new AndGate(); and.ConnectInput1(Instruction[Type]); and.ConnectInput2(Instruction[D2]); m_rD.Load.ConnectInput(and.Output); //6. connect control to register A (a bit more complicated) orOfA = new OrGate(); // shortcut for what we did in lesson "instead using and & not gates" // to implement as in lecture andOfA = new AndGate(); notOfA = new NotGate(); notOfA.ConnectInput(Instruction[Type]); andOfA.ConnectInput1(Instruction[Type]); andOfA.ConnectInput2(Instruction[D1]); orOfA.ConnectInput1(andOfA.Output); orOfA.ConnectInput2(notOfA.Output); m_rA.Load.ConnectInput(orOfA.Output); //7. connect control to MemoryWritea andOfMemoryWrite = new AndGate(); andOfMemoryWrite.ConnectInput1(Instruction[Type]); andOfMemoryWrite.ConnectInput2(Instruction[D3]); MemoryWrite.ConnectInput(andOfMemoryWrite.Output); //8. create inputs for jump mux Wire on = new Wire(); on.Value = 1; Wire off = new Wire(); off.Value = 0; m_gJumpMux = new BitwiseMultiwayMux(1, 3); // so i'm gonna use it as jump box in lesson jumpOr1 = new OrGate(); jumpOr1.ConnectInput1(m_gALU.Zero); jumpOr1.ConnectInput2(m_gALU.Negative); jumpNot1 = new NotGate(); jumpNot1.ConnectInput(jumpOr1.Output); jumpNot2 = new NotGate(); jumpNot2.ConnectInput(m_gALU.Negative); jumpNot3 = new NotGate(); jumpNot3.ConnectInput(m_gALU.Zero); jumpOr2 = new OrGate(); jumpOr2.ConnectInput1(m_gALU.Zero); jumpOr2.ConnectInput2(m_gALU.Negative); Wire input1 = off; // we did somthing like this in practical session Wire input2 = jumpNot1.Output; Wire input3 = m_gALU.Zero; Wire input4 = jumpNot2.Output; Wire input5 = m_gALU.Negative; Wire input6 = jumpNot3.Output; Wire input7 = jumpOr2.Output; Wire input8 = on; //9. connect jump mux (this is the most complicated part m_gJumpMux.Inputs[0][0].ConnectInput(input1); m_gJumpMux.Inputs[1][0].ConnectInput(input2); m_gJumpMux.Inputs[2][0].ConnectInput(input3); m_gJumpMux.Inputs[3][0].ConnectInput(input4); m_gJumpMux.Inputs[4][0].ConnectInput(input5); m_gJumpMux.Inputs[5][0].ConnectInput(input6); m_gJumpMux.Inputs[6][0].ConnectInput(input7); m_gJumpMux.Inputs[7][0].ConnectInput(input8); m_gJumpMux.Control[0].ConnectInput(Instruction[J3]); m_gJumpMux.Control[1].ConnectInput(Instruction[J2]); m_gJumpMux.Control[2].ConnectInput(Instruction[J1]); //10. connect PC load control andOfpc = new AndGate(); andOfpc.ConnectInput1(Instruction[Type]); andOfpc.ConnectInput2(m_gJumpMux.Output[0]); m_rPC.ConnectLoad(andOfpc.Output); }