Beispiel #1
0
 protected FunctionLedMatrix(CircuitState circuitState, IEnumerable <CircuitSymbol> symbols, int[] parameter) : base(circuitState, parameter)
 {
     this.circuitSymbol = symbols.ToList();
     this.Matrix        = (LedMatrix)this.circuitSymbol[0].Circuit;
     this.BitPerLed     = this.Matrix.Colors;
     this.project       = this.circuitSymbol[0].LogicalCircuit.CircuitProject.ProjectSet.Project;
 }
        private void ReportFunctions(LogicalCircuit root)
        {
            try {
                CircuitMap               map   = new CircuitMap(root);
                CircuitState             state = map.Apply(1);
                Dictionary <string, int> func  = new Dictionary <string, int>();
                foreach (CircuitFunction f in state.Functions)
                {
                    string name = f.ReportName;
                    if (func.ContainsKey(name))
                    {
                        func[name]++;
                    }
                    else
                    {
                        func.Add(name, 1);
                    }
                }

                this.Functions = new List <string>(func.Keys);
                this.Functions.Sort(StringComparer.Ordinal);
                this.Usage = func;
            } catch (Exception exception) {
                this.BuildMapException = exception;
            }
        }
		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 FunctionAndNot3(CircuitState circuitState, int[] parameter, int result) : base(circuitState, parameter, result)
 {
     Tracer.Assert(parameter.Length == 3);
     this.param0 = parameter[0];
     this.param1 = parameter[1];
     this.param2 = parameter[2];
 }
Beispiel #5
0
        public FunctionSensor(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
        {
            this.CircuitSymbol = symbol;
            Tracer.Assert(this.BitWidth == result.Length);
            switch (this.Sensor.SensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                this.sensorValue = new SeriesValue(this.Sensor.Data, this.Sensor.SensorType == SensorType.Loop, this.Sensor.BitWidth);
                break;

            case SensorType.Random:
                this.sensorValue = new RandomValue(this.Sensor.Data, this.Sensor.BitWidth, this.CircuitState.Random);
                break;

            case SensorType.Manual:
                this.sensorValue = new ManualValue(this.Sensor.Data, this.Sensor.BitWidth);
                break;

            default:
                Tracer.Fail();
                this.sensorValue = null;
                break;
            }
        }
        public FunctionGraphicsArray(
            CircuitState circuitState,
            int[] address,
            int[] inputData,
            int[] outputData,
            int write,
            IEnumerable <CircuitSymbol> symbols
            ) : base(circuitState, FunctionMemory.Input(address, null, inputData, write), outputData)
        {
            this.circuitSymbol = symbols.ToList();
            Tracer.Assert(0 < this.circuitSymbol.Count);

            GraphicsArray graphicsArray = (GraphicsArray)this.circuitSymbol[0].Circuit;

            this.project = graphicsArray.CircuitProject.ProjectSet.Project;

            this.address   = address;
            this.inputData = inputData;
            this.write     = write;
            this.writeOn   = graphicsArray.WriteOn1 ? State.On1 : State.On0;

            Tracer.Assert(this.inputData.Length == outputData.Length && this.inputData.Length == graphicsArray.DataBitWidth);

            this.bitsPerPixel = graphicsArray.BitsPerPixel;
            this.drawingRect  = new Int32Rect(0, 0, graphicsArray.Width, graphicsArray.Height);

            int w = this.drawingRect.Width * this.bitsPerPixel;

            this.memoryStride = w / this.DataBitWidth + (((w % this.DataBitWidth) == 0) ? 0 : 1);
            int byteStride = w / 8 + (((w % 8) == 0) ? 0 : 1);

            this.bitmapStride = Math.Max(byteStride * 8, this.memoryStride * this.DataBitWidth) / 8;
            Tracer.Assert(this.memoryStride * this.DataBitWidth <= this.bitmapStride * 8);
            this.zoom = graphicsArray.Zoom;

            switch (graphicsArray.OnStart)
            {
            case MemoryOnStart.Random:
                this.data = this.Allocate();
                circuitState.Random.NextBytes(this.data);
                break;

            case MemoryOnStart.Zeros:
                this.data = this.Allocate();
                break;

            case MemoryOnStart.Ones:
                this.data = this.Allocate();
                for (int i = 0; i < this.data.Length; i++)
                {
                    this.data[i] = 0xFF;
                }
                break;

            case MemoryOnStart.Data:
            default:
                Tracer.Fail();
                break;
            }
        }
Beispiel #7
0
 protected CircuitFunction(CircuitState circuitState, int[] parameter, int[] result)
 {
     this.CircuitState = circuitState;
     this.parameter    = parameter ?? CircuitFunction.EmptyList;
     this.result       = result ?? CircuitFunction.EmptyList;
     this.result0      = (0 < this.result.Length) ? this.result[0] : -1;
     this.CircuitState.DefineFunction(this);
 }
Beispiel #8
0
 protected CircuitFunction(CircuitState circuitState, int[] parameter, int[] result)
 {
     this.CircuitState = circuitState;
     this.parameter    = (parameter == null) ? CircuitFunction.EmptyList : parameter;
     this.result       = (result == null) ? CircuitFunction.EmptyList : result;
     this.result0      = (0 < this.result.Length) ? this.result[0] : -1;
     this.CircuitState.DefineFunction(this);
 }
 public FunctionOrNot5(CircuitState circuitState, int[] parameter, int result) : base(circuitState, parameter, result)
 {
     Tracer.Assert(parameter.Length == 5);
     this.param0 = parameter[0];
     this.param1 = parameter[1];
     this.param2 = parameter[2];
     this.param3 = parameter[3];
     this.param4 = parameter[4];
 }
        // jkb end

        public FunctionRam(CircuitState circuitState, int[] address, int[] inputData, int[] outputData, int write, Memory memory) : base(
                circuitState, address, inputData, outputData, write, memory)
        {
            // jkb: remember this guy if its a keyboard
            if (this.Memory.MapKeyboard == MemoryMapKeyboard.Hack)
            {
                keyboardRAM = this;
            }
        }
 public FunctionSound(CircuitState circuitState, int parameter) : base(circuitState, parameter)
 {
     if (FunctionSound.player == null)
     {
         FunctionSound.player = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("LogicCircuit.Properties.default.wav"));
         FunctionSound.player.LoadAsync();
     }
     FunctionSound.playCount = 0;
 }
