Ejemplo n.º 1
0
        public static bool TryParseSeries(string data, int bitWidth, out IList <SensorPoint> result)
        {
            result = null;
            Tracer.Assert(data != null);
            Tracer.Assert(0 < bitWidth && bitWidth <= 32);
            List <SensorPoint> list = new List <SensorPoint>();
            int lastTick            = -1;

            foreach (string item in data.Split(' '))
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    SensorPoint point;
                    if (!Sensor.TryParsePoint(item, bitWidth, out point) || point.Tick <= lastTick)
                    {
                        return(false);
                    }
                    lastTick = point.Tick;
                    list.Add(point);
                }
            }
            result = list;
            return(true);
        }
Ejemplo n.º 2
0
        public WireDisplayControl(Canvas canvas, Point point, Wire wire)
        {
            this.InitializeComponent();
            Panel.SetZIndex(this, int.MaxValue);
            Canvas.SetLeft(this, point.X - 3);
            Canvas.SetTop(this, point.Y - 3);
            canvas.Children.Add(this);
            this.UpdateLayout();

            if (this.CaptureMouse() && Mouse.LeftButton == MouseButtonState.Pressed)
            {
                this.editor = App.Mainframe.Editor;
                CircuitMap map = this.editor.CircuitRunner.VisibleMap;
                Tracer.Assert(wire.LogicalCircuit == map.Circuit);
                this.parameter    = map.StateIndexes(wire).ToArray();
                this.circuitState = this.editor.CircuitRunner.CircuitState;
                if (0 < this.parameter.Length && this.circuitState != null)
                {
                    this.state         = new State[this.parameter.Length];
                    this.bitWidth.Text = Properties.Resources.WireDisplayBitWidth(this.parameter.Length);

                    this.timer          = new DispatcherTimer(DispatcherPriority.Normal, App.Mainframe.Dispatcher);
                    this.timer.Tick    += TimerTick;
                    this.timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / (this.editor.IsMaximumSpeed ? 25 : Math.Min(25, this.editor.Frequency * 4)));
                }
                else
                {
                    this.bitWidth.Text      = Properties.Resources.WireDisplayDisconnected;
                    this.display.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                this.Cancel();
            }
        }
 public void Allocate(CircuitState circuitState)
 {
     Tracer.Assert(this.PrivateIndex == 0);
     if (this.TriStateGroup != null && 0 < this.TriStateGroup.Count)
     {
         if (this.StateIndex == 0)
         {
             this.StateIndex = circuitState.ReserveState();
             foreach (Result r in this.TriStateGroup)
             {
                 Tracer.Assert(r == this || r.StateIndex == 0);
                 r.StateIndex = this.StateIndex;
             }
         }
         this.PrivateIndex = circuitState.ReserveState();
         Tracer.Assert(0 < this.PrivateIndex);
     }
     else
     {
         Tracer.Assert(this.StateIndex == 0);
         this.StateIndex = circuitState.ReserveState();
     }
     Tracer.Assert(0 < this.StateIndex);
 }
        public SettingsDoubleCache(
            Settings settings,
            string key,
            double minimum,
            double maximum,
            double defaultValue,
            bool persistInteger
            )
        {
            Tracer.Assert(minimum <= maximum);
            this.settings = settings;
            this.key      = key;
            this.minimum  = minimum;
            this.maximum  = maximum;
            string text = this.settings[this.key];
            double value;

            if (string.IsNullOrEmpty(text) || !double.TryParse(text, out value))
            {
                value = defaultValue;
            }
            this.cache  = Math.Max(this.minimum, Math.Min(value, this.maximum));
            this.format = persistInteger ? "f0" : "g";
        }
Ejemplo n.º 5
0
 public static int NumberCellsFor(int addressBitWidth)
 {
     // GraphicsArray can have up to 22 address bits
     Tracer.Assert(0 < addressBitWidth && addressBitWidth <= 22);
     return(1 << addressBitWidth);
 }
Ejemplo n.º 6
0
 public static void UpdateWritePinName(Memory memory)
 {
     Tracer.Assert(memory.Writable);
     memory.WritePin.Name = Properties.Resources.MemoryWritePinName(memory.WriteOn1 ? Properties.Resources.WriteOn1 : Properties.Resources.WriteOn0);
 }
Ejemplo n.º 7
0
 protected override int CircuitSymbolWidth(int defaultWidth)
 {
     Tracer.Assert(defaultWidth == (this.Writable ? 2 : 1));
     return(3);
 }
