Exemple #1
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     Tracer.Assert(targetType == typeof(bool));
     return(!(bool)value);
 }
Exemple #2
0
 public JamKey(Jam jam, int bitNumber)
 {
     Tracer.Assert(jam.IsValid(bitNumber));
     this.Jam       = jam;
     this.BitNumber = bitNumber;
 }
Exemple #3
0
 public EnumDescriptor(T value, string text)
 {
     Tracer.Assert(!(value is Enum) || EnumHelper.IsValid(value));
     this.Value = value;
     this.Text  = text;
 }
Exemple #4
0
 public int Compare(Result x, Result y)
 {
     Tracer.Assert(x.CircuitMap == y.CircuitMap && x.Jam == y.Jam);
     return(x.BitNumber - y.BitNumber);
 }
Exemple #5
0
 public Parameter(Result result, CircuitMap circuitMap, Jam jam, int bitNumber) : base(circuitMap, jam, bitNumber)
 {
     Tracer.Assert(jam.Pin.PinType == PinType.Input);
     this.Result = result;
 }
Exemple #6
0
 public override FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateButtonGlyph(mainSymbol));
 }
            public CircuitFunction Get()
            {
                int random;
                int count = this.current.Count;

                if (count <= this.index)
                {
                    count = this.next.Count;
                    if (count <= 0)
                    {
                        return(null);
                    }

                                        #if VALIDATE_GET_FUNCTION
                    Tracer.Assert(this.functionCount == this.functionIndex.Count);
                    Tracer.Assert(this.functionCount == 0 || (this.functionIndex.Contains(0) && this.functionIndex.Contains(this.functionCount - 1)));
                    this.functionCount = count;
                    this.functionIndex.Clear();
                                        #endif

                    this.iteration++;
                    this.current.Clear();
                    FunctionList temp = this.next;
                    this.next    = this.current;
                    this.current = temp;

                    this.index = 1;

                    // This expression for step will allow to iterate for this.index from 0 to this.current.Count - 1 and walk through each element
                    // of this.current exactly once because int.MaxValue is prime number
                    this.step = int.MaxValue % count;

                    // simple but fast random number generator
                    this.seed = 214013 * this.seed + 2531011;

                    // this will just make sure: 0 <= random < count
                    random      = (int.MaxValue & this.seed) % count;
                    this.offset = random;

                    if (0 < this.Delay && 1 < count)
                    {
                        int max = Math.Min(this.Delay, count - 1);
                        for (int i = 0; i < max; i++)
                        {
                            this.Add(this.Get());
                        }
                    }
                                        #if REPORT_STAT
                    this.ReportStat(this.current.Count);
                                        #endif
                }
                else
                {
                    this.index++;
                    random = this.offset - this.step;
                    if (random < 0)
                    {
                        random += count;
                    }
                    this.offset = random;
                }

                                #if VALIDATE_GET_FUNCTION
                Tracer.Assert(0 <= random && random < this.functionCount && this.functionIndex.Add(random));
                                #endif

                return(this.current[random]);
            }
        private void Run()
        {
            PropertyChangedEventHandler editorPropertyChanged = null;

            try {
                this.running = true;
                this.Editor.Mainframe.Status = Properties.Resources.PowerOn;

                this.CircuitState = this.RootMap.Apply(CircuitRunner.HistorySize);
                this.CircuitState.FunctionUpdated += new EventHandler(this.OnFunctionUpdated);
                this.HasProbes = this.CircuitState.HasProbes;

                this.Editor.Mainframe.Dispatcher.Invoke(new Action(() => this.RootMap.TurnOn()));
                this.Editor.ActualFrequency = this.Editor.Frequency;

                if (this.Oscilloscoping && this.CircuitState.HasProbes)
                {
                    Tracer.Assert(this.DialogOscilloscope == null);
                    this.Editor.Mainframe.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(this.ShowOscilloscope));
                }
                else
                {
                    this.Oscilloscoping = false;
                }

                this.refreshingThread = new Thread(new ThreadStart(this.MonitorUI))
                {
                    IsBackground = true,
                    Name         = "RefreshingThread",
                    Priority     = ThreadPriority.BelowNormal
                };


                using (this.evaluationGate = new AutoResetEvent(false)) {
                    using (this.refreshingGate = new AutoResetEvent(false)) {
                        using (PreciseTimer timer = new PreciseTimer(this.TimerTick, CircuitRunner.HalfPeriod(this.Editor.Project.Frequency))) {
                            editorPropertyChanged = new PropertyChangedEventHandler((s, e) => {
                                switch (e.PropertyName)
                                {
                                case "Frequency":
                                    timer.Period = CircuitRunner.HalfPeriod(this.Editor.Project.Frequency);
                                    break;

                                case "IsMaximumSpeed":
                                    this.isMaxSpeed = this.Editor.Project.IsMaximumSpeed;
                                    if (this.isMaxSpeed)
                                    {
                                        AutoResetEvent resetEvent = this.evaluationGate;
                                        if (resetEvent != null)
                                        {
                                            resetEvent.Set();
                                        }
                                    }
                                    break;
                                }
                            });
                            this.Editor.PropertyChanged += editorPropertyChanged;
                            this.refreshingThread.Start();
                            this.flipCount = 1;
                            timer.Start();
                            this.RunCircuit();
                        }
                    }
                }
            } catch (ThreadAbortException) {
                // Do nothing
            } catch (Exception exception) {
                this.Editor.Mainframe.ReportException(exception);
            } finally {
                this.running = false;
                if (this.refreshingThread != null)
                {
                    this.refreshingThread.Abort();
                }
                if (editorPropertyChanged != null)
                {
                    this.Editor.PropertyChanged -= editorPropertyChanged;
                }
                if (this.DialogOscilloscope != null)
                {
                    this.DialogOscilloscope.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                                   new Action(this.DialogOscilloscope.Close)
                                                                   );
                }
                if (this.RootMap != null)
                {
                    while (this.updatingUI)
                    {
                        ;
                    }
                    this.Editor.Mainframe.Dispatcher.BeginInvoke(
                        new Action(() => this.RootMap.Circuit.CircuitProject.InTransaction(() => this.RootMap.TurnOff())),
                        DispatcherPriority.ApplicationIdle
                        );
                }
                this.Editor.Mainframe.Status = Properties.Resources.PowerOff;
            }
        }