コード例 #1
0
ファイル: CircuitTester.cs プロジェクト: bloeys/LogicCircuit
        public int GetOutput(string outputName)
        {
            this.ValidateEditor();
            if (string.IsNullOrEmpty(outputName))
            {
                throw new ArgumentNullException(nameof(outputName));
            }
            OutputPinSocket pin = this.socket.Outputs.FirstOrDefault(o => o.Pin.Name == outputName);

            if (pin == null)
            {
                throw new CircuitException(Cause.UserError,
                                           string.Format(CultureInfo.InvariantCulture, "Output pin {0} not found on Logical Circuit {1}", outputName, this.logicalCircuitName)
                                           );
            }
            int value;

            if (FunctionProbe.ToInt(pin.Function.Pack(), pin.Pin.BitWidth, out value))
            {
                return(value);
            }
            throw new CircuitException(Cause.UserError,
                                       string.Format(CultureInfo.InvariantCulture,
                                                     "Output value cannot be represented by number because it contains bit(s) in high impedance state: {0}. Use GetStateOutput instead.",
                                                     pin.Function.ToText()
                                                     )
                                       );
        }
コード例 #2
0
 public DialogProbeHistory(FunctionProbe functionProbe)
 {
     this.functionProbe = functionProbe;
     this.BitWidth      = this.functionProbe.BitWidth;
     this.RefreshHistory();
     this.DataContext = this;
     this.InitializeComponent();
 }
コード例 #3
0
 public string this[int index] {
     get {
         if (this.output != null)
         {
             return(this.output[index].ToString("X", CultureInfo.InvariantCulture));
         }
         if (FunctionProbe.ToInt(this.result[index], bitWidth[index], out int unpacked))
         {
             return(unpacked.ToString("X", CultureInfo.InvariantCulture));
         }
         long res = this.result[index];
         return(CircuitFunction.ToText(Enumerable.Range(0, this.bitWidth[index]).Select(i => (State)((res >> i * 2) & 0x3)), false));
     }
 }
コード例 #4
0
 public bool Unpack(int[] bitWidthList)
 {
     Tracer.Assert(bitWidthList.Length == this.result.Length);
     this.bitWidth = bitWidthList;
     int[] res = new int[this.result.Length];
     for (int i = 0; i < res.Length; i++)
     {
         int unpacked;
         if (!FunctionProbe.ToInt(this.result[i], this.bitWidth[i], out unpacked))
         {
             return(false);
         }
         res[i] = unpacked;
     }
     this.output = res;
     return(true);
 }
コード例 #5
0
 public void Read(FunctionProbe probe)
 {
     if (probe.BitWidth == 1)
     {
         probe.Read(0, this.history[probe.Label]);
     }
     else
     {
         List <string> list;
         this.probeLabels.TryGetValue(probe.Label, out list);
         Tracer.Assert(list != null && list.Count == probe.BitWidth);
         for (int i = 0; i < probe.BitWidth; i++)
         {
             probe.Read(i, this.history[list[i]]);
         }
     }
 }
コード例 #6
0
        public void DefineFunction(CircuitFunction function)
        {
            if (this.state == null)
            {
                this.state     = new State[this.Count];
                this.dependent = new List <CircuitFunction> [this.Count];
                for (int i = 0; i < this.dependent.Length; i++)
                {
                    this.dependent[i] = new List <CircuitFunction>();
                }
            }
            this.functions.Add(function);
            if (function is IFunctionClock)
            {
                this.clockList.Add(function);
            }
            int count = 0;

            foreach (int parameter in function.Parameter)
            {
                this.dependent[parameter].Add(function);
                count++;
            }
            if (count <= 0)
            {
                this.dirty.Add(function);
            }
            else
            {
                FunctionProbe probe = function as FunctionProbe;
                if (probe != null)
                {
                    this.probeList.Add(probe);
                }
            }
            FunctionTriStateGroup group = function as FunctionTriStateGroup;

            if (group != null)
            {
                this.triStateGroupList.Add(group);
            }
        }