Ejemplo n.º 8
0
 private void ValidateCircuitProject()
 {
     foreach (Circuit circuit in this.CircuitSet)
     {
         if (circuit is LogicalCircuit)
         {
             Tracer.Assert(this.LogicalCircuitSet.Table.Exists(LogicalCircuitData.LogicalCircuitIdField.Field, circuit.CircuitId));
         }
         else if (circuit is CircuitProbe)
         {
             Tracer.Assert(this.CircuitProbeSet.Table.Exists(CircuitProbeData.CircuitProbeIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is CircuitButton)
         {
             Tracer.Assert(this.CircuitButtonSet.Table.Exists(CircuitButtonData.CircuitButtonIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is Constant)
         {
             Tracer.Assert(this.ConstantSet.Table.Exists(ConstantData.ConstantIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is Sensor)
         {
             Tracer.Assert(this.SensorSet.Table.Exists(SensorData.SensorIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is DevicePin)
         {
             Tracer.Assert(this.DevicePinSet.Table.Exists(DevicePinData.PinIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 0);
         }
         else if (circuit is Gate)
         {
             Tracer.Assert(this.GateSet.Table.Exists(GateData.GateIdField.Field, circuit.CircuitId));
         }
         else if (circuit is Memory)
         {
             Tracer.Assert(this.MemorySet.Table.Exists(MemoryData.MemoryIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is LedMatrix)
         {
             Tracer.Assert(this.LedMatrixSet.Table.Exists(LedMatrixData.LedMatrixIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is Pin)
         {
             Tracer.Assert(this.PinSet.Table.Exists(PinData.PinIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
             Pin pin = (Pin)circuit;
             Tracer.Assert(pin.LogicalCircuit == this.CircuitSymbolSet.SelectByCircuit(circuit).First().LogicalCircuit);
         }
         else if (circuit is Splitter)
         {
             Tracer.Assert(this.SplitterSet.Table.Exists(SplitterData.SplitterIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is Sound)
         {
             Tracer.Assert(this.SoundSet.Table.Exists(SoundData.SoundIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
         else if (circuit is GraphicsArray)
         {
             Tracer.Assert(this.GraphicsArraySet.Table.Exists(GraphicsArrayData.GraphicsArrayIdField.Field, circuit.CircuitId));
             Tracer.Assert(this.CircuitSymbolSet.SelectByCircuit(circuit).Count() == 1);
         }
     }
     foreach (LedMatrix ledMatrix in this.LedMatrixSet)
     {
         int count = this.DevicePinSet.SelectByCircuit(ledMatrix).Count();
         if (ledMatrix.MatrixType == LedMatrixType.Individual)
         {
             Tracer.Assert(ledMatrix.Rows == count);
         }
         else
         {
             Tracer.Assert((ledMatrix.Rows + ledMatrix.Columns) == count);
         }
     }
     foreach (Wire wire in this.WireSet)
     {
         Tracer.Assert(wire.Point1 != wire.Point2);
     }
     //TODO: Add check of many wires hidden by each other.
 }
Ejemplo n.º 9
0
 public FunctionConstant(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
 {
     this.CircuitSymbol = symbol;
     Tracer.Assert(this.BitWidth == result.Length);
 }
Ejemplo n.º 10
0
 public static EnumDescriptor <PinSide> PinSideDescriptor(PinSide pinSide)
 {
     Tracer.Assert(EnumHelper.IsValid(pinSide));
     return(PinDescriptor.PinSideRange.First(d => d.Value == pinSide));
 }
Ejemplo n.º 11
0
        private Gate Create(GateType gateType, int inputCount, bool invertedOutput)
        {
            Gate gate = this.CreateItem(GateSet.GateGuid(gateType, inputCount, invertedOutput));

            gate.GateType       = gateType;
            gate.InvertedOutput = invertedOutput;
            switch (gate.GateType)
            {
            case GateType.Clock:
                gate.Name     = Properties.Resources.GateClockName;
                gate.Notation = Properties.Resources.GateClockNotation;
                gate.Category = Properties.Resources.CategoryInputOutput;
                break;

            case GateType.Not:
                gate.Name     = Properties.Resources.GateNotName;
                gate.Notation = Properties.Resources.GateNotNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Or:
                gate.Name     = invertedOutput ? Properties.Resources.GateOrNotName : Properties.Resources.GateOrName;
                gate.Notation = Properties.Resources.GateOrNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.And:
                gate.Name     = invertedOutput ? Properties.Resources.GateAndNotName : Properties.Resources.GateAndName;
                gate.Notation = Properties.Resources.GateAndNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Xor:
                gate.Name     = invertedOutput ? Properties.Resources.GateXorNotName : Properties.Resources.GateXorName;
                gate.Notation = Properties.Resources.GateXorNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Led:
                Tracer.Assert(inputCount == 1 || inputCount == 8);
                gate.Name     = (inputCount == 1) ? Properties.Resources.GateLedName : Properties.Resources.Gate7SegName;
                gate.Notation = Properties.Resources.GateLedNotation;
                gate.Category = Properties.Resources.CategoryInputOutput;
                break;

            case GateType.TriState1:
            case GateType.TriState2:
                gate.Name     = Properties.Resources.GateTriStateName;
                gate.Notation = Properties.Resources.GateTriStateNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
            default:
                Tracer.Fail();
                break;
            }
            if (gate.GateType == GateType.TriState1 || gate.GateType == GateType.TriState2)
            {
                this.GenerateTriStatePins(gate);
            }
            else if (gate.GateType == GateType.Led && inputCount == 8)
            {
                this.GenerateSevenSegmentIndicatorPins(gate);
            }
            else
            {
                this.GeneratePins(gate, inputCount, invertedOutput);
            }
            return(gate);
        }
Ejemplo n.º 12
0
 private static bool HasOutput(GateType gateType)
 {
     Tracer.Assert(GateSet.IsValid(gateType));
     return(gateType != GateType.Nop && gateType != GateType.Led);
 }
Ejemplo n.º 13
0
 public virtual FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     throw new InvalidOperationException();
 }
Ejemplo n.º 14
0
 public FunctionAndNot2(CircuitState circuitState, int[] parameter, int result) : base(circuitState, parameter, result)
 {
     Tracer.Assert(parameter.Length == 2);
     this.param0 = parameter[0];
     this.param1 = parameter[1];
 }
Ejemplo n.º 15
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateSimpleGlyph(SymbolShape.Sound, symbol));
 }
Ejemplo n.º 16
0
 public void MarkConnected(LogicalCircuit logicalCircuit)
 {
     Tracer.Assert(!this.IsConnected(logicalCircuit));
     this.connected.Add(logicalCircuit);
 }
Ejemplo n.º 17
0
 public static EnumDescriptor <LedMatrixType> LedMatrixTypeDescriptor(LedMatrixType ledMatrixType)
 {
     Tracer.Assert(EnumHelper.IsValid(ledMatrixType));
     return(LedMatrixDescriptor.MatrixTypes.First(d => d.Value == ledMatrixType));
 }
Ejemplo n.º 18
0
        public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
        {
            Tracer.Assert(this == symbol.Circuit);
            string skin;

            switch (this.GateType)
            {
            case GateType.Clock:
                skin = SymbolShape.Clock;
                break;

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
                Tracer.Fail();
                return(null);

            case GateType.Led:
                if (this.InputCount == 1)
                {
                    skin = SymbolShape.Led;
                }
                else
                {
                    Tracer.Assert(this.InputCount == 8);
                    skin = SymbolShape.SevenSegment;
                }
                break;

            default:
                if (Settings.User.GateShape == GateShape.Rectangular)
                {
                    return(symbol.CreateRectangularGlyph());
                }
                else
                {
                    switch (this.GateType)
                    {
                    case GateType.Not:
                        skin = SymbolShape.ShapedNot;
                        break;

                    case GateType.Or:
                        skin = SymbolShape.ShapedOr;
                        break;

                    case GateType.And:
                        skin = SymbolShape.ShapedAnd;
                        break;

                    case GateType.Xor:
                        skin = SymbolShape.ShapedXor;
                        break;

                    case GateType.TriState1:
                        skin = SymbolShape.ShapedTriState1;
                        break;

                    case GateType.TriState2:
                        skin = SymbolShape.ShapedTriState2;
                        break;

                    default:
                        Tracer.Fail();
                        return(null);
                    }
                    return(symbol.CreateShapedGlyph(skin));
                }
            }
            return(symbol.CreateSimpleGlyph(skin, symbol));
        }
Ejemplo n.º 19
0
 public DirectionDescriptor(bool clockwise, string text, int flip) : base(clockwise, text)
 {
     Tracer.Assert(flip == 1 || flip == -1);
     this.Flip = flip;
 }
Ejemplo n.º 20
0
            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]);
            }
Ejemplo n.º 21
0
 public void Read(int bitNumber, State[] state)
 {
     Tracer.Assert(state.Length == this.tickHistory[bitNumber].Capacity);
     this.tickHistory[bitNumber].GetState(state);
 }
Ejemplo n.º 22
0
 public JamItem(BasePin pin, CircuitGlyph symbol)
 {
     Tracer.Assert(pin.Circuit == symbol.Circuit);
     this.Pin           = pin;
     this.CircuitSymbol = symbol;
 }
Ejemplo n.º 23
0
 public void SetMemoryValue(byte[] value)
 {
     Tracer.Assert(value == null || value.Length == this.BytesPerCell * this.TotalCells);
     this.Data = (value != null) ? Convert.ToBase64String(value, Base64FormattingOptions.InsertLineBreaks) : string.Empty;
 }
Ejemplo n.º 24
0
 public LogicalJamItem(BasePin pin, CircuitGlyph symbol, Jam innerJam) : base(pin, symbol)
 {
     Tracer.Assert(innerJam != null && innerJam.CircuitSymbol.LogicalCircuit == symbol.Circuit);
     this.innerJam = innerJam;
 }
Ejemplo n.º 25
0
 protected override int CircuitSymbolHeight(int defaultHeight)
 {
     Tracer.Assert(defaultHeight == ((this.Writable ? 3 : 2) + (this.DualPort ? 1 : 0)));
     return(Math.Max(4, defaultHeight));
 }
Ejemplo n.º 26
0
 public void Edit(Project project)
 {
     Tracer.Assert(project == this.Project);
     this.Mainframe.ShowDialog(new DialogProject(project));
 }
Ejemplo n.º 27
0
 public static int BytesPerCellFor(int dataBitWidth)
 {
     Tracer.Assert(0 < dataBitWidth && dataBitWidth <= Pin.MaxBitWidth);
     return(dataBitWidth / 8 + (((dataBitWidth % 8) == 0) ? 0 : 1));
 }
            private void Build(Action <double> reportProgress, Func <bool> keepGoing, Predicate <TruthState> include, int maxCount)
            {
                this.Results     = new List <TruthState>();
                this.Oscillation = false;
                this.Trancated   = false;
                int inputCount  = this.Inputs.Count;
                int outputCount = this.Outputs.Count;

                if (0 < inputCount && 0 < outputCount)
                {
                    BigInteger end        = this.Start + this.Count;
                    BigInteger onePercent = this.Count / 100;
                    BigInteger count      = 0;
                    double     progress   = 0;

                    TruthState state = new TruthState(inputCount, outputCount);
                    for (BigInteger value = this.Start; value < end; value++)
                    {
                        if (maxCount <= this.Results.Count || !keepGoing())
                        {
                            this.Trancated = true;
                            break;
                        }
                        int bit = 0;
                        for (int i = this.Inputs.Count - 1; 0 <= i; i--)
                        {
                            InputPinSocket pin = this.Inputs[i];
                            int            v   = (int)((value >> bit) & int.MaxValue) & (pin.Pin.BitWidth < 32 ? (1 << pin.Pin.BitWidth) - 1 : ~0);
                            pin.Function.Value = v;
                            Tracer.Assert(pin.Function.Value == v, "Value get truncated");
                            bit += pin.Pin.BitWidth;
                        }
                        if (!this.CircuitState.Evaluate(true))
                        {
                            this.Oscillation = true;
                            break;
                        }
                        for (int i = 0; i < inputCount; i++)
                        {
                            state.Input[i] = this.Inputs[i].Function.Value;
                        }
                        for (int i = 0; i < outputCount; i++)
                        {
                            state.Result[i] = this.Outputs[i].Function.Pack();
                        }
                        if (!state.Unpack(this.Outputs.Select(o => o.Function.ParameterCount).ToArray()) || include == null || include(state))
                        {
                            this.Results.Add(state);
                            state = new TruthState(inputCount, outputCount);
                        }
                        if (reportProgress != null)
                        {
                            count++;
                            if (onePercent < count)
                            {
                                count = 0;
                                if (onePercent == BigInteger.Zero)
                                {
                                    Tracer.Assert(0 < this.Count && this.Count < 100);
                                    reportProgress((double)((value + 1 - this.Start) * 100) / (double)this.Count);
                                }
                                else
                                {
                                    reportProgress(Math.Min(++progress, 100));
                                }
                            }
                        }
                    }
                }
            }
Ejemplo n.º 29
0
 public static void AssertAddressBitWidth(int addressBitWidth)
 {
     Tracer.Assert(0 < addressBitWidth && addressBitWidth <= Memory.MaxAddressBitWidth);
 }
Ejemplo n.º 30
0
 protected SensorValue(int bitWidth)
 {
     Tracer.Assert(0 < bitWidth && bitWidth <= 32);
     this.BitWidth = bitWidth;
 }