Пример #1
0
 // Helper Methods:
 private static string ToHadesString(this Component component)
 {
     return(component switch
     {
         ANDGate and =>
         $"hades.models.gatter.And{and.NumberOfInputs} {and.Name} {and.Pos.X * 3}0 {and.Pos.Y * 3}0 @N 1001 1.0E-8",
         INVGate inv =>
         $"hades.models.gatter.Inv {inv.Name} {inv.Pos.X * 3}0 {inv.Pos.Y * 3}0 @N 1001 5.0E-9",
         NANDGate nand =>
         $"hades.models.gatter.Nand{nand.NumberOfInputs} {nand.Name} {nand.Pos.X * 3}0 {nand.Pos.Y * 3}0 @N 1001 1.0E-8",
         NORGate nor =>
         $"hades.models.gatter.Nor{nor.NumberOfInputs} {nor.Name} {nor.Pos.X * 3}0 {nor.Pos.Y * 3}0 @N 1001 1.0E-8",
         ORGate or =>
         $"hades.models.gatter.Or{or.NumberOfInputs} {or.Name} {or.Pos.X * 3}0 {or.Pos.Y * 3}0 @N 1001 1.0E-8",
         XNORGate xnor =>
         $"hades.models.gatter.Xnor{xnor.NumberOfInputs} {xnor.Name} {xnor.Pos.X * 3}0 {xnor.Pos.Y * 3}0 @N 1001 1.0E-8",
         XORGate xor =>
         $"hades.models.gatter.Xor{xor.NumberOfInputs} {xor.Name} {xor.Pos.X * 3}0 {xor.Pos.Y * 3}0 @N 1001 1.0E-8",
         InputPulse ip =>
         $"hades.models.io.PulseSwitch {ip.Name} {ip.Pos.X * 3}0 {ip.Pos.Y * 3}0 @N 1001 0.1 null",
         InputClock ic =>
         $"hades.models.io.ClockGen {ic.Name} {ic.Pos.X * 3}0 {ic.Pos.Y * 3}0 @N 1001 {InputClock.MsToSec()} 0.5 0.0",
         Input i => $"hades.models.io.Ipin {i.Name} {i.Pos.X * 3}0 {i.Pos.Y * 3}0 @N 1001  {i.IsActive}",
         Output o => $"hades.models.io.Opin {o.Name} {o.Pos.X * 3}0 {o.Pos.Y * 3}0 @N 1001 5.0E-9",
         _ => throw new ComponentNotFoundException(component.GetType().ToString())
     });
Пример #2
0
        public Quad_Nor_Gates() : base(8, 4)
        {
            Gate gateA  = new NORGate();
            int  indexA = AddGate(gateA);

            Gate gateB  = new NORGate();
            int  indexB = AddGate(gateB);

            Gate gateC  = new NORGate();
            int  indexC = AddGate(gateC);

            Gate gateD  = new NORGate();
            int  indexD = AddGate(gateD);

            // Gate A
            AddWire(ID, new Wire(0, 0, indexA, false));
            AddWire(ID, new Wire(1, 1, indexA, false));
            AddWire(gateA.ID, new Wire(0, 0, -1, true));

            // Gate B
            AddWire(ID, new Wire(2, 0, indexB, false));
            AddWire(ID, new Wire(3, 1, indexB, false));
            AddWire(gateB.ID, new Wire(0, 1, -1, true));

            // Gate C
            AddWire(ID, new Wire(4, 0, indexC, false));
            AddWire(ID, new Wire(5, 1, indexC, false));
            AddWire(gateC.ID, new Wire(0, 2, -1, true));

            // Gate D
            AddWire(ID, new Wire(6, 0, indexD, false));
            AddWire(ID, new Wire(7, 1, indexD, false));
            AddWire(gateD.ID, new Wire(0, 3, -1, true));
        }
Пример #3
0
        public void NOR()
        {
            PowerSupplier  power1  = new PowerSupplier();
            PowerSupplier  power2  = new PowerSupplier();
            NORGate        norGate = new NORGate();
            IndicatorLight light   = new IndicatorLight();

            norGate.Output.ConnectTo(light.Input);
            Assert.IsTrue(light.Lighting);

            norGate.Input1.ConnectTo(power1.Output);
            norGate.Input2.ConnectTo(power2.Output);
            Assert.IsTrue(light.Lighting);

            power1.On();
            power2.Off();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.On();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.Off();
            Assert.IsTrue(light.Lighting);
        }
Пример #4
0
        public FlipFlop()
        {
            _norGate1 = new NORGate();
            _norGate2 = new NORGate();
            _nexus    = new TShapedNexus(_norGate2.Output, _norGate1.Input1);

            _norGate1.Output.ConnectTo(_norGate2.Input1);

            Set    = _norGate1.Input2;
            Clear  = _norGate2.Input2;
            Output = _nexus.GetEndpointAt(2);
        }
Пример #5
0
        public RSFlipFlop()
        {
            _norGate1 = new NORGate();
            _norGate2 = new NORGate();
            _nexus1   = new TShapedNexus(_norGate1.Output, _norGate2.Input1);
            _nexus2   = new TShapedNexus(_norGate2.Output, _norGate1.Input1);

            Reset = _norGate1.Input2;
            Set   = _norGate2.Input2;
            Q     = _nexus1.GetEndpointAt(2);
            QBar  = _nexus2.GetEndpointAt(2);
        }
Пример #6
0
        public XNORGate()
        {
            _orGate  = new ORGate();
            _norGate = new NORGate();
            _andGate = new ANDGate();
            _nexus1  = new TShapedNexus(null, _andGate.Input1, _norGate.Input1);
            _nexus2  = new TShapedNexus(null, _andGate.Input2, _norGate.Input2);

            _orGate.Input1.ConnectTo(_andGate.Output);
            _orGate.Input2.ConnectTo(_norGate.Output);

            Input1 = _nexus1.GetEndpointAt(0);
            Input2 = _nexus2.GetEndpointAt(0);
            Output = _orGate.Output;
        }
Пример #7
0
        public TestChip2() : base(3, 1)
        {
            Gate gateA  = new NANDGate();
            int  indexA = AddGate(gateA);

            Gate gateB  = new NORGate();
            int  indexB = AddGate(gateB);

            Gate gateC  = new ANDGate(3);
            int  indexC = AddGate(gateC);

            AddWire(ID, new Wire(2, 0, indexA, false));
            AddWire(ID, new Wire(2, 0, indexB, false));
            AddWire(ID, new Wire(1, 1, indexC, false));
            AddWire(ID, new Wire(0, 1, indexA, false));
            AddWire(ID, new Wire(0, 1, indexB, false));

            AddWire(gateA.ID, new Wire(0, 0, indexC, false));
            AddWire(gateB.ID, new Wire(0, 2, indexC, false));

            AddWire(gateC.ID, new Wire(0, 0, -1, true));
        }
Пример #8
0
        /// <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));
        }