Пример #1
0
        static IC Nor()
        {
            Circuit nor = new Circuit();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not();

            Gates.IOGates.UserInput  in1  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  in2  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();

            nor.Add(mand);
            nor.Add(mnot1);
            nor.Add(mnot2);
            nor.Add(in1);
            nor.Add(in2);
            nor.Add(out1);

            nor[new Terminal(0, mnot1)] = new Terminal(0, in1);
            nor[new Terminal(0, mnot2)] = new Terminal(0, in2);
            nor[new Terminal(0, mand)]  = new Terminal(0, mnot1);
            nor[new Terminal(1, mand)]  = new Terminal(0, mnot2);
            nor[new Terminal(0, out1)]  = new Terminal(0, mand);

            return(new IC(nor, new Gates.IOGates.UserInput[] { in1, in2 },
                          new Gates.IOGates.UserOutput[] { out1 }, "Nor"));
        }
Пример #2
0
        static IC SRLatch()
        {
            Circuit sr   = new Circuit();
            IC      nor1 = Nor();
            IC      nor2 = Nor();

            Gates.IOGates.UserInput  in1  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  in2  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();
            Gates.IOGates.UserOutput out2 = new Gates.IOGates.UserOutput();

            sr.Add(nor1);
            sr.Add(nor2);

            sr.Add(in1);
            sr.Add(in2);
            sr.Add(out1);
            sr.Add(out2);

            nor1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(nor_PropertyChanged);

            sr[new Terminal(0, nor1)] = new Terminal(0, in1);
            sr[new Terminal(1, nor2)] = new Terminal(0, in2);

            sr[new Terminal(1, nor1)] = new Terminal(0, nor2);
            sr[new Terminal(0, nor2)] = new Terminal(0, nor1);

            sr[new Terminal(0, out1)] = new Terminal(0, nor1);
            sr[new Terminal(0, out2)] = new Terminal(0, nor2);

            return(new IC(sr, new Gates.IOGates.UserInput[] { in1, in2 },
                          new Gates.IOGates.UserOutput[] { out1, out2 }, "SRLatch"));
        }
Пример #3
0
        public UserInput(Gates.IOGates.UserInput gate)
            : base(gate,
                   new TerminalID[] {
            new TerminalID(false, 0, Position.RIGHT)
        })
        {
            Rectangle r = new Rectangle();

            r.Margin          = new System.Windows.Thickness(15);
            r.Width           = 34;
            r.Height          = 34;
            r.Stroke          = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill            = Brushes.White;
            myCanvas.Children.Add(r);

            _r                 = new Rectangle();
            _r.Margin          = new System.Windows.Thickness(20);
            _r.Width           = 24;
            _r.Height          = 24;
            _r.Stroke          = Brushes.Black;
            _r.StrokeThickness = 2;
            SetFill();

            _r.MouseEnter += new System.Windows.Input.MouseEventHandler(r_MouseEnter);
            _r.MouseLeave += new System.Windows.Input.MouseEventHandler(r_MouseLeave);
            _r.MouseDown  += new System.Windows.Input.MouseButtonEventHandler(r_MouseDown);


            myCanvas.Children.Add(_r);
            myCanvas.Children.Add(txtName);
            myCanvas.Children.Add(txtFirstLetter);
        }
Пример #4
0
        private Gates.IC CreateAndChain(int len)
        {
            Gates.Circuit andc = new Gates.Circuit();
            andc.Start();



            Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput();
            andc.Add(in1);
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();
            andc.Add(out1);

            if (len > 1)
            {
                Gates.IC cand1 = CreateAndChain(len / 2);
                Gates.IC cand2 = CreateAndChain(len / 2);
                andc.Add(cand1);
                andc.Add(cand2);
                andc[new Gates.Terminal(0, cand1)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(0, cand2)] = new Gates.Terminal(0, cand1);
                andc[new Gates.Terminal(0, out1)]  = new Gates.Terminal(0, cand2);
            }
            else
            {
                Gates.BasicGates.And mand = new Gates.BasicGates.And();
                andc.Add(mand);
                andc[new Gates.Terminal(0, mand)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(1, mand)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, mand);
            }

            return(new Gates.IC(andc, new Gates.IOGates.UserInput[] { in1 },
                                new Gates.IOGates.UserOutput[] { out1 }, "AndChain"));
        }
