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

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

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

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

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

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

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

            // Gate D
            AddWire(ID, new Wire(6, 0, indexD, false));
            AddWire(ID, new Wire(7, 1, indexD, false));
            AddWire(gateD.ID, new Wire(0, 3, -1, true));
        }
        public void XOR()
        {
            PowerSupplier  power1  = new PowerSupplier();
            PowerSupplier  power2  = new PowerSupplier();
            XORGate        xorGate = new XORGate();
            IndicatorLight light   = new IndicatorLight();

            xorGate.Output.ConnectTo(light.Input);
            Assert.IsFalse(light.Lighting);

            xorGate.Input1.ConnectTo(power1.Output);
            xorGate.Input2.ConnectTo(power2.Output);
            Assert.IsFalse(light.Lighting);

            power1.On();
            power2.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.On();
            Assert.IsTrue(light.Lighting);
            power1.On();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.Off();
            Assert.IsFalse(light.Lighting);
        }
Exemple #4
0
 private void InitXORGates()
 {
     _xorGates = new XORGate[8];
     for (var i = 0; i < WIDTH; i++)
     {
         _xorGates[i] = new XORGate();
     }
 }
Exemple #5
0
        public HalfAdder()
        {
            _andGate = new ANDGate();
            _xorGate = new XORGate();
            _nexus1  = new TShapedNexus(null, _andGate.Input1, _xorGate.Input1);
            _nexus2  = new TShapedNexus(null, _andGate.Input2, _xorGate.Input2);

            Number1In = _nexus1.GetEndpointAt(0);
            Number2In = _nexus2.GetEndpointAt(0);
            Sum       = _xorGate.Output;
            CarryOut  = _andGate.Output;
        }
Exemple #6
0
        private void InitBasicElements()
        {
            _cplmtor = new TComplementor();
            _adder   = new TAdder();

            if (_adder.BitWidth != _cplmtor.BitWidth)
            {
                throw new ArgumentException("Bit width between adder and complementor are not match.");
            }

            _xorGate  = new XORGate();
            _subNexus = new CrossNexus(null, _cplmtor.Invert, _adder.CarryInput, _xorGate.Input1);

            _cplmtor.Outputs.Connect(_adder.Number2Inputs);
            _adder.CarryOutput.ConnectTo(_xorGate.Input2);
        }
Exemple #7
0
        public Full_Adder() : base(3, 2)
        {
            Gate gateA  = new XORGate();
            int  indexA = AddGate(gateA);

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

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

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

            Gate gateE  = new ORGate();
            int  indexE = AddGate(gateE);

            // Gate A
            AddWire(ID, new Wire(0, 0, indexA));
            AddWire(ID, new Wire(1, 1, indexA));
            AddWire(gateA.ID, new Wire(0, 0, indexB));
            AddWire(gateA.ID, new Wire(0, 0, indexC));

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

            // Gate C
            AddWire(ID, new Wire(2, 1, indexC));
            AddWire(gateC.ID, new Wire(0, 0, indexE));

            // Gate D
            AddWire(ID, new Wire(0, 0, indexD));
            AddWire(ID, new Wire(1, 1, indexD));
            AddWire(gateD.ID, new Wire(0, 1, indexE));

            // Gate E
            AddWire(gateE.ID, new Wire(0, 1, -1, true));
        }
Exemple #8
0
        public override void Initialize()
        {
            base.Initialize();

            par = parent as XORGate;
        }
Exemple #9
0
        public override void Initialize()
        {
            base.Initialize();

            par = parent as XORGate;
        }