예제 #1
0
        public static string ToText(IEnumerable <State> probeState, bool showFormatPrefix)
        {
            int value = 0;
            int count = 0;

            foreach (State state in probeState)
            {
                Tracer.Assert(count < 32);
                switch (state)
                {
                case State.Off:
                    return(CircuitFunction.Binary(probeState));

                case State.On0:
                    break;

                case State.On1:
                    value |= 1 << count;
                    break;

                default:
                    Tracer.Fail();
                    break;
                }
                count++;
            }
            if (showFormatPrefix && 1 < count)
            {
                return(string.Format(CultureInfo.InvariantCulture, "0x{0:X}", value));
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0:X}", value));
            }
        }
예제 #2
0
 public void Add(CircuitFunction function)
 {
     if (function.Iteration < this.iteration)
     {
         function.Iteration = this.iteration;
         this.next.Add(function);
     }
 }
예제 #3
0
 public void Add(CircuitFunction f)
 {
     if (this.list.Length <= this.Count)
     {
         Array.Resize(ref this.list, this.list.Length * 2);
     }
     this.list[this.Count++].CircuitFunction = f;
 }
예제 #4
0
        protected bool IsWriteAllowed()
        {
            State state   = this.CircuitState[this.write];
            bool  allowed = (state == this.writeOn && CircuitFunction.Not(state) == this.oldWriteState);

            this.oldWriteState = state;
            return(allowed);
        }
		private void TimerTick(object sender, EventArgs e) {
			if(!this.editor.InEditMode) {
				if(this.WasChanged()) {
					this.display.Text = Properties.Resources.WireDisplayValue(CircuitFunction.ToText(this.state, true));
				}
			} else {
				this.Cancel();
			}
		}
예제 #6
0
        /// <summary>
        /// Sets multi-bit result from the 32 bit parameter
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        protected bool SetResult(int state)
        {
            bool changed = false;

            for (int i = 0; i < this.result.Length; i++)
            {
                changed |= this.SetResult(i, CircuitFunction.FromBool((state & (1 << i)) != 0));
            }
            return(changed);
        }
예제 #7
0
        public override string ToString()
        {
            StringBuilder text = new StringBuilder();

            foreach (State s in this.state)
            {
                text.Append(CircuitFunction.ToChar(s));
            }
            return(text.ToString());
        }
예제 #8
0
        private static string Binary(IEnumerable <State> probeState)
        {
            char[] text  = new char[32];
            int    index = 0;

            foreach (State state in probeState)
            {
                text[index++] = CircuitFunction.ToChar(state);
            }
            Array.Reverse(text, 0, index);
            return(new string(text, 0, index));
        }
예제 #9
0
        public void MarkUpdated(CircuitFunction function)
        {
            bool wasUpdated;

            lock (this.updated) {
                wasUpdated = this.updated.Add(function);
            }
            if (wasUpdated && this.FunctionUpdated != null)
            {
                this.FunctionUpdated(this, EventArgs.Empty);
            }
        }
 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));
     }
 }
예제 #11
0
        protected static State Not(State state)
        {
            switch (state)
            {
            case State.Off:
                return(State.On0);

            case State.On0:
                return(State.On1);

            case State.On1:
                return(State.On0);
            }
            throw CircuitFunction.BadState(state);
        }
예제 #12
0
        private string ShowParam(CircuitFunction f)
        {
            StringBuilder text = new StringBuilder();

            text.Append(' ', this.Count);
            foreach (int p in f.Parameter)
            {
                text[p] = '^';
            }
            foreach (int r in f.Result)
            {
                text[r] = 'v';
            }
            return(text.ToString());
        }
예제 #13
0
        public static char ToChar(State state)
        {
            // The chars are hardcoded if needed must be localized.
            switch (state)
            {
            case State.Off:
                return('-');

            case State.On0:
                return('0');

            case State.On1:
                return('1');

            default:
                throw CircuitFunction.BadState(state);
            }
        }
예제 #14
0
 private void StateChangedAction(CircuitSymbol symbol, bool isPressed)
 {
     if (isPressed)
     {
         if (this.isToggle)
         {
             this.SetState(CircuitFunction.Not(this.State));
             this.Invalid = true;
         }
         else
         {
             this.SetState(State.On1);
         }
     }
     else if (!this.isToggle)
     {
         this.SetState(State.On0);
     }
 }
예제 #15
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);
            }
        }
        private void RefreshHistory()
        {
            List <string> list  = new List <string>();
            int           width = this.functionProbe.BitWidth;

            this.reads = this.functionProbe.Read();
            Array.Reverse(this.reads);
            foreach (long pack in this.reads)
            {
                if (pack == -1L)
                {
                    list.Add(Properties.Resources.ProbeHistoryMark);
                }
                else
                {
                    list.Add(CircuitFunction.ToText(this.Unpack(pack, width), false));
                }
            }
            this.History = list;
        }
예제 #17
0
        protected bool Read()
        {
            int state = Memory.CellValue(this.data, this.DataBitWidth, this.ReadNumericState(this.address));

            if (this.address2 == null)
            {
                return(this.SetResult(state));
            }
            else
            {
                bool changed = false;
                for (int i = 0; i < this.outputData.Length; i++)
                {
                    changed |= this.SetResult(i, CircuitFunction.FromBool((state & (1 << i)) != 0));
                }
                state = Memory.CellValue(this.data, this.DataBitWidth, this.ReadNumericState(this.address2));
                for (int i = 0; i < this.outputData2.Length; i++)
                {
                    changed |= this.SetResult(i + this.outputData.Length, CircuitFunction.FromBool((state & (1 << i)) != 0));
                }
                return(changed);
            }
        }
예제 #18
0
        protected State TriStateGroup()
        {
            State state = State.Off;

            foreach (int index in this.parameter)
            {
                switch (this.CircuitState[index])
                {
                case State.On0:
                    return(State.On0);

                case State.On1:
                    state = State.On1;
                    break;

                case State.Off:
                    break;

                default:
                    throw CircuitFunction.BadState(this.CircuitState[index]);
                }
            }
            return(state);
        }
예제 #19
0
 public override bool Evaluate()
 {
     return(this.SetResult0(CircuitFunction.FromBool((this.Count(State.On1) & 1) == 1)));
 }
예제 #20
0
 public override bool Evaluate()
 {
     return(this.SetResult0(CircuitFunction.Not(this.CircuitState[this.param0])));
 }
예제 #21
0
 public string ToText()
 {
     return(CircuitFunction.ToText(this.state, false));
 }
예제 #22
0
 public override bool Evaluate()
 {
     return(this.SetResult0(CircuitFunction.FromBool(this.state)));
 }
예제 #23
0
 public override bool Evaluate()
 {
     return(this.SetResult0(CircuitFunction.Not(this.And())));
 }