Пример #5
0
        Gates.IC CreateSRLatch()
        {
            Gates.Circuit sr = new Gates.Circuit();
            sr.Start();
            Gates.IC nor1 = CreateNor();
            Gates.IC nor2 = CreateNor();

            Gates.IOGates.UserInput  in1  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  in2  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();
            Gates.IOGates.UserOutput out2 = new Gates.IOGates.UserOutput();

            sr.Add(nor1);
            sr.Add(nor2);

            sr.Add(in1);
            sr.Add(in2);
            sr.Add(out1);
            sr.Add(out2);


            sr[new Gates.Terminal(0, nor1)] = new Gates.Terminal(0, in1);
            sr[new Gates.Terminal(1, nor2)] = new Gates.Terminal(0, in2);

            sr[new Gates.Terminal(1, nor1)] = new Gates.Terminal(0, nor2);
            sr[new Gates.Terminal(0, nor2)] = new Gates.Terminal(0, nor1);

            sr[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, nor1);
            sr[new Gates.Terminal(0, out2)] = new Gates.Terminal(0, nor2);

            return(new Gates.IC(sr, new Gates.IOGates.UserInput[] { in1, in2 },
                                new Gates.IOGates.UserOutput[] { out1, out2 }, "SRLatch"));
        }
Пример #6
0
        public void UserInput()
        {
            Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput();

            ui.Value = false;
            Assert.AreEqual(ui.Output[0], false);

            ui.Value = true;
            Assert.AreEqual(ui.Output[0], true);
        }
Пример #7
0
        public void PropagationTest()
        {
            // this test checks for the accuracy
            // of wait for propagation
            // by determining if it fully waits for all propagation
            // to occur through the contained sub-circuits

            // this came from a problem where all sub-circuits
            // were instructed to wait BUT
            // the loop didn't repeat this based on that
            // so one could pass off an incomplete result
            // to another and the waiting could end before
            // it was all really done
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            // EXTREMELY SPECIFIC
            // The long chain appears FIRST in the circuit add list
            // But the input connects to the short chain first
            // Then the wait waits on the long chain, which has nothing
            // then briefly on the short chain, which passes a change
            // to the long chain...
            // but it DOESN'T wait for the long chain to finish
            // (because it already waited on the long chain before it had any work!)
            Gates.IC ac1 = CreateAndChain(64);
            Gates.IC ac2 = CreateAndChain(10);

            Gates.IOGates.UserInput ui   = new Gates.IOGates.UserInput();
            Gates.BasicGates.And    mand = new Gates.BasicGates.And();

            c.Add(ac1);
            c.Add(ac2);
            c.Add(ui);
            c.Add(mand);

            c[new Gates.Terminal(0, ac2)]  = new Gates.Terminal(0, ui);
            c[new Gates.Terminal(0, ac1)]  = new Gates.Terminal(0, ac2);
            c[new Gates.Terminal(0, mand)] = new Gates.Terminal(0, ac1);
            c[new Gates.Terminal(1, mand)] = new Gates.Terminal(0, ac2);

            ui.Value = false;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mand.Output[0]);

            ui.Value = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, mand.Output[0]);
        }
Пример #8
0
        static void TestIC2()
        {
            Circuit c = new Circuit();

            Gates.IOGates.UserInput  ui_r = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  ui_s = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput uo   = new Gates.IOGates.UserOutput();
            IC latch = SRLatch();

            c.Add(ui_r);
            c.Add(ui_s);
            c.Add(uo);
            c.Add(latch);

            c[new Terminal(0, latch)] = new Terminal(0, ui_r);
            c[new Terminal(1, latch)] = new Terminal(0, ui_s);
            c[new Terminal(0, uo)]    = new Terminal(0, latch);

            uo.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(uo_PropertyChanged);

            while (true)
            {
                Console.WriteLine("Ready for input (S = set, R = reset, X = hold, I = illegal)");
                string val = Console.In.ReadLine();
                if (val == "S")
                {
                    ui_r.Value = false;
                    ui_s.Value = true;
                }
                if (val == "R")
                {
                    ui_s.Value = false;
                    ui_r.Value = true;
                }
                if (val == "X")
                {
                    ui_s.Value = false;
                    ui_r.Value = false;
                }
                if (val == "I")
                {
                    ui_s.Value = true;
                    ui_r.Value = true;
                }
            }
        }