Beispiel #12
0
		public FunctionLed(CircuitState circuitState, IEnumerable<CircuitSymbol> symbols, int parameter) : base(circuitState, parameter) {
			if(FunctionLed.stateBrush == null) {
				FunctionLed.stateBrush = new Brush[3];
				FunctionLed.stateBrush[(int)State.Off] = (Brush)App.CurrentApp.FindResource("LedOff");
				FunctionLed.stateBrush[(int)State.On0] = (Brush)App.CurrentApp.FindResource("LedOn0");
				FunctionLed.stateBrush[(int)State.On1] = (Brush)App.CurrentApp.FindResource("LedOn1");
			}
			this.circuitSymbol = symbols.ToList();
			this.project = this.circuitSymbol[0].LogicalCircuit.CircuitProject.ProjectSet.Project;
		}
Beispiel #13
0
 protected CircuitFunction(CircuitState circuitState, int[] parameter, int minimumParameterCount, int result) : this(circuitState, parameter, new int[] { result })
 {
     if (parameter == null)
     {
         throw new ArgumentNullException(nameof(parameter));
     }
     if (parameter.Length < minimumParameterCount)
     {
         throw new ArgumentException(Properties.Resources.FunctionParameter(this.Name, minimumParameterCount));
     }
 }
 public FunctionProbe(CircuitSymbol symbol, CircuitState circuitState, int[] parameter, int capacity) : base(circuitState, parameter)
 {
     Tracer.Assert(0 < this.BitWidth && this.BitWidth <= BasePin.MaxBitWidth);
     this.CircuitSymbol = symbol;
     this.tickHistory   = new History <State> [this.BitWidth];
     for (int i = 0; i < this.tickHistory.Length; i++)
     {
         this.tickHistory[i] = new History <State>(capacity);
     }
     this.valueHistory = new History <long>(capacity);
     this.valueHistory.Add(this.Pack());
 }
Beispiel #15
0
        /// <summary>
        /// Creates function. Assumes parameter layout: first goes columns states starting from column 0, bit 0 to bit 2. After all columns goes rows they are one bit wide.
        /// </summary>
        /// <param name="circuitState"></param>
        /// <param name="symbol"></param>
        /// <param name="parameter"></param>
        public FunctionLedMatrixSelector(CircuitState circuitState, IEnumerable <CircuitSymbol> symbols, int[] parameter) : base(circuitState, symbols, parameter)
        {
            LedMatrix matrix = this.Matrix;

            this.row = new State[matrix.Rows];
            int columns = matrix.Columns;

            this.column        = new int[columns];
            this.columnChanged = new bool[columns];
            this.cell          = new int[this.column.Length * this.row.Length];
            this.cellFlip      = new int[this.column.Length * this.row.Length];
            this.rowParameter  = columns * this.BitPerLed;
        }
        protected FunctionMemory(
            CircuitState circuitState, int[] address, int[] inputData, int[] outputData, int[] address2, int[] outputData2, int write, Memory memory
            ) : base(circuitState, FunctionMemory.Input(address, address2, inputData, write), FunctionMemory.Output(outputData, outputData2))
        {
            this.address     = address;
            this.address2    = address2;
            this.inputData   = inputData;
            this.outputData  = outputData;
            this.outputData2 = outputData2;
            this.Memory      = memory;
            if (inputData != null)
            {
                Tracer.Assert(memory.Writable);
                Tracer.Assert(this.inputData.Length == this.outputData.Length);
                this.write   = write;
                this.writeOn = this.Memory.WriteOn1 ? State.On1 : State.On0;
                switch (this.Memory.OnStart)
                {
                case MemoryOnStart.Random:
                    this.data = this.Allocate();
                    circuitState.Random.NextBytes(this.data);
                    break;

                case MemoryOnStart.Zeros:
                    this.data = this.Allocate();
                    break;

                case MemoryOnStart.Ones:
                    this.data = this.Allocate();
                    for (int i = 0; i < this.data.Length; i++)
                    {
                        this.data[i] = 0xFF;
                    }
                    break;

                case MemoryOnStart.Data:
                    this.data = memory.MemoryValue();
                    break;

                default:
                    Tracer.Fail();
                    break;
                }
            }
            else
            {
                Tracer.Assert(!memory.Writable);
                this.write = -1;
                this.data  = memory.MemoryValue();
            }
        }
