Example #1
0
        public void ThruCircuit1()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.And mand2 = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot  = new Gates.BasicGates.Not();

            c.Add(mand);
            c.Add(mand2);
            c.Add(mnot);
            mand2[0] = true;

            c[new Gates.Terminal(1, mand2)] = new Gates.Terminal(0, mand);
            c[new Gates.Terminal(0, mnot)]  = new Gates.Terminal(0, mand2);


            Assert.AreEqual(true, mnot.Output[0]);

            mand[1] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, mnot.Output[0]);

            mand[0] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mnot.Output[0]);
        }
Example #2
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"));
        }
Example #3
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"));
        }
Example #4
0
        public void OscillationCircuit1()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.And mand2 = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot  = new Gates.BasicGates.Not();

            c.Add(mand);
            c.Add(mand2);
            c.Add(mnot);
            mand2[0] = true;
            mand[1]  = false;

            c[new Gates.Terminal(1, mand2)] = new Gates.Terminal(0, mand);
            c[new Gates.Terminal(0, mnot)]  = new Gates.Terminal(0, mand2);
            c[new Gates.Terminal(0, mand)]  = new Gates.Terminal(0, mnot);


            int      cnt    = 0;
            bool     oldval = true;
            DateTime start  = DateTime.Now;

            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot.Output[0] != oldval)
                {
                    oldval = mnot.Output[0];
                    cnt++;
                }
            }
            // 5 seconds but circuit should be "off" due to first and
            Assert.AreEqual(0, cnt);

            // turn circuit on and try again
            mand[1] = true;
            cnt     = 0;
            oldval  = false;
            start   = DateTime.Now;
            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot.Output[0] != oldval)
                {
                    oldval = mnot.Output[0];
                    cnt++;
                }
            }

            // 5 seconds at arbitrarily high propagation rate
            // we'll assume AT LEAST 1 prop a second
            if (cnt < 5)
            {
                Assert.Fail("Unacceptable count = " + cnt.ToString());
            }

            c.Stop();
        }
Example #5
0
        public And(Gates.BasicGates.And mand) : base(mand,
                                                     new TerminalID[] { new TerminalID(true, 0, Position.LEFT),
                                                                        new TerminalID(true, 1, Position.LEFT),
                                                                        new TerminalID(false, 0, Position.RIGHT) })
        {
            Path ph = new Path();

            ph.Data            = StreamGeometry.Parse("M 15,12 v 40 h 15 a 2,2 1 0 0 0,-40 h -15");
            ph.Stroke          = Brushes.Black;
            ph.StrokeThickness = 2;
            ph.Fill            = Brushes.White;
            myCanvas.Children.Add(ph);
        }
Example #6
0
        public void ThreeInputAnd()
        {
            Gates.BasicGates.And and = new Gates.BasicGates.And(3);
            and[0] = false;
            and[1] = false;
            and[2] = false;

            Assert.AreEqual(and.Output[0], false);

            and[0] = true;
            and[1] = false;
            and[2] = false;

            Assert.AreEqual(and.Output[0], false);

            and[0] = false;
            and[1] = true;
            and[2] = false;

            Assert.AreEqual(and.Output[0], false);

            and[0] = true;
            and[1] = true;
            and[2] = false;

            Assert.AreEqual(and.Output[0], false);

            and[0] = false;
            and[1] = false;
            and[2] = true;

            Assert.AreEqual(and.Output[0], false);

            and[0] = true;
            and[1] = false;
            and[2] = true;

            Assert.AreEqual(and.Output[0], false);

            and[0] = false;
            and[1] = true;
            and[2] = true;

            Assert.AreEqual(and.Output[0], false);

            and[0] = true;
            and[1] = true;
            and[2] = true;

            Assert.AreEqual(and.Output[0], true);
        }
Example #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]);
        }
Example #8
0
        static void TestClock()
        {
            Circuit c = new Circuit();

            Gates.IOGates.Clock  clk1 = new Gates.IOGates.Clock(1000);
            Gates.IOGates.Clock  clk2 = new Gates.IOGates.Clock(250);
            Gates.BasicGates.And mand = new Gates.BasicGates.And();

            c.Add(clk1);
            c.Add(clk2);
            c.Add(mand);

            mand.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mand2_PropertyChanged);

            //mand[1] = true;

            c[new Terminal(0, mand)] = new Terminal(0, clk1);
            c[new Terminal(1, mand)] = new Terminal(0, clk2);
        }
Example #9
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);
        }
Example #10
0
        static void TestAndNotLoop(bool oscillation)
        {
            Circuit c = new Circuit();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.And mand2 = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot  = new Gates.BasicGates.Not();
            mand2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mand2_PropertyChanged);
            mnot.PropertyChanged  += new System.ComponentModel.PropertyChangedEventHandler(mnot3_PropertyChanged);
            c.Add(mand);
            c.Add(mand2);
            c.Add(mnot);
            mand2[0] = true;


            c[new Terminal(1, mand2)] = new Terminal(0, mand);
            c[new Terminal(0, mnot)]  = new Terminal(0, mand2);
            if (oscillation)
            {
                c[new Terminal(0, mand)] = new Terminal(0, mnot);
            }

            Console.Out.WriteLine(mand2.Output[0].ToString());

            mand[1] = true;
            Console.Out.WriteLine(mand2.Output[0].ToString());

            mand[0] = true;
            Console.Out.WriteLine(mand2.Output[0].ToString());

            Console.Out.Write(mnot.Output[0].ToString());
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Console.Out.Write(mnot.Output[0].ToString());

            Console.Out.Write(mnot[0].ToString());

            Console.Out.Write("X");
        }
Example #11
0
 static void mand2_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     Gates.BasicGates.And mand2 = (Gates.BasicGates.And)sender;
     Console.Out.WriteLine("NOTIFY: " + mand2.Output[0].ToString());
 }