Пример #9
0
        public void SRLatch()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.IOGates.UserInput  ui_r = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  ui_s = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput uo   = new Gates.IOGates.UserOutput();
            Gates.IC latch = CreateSRLatch();

            c.Add(ui_r);
            c.Add(ui_s);
            c.Add(uo);
            c.Add(latch);

            c[new Gates.Terminal(0, latch)] = new Gates.Terminal(0, ui_r);
            c[new Gates.Terminal(1, latch)] = new Gates.Terminal(0, ui_s);
            c[new Gates.Terminal(0, uo)]    = new Gates.Terminal(0, latch);

            for (int i = 0; i < 4; i++)
            {
                // SET
                ui_r.Value = false;
                ui_s.Value = true;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(true, uo.Value);

                // HOLD
                ui_r.Value = false;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(true, uo.Value);

                // RESET
                ui_r.Value = true;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(false, uo.Value);

                // HOLD
                ui_r.Value = false;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(false, uo.Value);
            }
        }
Пример #10
0
        static void TestUserIO()
        {
            Circuit c = new Circuit();

            Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not();
            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot3 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not();

            Gates.IOGates.UserInput  ui = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput();

            c.Add(mnot1);
            c.Add(mnot2);
            c.Add(mand);
            c.Add(mnot3);

            c.Add(ui);
            c.Add(uo);


            uo.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(uo_PropertyChanged);

            c[new Terminal(0, mand)]  = new Terminal(0, mnot2);
            c[new Terminal(0, mnot3)] = new Terminal(0, mand);
            c[new Terminal(0, mnot1)] = new Terminal(0, mnot3);
            c[new Terminal(0, mnot2)] = new Terminal(0, mnot1);

            c[new Terminal(1, mand)] = new Terminal(0, ui);
            c[new Terminal(0, uo)]   = new Terminal(0, mnot3);



            do
            {
                Console.Out.WriteLine("Ready for X");
                Console.In.ReadLine();
                ui.Value = !ui.Value;
            } while (true);
        }
Пример #11
0
        private Gates.AbstractGate CreateGate(XElement gate)
        {
            int numInputs = 2; // default for variable input gates
            if (gate.Attribute("NumInputs") != null)
                numInputs = int.Parse(gate.Attribute("NumInputs").Value);

            switch (gate.Attribute("Type").Value)
            {
                case "And":
                    return new Gates.BasicGates.And(numInputs);
                case "Not":
                    return new Gates.BasicGates.Not();
                case "Or":
                    return new Gates.BasicGates.Or(numInputs);
                case "Nand":
                    return new Gates.BasicGates.Nand(numInputs);
                case "Nor":
                    return new Gates.BasicGates.Nor(numInputs);
                case "Xor":
                    return new Gates.BasicGates.Xor();
                case "Xnor":
                    return new Gates.BasicGates.Xnor();
                case "Buffer":
                    return new Gates.BasicGates.Buffer();
                case "UserInput":
                    Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput();
                    ui.SetName(gate.Attribute("Name").Value);
                    return ui;
                case "UserOutput":
                    Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput();
                    uo.SetName(gate.Attribute("Name").Value);
                    return uo;
                case "NumericInput":
                    Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value));
                    ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value);
                    ni.Value = gate.Attribute("Value").Value;
                    return ni;
                case "NumericOutput":
                    Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value));
                    no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value);
                    return no;
                case "Clock":
                    Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value));
                    return clk;
                case "IC":
                    // check if this ic has been renamed
                    string cname = gate.Attribute("Name").Value;
                    // check first if we need to rename
                    if (UpdateICNames.ContainsKey(cname))
                        cname = UpdateICNames[cname];
                
                    return icl.GetIC(cname).AbGate.Clone();
                case "Comment":
                    Gates.IOGates.Comment cmt = new Gates.IOGates.Comment();
                    cmt.Value = gate.Element("Comment").Value;
                    return cmt;
                
            }
            throw new ArgumentException("unknown gate");
        }