Beispiel #17
0
        public FunctionButton(CircuitState circuitState, IEnumerable <CircuitSymbol> symbols, int result) : base(circuitState, State.On0, result)
        {
            this.circuitSymbol = symbols.ToList();
            this.project       = this.circuitSymbol[0].LogicalCircuit.CircuitProject.ProjectSet.Project;
            this.isToggle      = ((CircuitButton)this.circuitSymbol[0].Circuit).IsToggle;

            if (this.isToggle && FunctionButton.stateBrush == null)
            {
                FunctionButton.stateBrush = new Brush[] {
                    (Brush)App.CurrentApp.FindResource("Led7SegmentOff"),
                    (Brush)App.CurrentApp.FindResource("Led7SegmentOn0"),
                    (Brush)App.CurrentApp.FindResource("Led7SegmentOn1")
                };
            }
        }
        public static FunctionAndNot Create(CircuitState circuitState, int[] parameter, int result)
        {
            switch (parameter.Length)
            {
            case 1: return(new FunctionAndNot1(circuitState, parameter, result));

            case 2: return(new FunctionAndNot2(circuitState, parameter, result));

            case 3: return(new FunctionAndNot3(circuitState, parameter, result));

            case 4: return(new FunctionAndNot4(circuitState, parameter, result));

            case 5: return(new FunctionAndNot5(circuitState, parameter, result));

            default: return(new FunctionAndNotCommon(circuitState, parameter, result));
            }
        }
            public TableChank(LogicalCircuit logicalCircuit)
            {
                this.LogicalCircuit = TableChank.Copy(logicalCircuit);
                this.Plug();

                // Create map and state
                CircuitMap circuitMap = new CircuitMap(this.LogicalCircuit);

                this.CircuitState = circuitMap.Apply(CircuitRunner.HistorySize);

                this.Inputs.ForEach(s => s.Function  = circuitMap.FunctionConstant(s.Symbol));
                this.Outputs.ForEach(s => s.Function = circuitMap.FunctionProbe(s.Symbol));

                this.Inputs.Where(s => s.Function == null).ToList().ForEach(s => this.Inputs.Remove(s));
                this.Outputs.Where(s => s.Function == null).ToList().ForEach(s => this.Outputs.Remove(s));

                Tracer.Assert(this.Inputs.All(s => s.Function != null) && this.Outputs.All(s => s.Function != null));

                this.InputBitCount = this.Inputs.Sum(p => p.Pin.BitWidth);
                this.Count         = BigInteger.One << this.InputBitCount;

                circuitMap.TurnOn();
            }
 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 FunctionLedMatrixIndividual(CircuitState circuitState, IEnumerable <CircuitSymbol> symbols, int[] parameter) : base(circuitState, symbols, parameter)
        {
            LedMatrix matrix = this.Matrix;

            this.state = new int[matrix.Rows * matrix.Columns];
        }
Beispiel #22
0
 protected CircuitFunction(CircuitState circuitState, int[] parameter, int result) : this(circuitState, parameter, 1, result)
 {
 }
Beispiel #23
0
 public FunctionConstant(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
 {
     this.CircuitSymbol = symbol;
     Tracer.Assert(this.BitWidth == result.Length);
 }
Beispiel #24
0
 public FunctionTriState(CircuitState circuitState, int parameter, int enable, int result) : base(
         circuitState, new int[] { parameter, enable }, result
         )
 {
 }
Beispiel #25
0
 protected CircuitFunction(CircuitState circuitState, int parameter, int result) : this(circuitState, new int[] { parameter }, new int[] { result })
 {
 }
Beispiel #26
0
 protected Probe(CircuitState circuitState, int[] parameter) : base(circuitState, parameter, null)
 {
     this.Init(parameter != null ? parameter.Length : 0);
 }
 public FunctionRam(CircuitState circuitState, int[] address, int[] inputData, int[] outputData, int[] address2, int[] outputData2, int write, Memory memory) : base(
         circuitState, address, inputData, outputData, address2, outputData2, write, memory
         )
 {
 }
 public FunctionClock(CircuitState circuitState, int result) : base(circuitState, null, new int[] { result })
 {
     this.state = false;
 }
 public FunctionAndNotCommon(CircuitState circuitState, int[] parameter, int result) : base(circuitState, parameter, result)
 {
 }
 protected FunctionAndNot(CircuitState circuitState, int[] parameter, int result) : base(circuitState, parameter, result)
 {
 }