コード例 #7
0
        protected override void Edit(Symbol symbol)
        {
            CircuitSymbol circuitSymbol = symbol as CircuitSymbol;

            if (circuitSymbol != null)
            {
                if (this.InEditMode)
                {
                    LogicalCircuit lc = circuitSymbol.Circuit as LogicalCircuit;
                    if (lc != null)
                    {
                        this.OpenLogicalCircuit(lc);
                        return;
                    }
                    CircuitProbe cp = circuitSymbol.Circuit as CircuitProbe;
                    if (cp != null)
                    {
                        this.Edit(cp);
                        return;
                    }
                    CircuitButton cb = circuitSymbol.Circuit as CircuitButton;
                    if (cb != null)
                    {
                        this.Edit(cb);
                        return;
                    }
                    Constant ct = circuitSymbol.Circuit as Constant;
                    if (ct != null)
                    {
                        this.Edit(ct);
                        return;
                    }
                    Sensor sr = circuitSymbol.Circuit as Sensor;
                    if (sr != null)
                    {
                        this.Edit(sr);
                        return;
                    }
                    Memory m = circuitSymbol.Circuit as Memory;
                    if (m != null)
                    {
                        this.Edit(m);
                        return;
                    }
                    Pin pin = circuitSymbol.Circuit as Pin;
                    if (pin != null)
                    {
                        this.Edit(pin);
                        return;
                    }
                    LedMatrix ledMatrix = circuitSymbol.Circuit as LedMatrix;
                    if (ledMatrix != null)
                    {
                        this.Edit(ledMatrix);
                        return;
                    }
                    Sound sound = circuitSymbol.Circuit as Sound;
                    if (sound != null)
                    {
                        this.Edit(sound);
                        return;
                    }
                    GraphicsArray graphicsArray = circuitSymbol.Circuit as GraphicsArray;
                    if (graphicsArray != null)
                    {
                        this.Edit(graphicsArray);
                        return;
                    }
                }
                else if (this.CircuitRunner != null && this.CircuitRunner.VisibleMap != null)
                {
                    CircuitMap map = this.CircuitRunner.VisibleMap.Child(circuitSymbol);
                    if (map != null)
                    {
                        this.OpenLogicalCircuit(map);
                        return;
                    }
                    if (circuitSymbol.Circuit is CircuitProbe)
                    {
                        FunctionProbe functionProbe = this.CircuitRunner.VisibleMap.FunctionProbe(circuitSymbol);
                        if (functionProbe != null)
                        {
                            this.Mainframe.ShowDialog(new DialogProbeHistory(functionProbe));
                        }
                        return;
                    }
                    if ((circuitSymbol.Circuit is Memory) || (circuitSymbol.Circuit is GraphicsArray))
                    {
                        IFunctionMemory functionMemory = this.CircuitRunner.VisibleMap.FunctionMemory(circuitSymbol);
                        if (functionMemory != null)
                        {
                            this.Mainframe.ShowDialog(new DialogMemory(functionMemory));
                        }
                        return;
                    }
                    if (circuitSymbol.Circuit is Constant)
                    {
                        if (this.CircuitRunner.Root.First() == this.CircuitRunner.VisibleMap)
                        {
                            FunctionConstant functionConstant = this.CircuitRunner.VisibleMap.FunctionConstant(circuitSymbol);
                            if (functionConstant != null)
                            {
                                this.CircuitProject.InOmitTransaction(() => functionConstant.Value++);
                            }
                        }
                        else
                        {
                            this.Mainframe.Status = Properties.Resources.MessageNotRootConstant(this.CircuitRunner.Root.First().Circuit.Name);
                        }
                    }
                }
            }
            else if (this.InEditMode)
            {
                TextNote textNote = symbol as TextNote;
                if (textNote != null)
                {
                    this.Edit(textNote);
                }
            }
        }