Пример #12
0
        //Modified method from CircuitXML.CreateGate Method
        private Gates.AbstractGate CreateGate(XElement gate)
        {
            int numInputs = 2; // default for variable input gates
            if (gate.Attribute("NumInputs") != null)
                numInputs = int.Parse(gate.Attribute("NumInputs").Value);

            switch (gate.Attribute("Type").Value)
            {
                case "And":
                    return new Gates.BasicGates.And(numInputs);
                case "Not":
                    return new Gates.BasicGates.Not();
                case "Or":
                    return new Gates.BasicGates.Or(numInputs);
                case "Nand":
                    return new Gates.BasicGates.Nand(numInputs);
                case "Nor":
                    return new Gates.BasicGates.Nor(numInputs);
                case "Xor":
                    return new Gates.BasicGates.Xor();
                case "Xnor":
                    return new Gates.BasicGates.Xnor();
                case "Buffer":
                    return new Gates.BasicGates.Buffer();
                case "UserInput":
                    Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput();
                    ui.SetName(gate.Attribute("Name").Value);
                    return ui;
                case "UserOutput":
                    Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput();
                    uo.SetName(gate.Attribute("Name").Value);
                    return uo;
                case "NumericInput":
                    Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value));
                    ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value);
                    ni.Value = gate.Attribute("Value").Value;
                    return ni;
                case "NumericOutput":
                    Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value));
                    no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value);
                    return no;
                case "Clock":
                    Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value));
                    return clk;
                case "Comment":
                    Gates.IOGates.Comment cmt = new Gates.IOGates.Comment();
                    cmt.Value = gate.Element("Comment").Value;
                    return cmt;
            }
            throw new ArgumentException("unknown gate");
        }
Пример #13
0
        private Gates.AbstractGate CreateGate(XElement gate)
        {
            int numInputs = 2; // default for variable input gates

            if (gate.Attribute("NumInputs") != null)
            {
                numInputs = int.Parse(gate.Attribute("NumInputs").Value);
            }

            switch (gate.Attribute("Type").Value)
            {
            case "And":
                return(new Gates.BasicGates.And(numInputs));

            case "Not":
                return(new Gates.BasicGates.Not());

            case "Or":
                return(new Gates.BasicGates.Or(numInputs));

            case "Nand":
                return(new Gates.BasicGates.Nand(numInputs));

            case "Nor":
                return(new Gates.BasicGates.Nor(numInputs));

            case "Xor":
                return(new Gates.BasicGates.Xor());

            case "Xnor":
                return(new Gates.BasicGates.Xnor());

            case "Buffer":
                return(new Gates.BasicGates.Buffer());

            case "UserInput":
                Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput();
                ui.SetName(gate.Attribute("Name").Value);
                return(ui);

            case "UserOutput":
                Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput();
                uo.SetName(gate.Attribute("Name").Value);
                return(uo);

            case "NumericInput":
                Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value));
                ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value);
                ni.Value = gate.Attribute("Value").Value;
                return(ni);

            case "NumericOutput":
                Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value));
                no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value);
                return(no);

            case "Clock":
                Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value));
                return(clk);

            case "IC":
                // check if this ic has been renamed
                string cname = gate.Attribute("Name").Value;
                // check first if we need to rename
                if (UpdateICNames.ContainsKey(cname))
                {
                    cname = UpdateICNames[cname];
                }

                return(icl.GetIC(cname).AbGate.Clone());

            case "Comment":
                Gates.IOGates.Comment cmt = new Gates.IOGates.Comment();
                cmt.Value = gate.Element("Comment").Value;
                return(cmt);
            }
            throw new ArgumentException("unknown gate");
        }