Exemplo n.º 1
0
        /// <summary>
        /// Create an edit field from the declaration
        /// </summary>
        void SetupEditField(Symbol symbol, bool parameter)
        {
            // Non bit value?
            if (symbol.CodeExprIndex < 0 || symbol.ArraySize <= 0)
            {
                return;
            }

            // Create array of bits
            List <OpCodeExpr> expr = new List <OpCodeExpr>();

            for (int i = 0; i < symbol.ArraySize; i++)
            {
                expr.Add(Box.LinkedCode[i + symbol.CodeExprIndex]);
            }

            // Create control
            EditField field = new EditField();

            field.Text        = symbol.Decl.VariableName;
            field.Expressions = expr;
            field.Visible     = false;
            if (parameter)
            {
                if (field.IsOutput())
                {
                    // Setup output only field (user output)
                    mFieldOutputs.Add(field);
                }
                else
                {
                    // Setup an input field (user input)
                    mFieldInputs.Add(field);
                    mFieldTabs.Add(field);
                }
            }
            else
            {
                // Setup a local field
                mFieldLocals.Add(field);
            }

            field.TabStop = !field.IsOutput();
            mFields.Add(field);
        }
Exemplo n.º 2
0
        private void FormSimulate_Load(object sender, EventArgs e)
        {
            // Initialize form variables
            Text = Box.ParseBox.NameDecl.VariableName + " Simulation";
            comboSpeed.Items.Add(new sComboSpeed("Speed: 100 gates/sec", 100));
            comboSpeed.Items.Add(new sComboSpeed("Speed: 1000 gates/sec", 1000));
            comboSpeed.Items.Add(new sComboSpeed("Speed: Fast as possible", 0));
            comboSpeed.SelectedIndex = 0;
            mThreadSpeedGPS          = 100;
            labelStats.Text          = "Simulating " + Box.GatesInLinkedCode() + " gates";


            // Setup edit field parameters IN/OUT
            SetupEditField(Box.Symbol, true);
            foreach (Symbol symbol in Box.Params)
            {
                SetupEditField(symbol, true);
            }

            // Setup edit field locals
            foreach (Symbol symbol in Box.Locals)
            {
                SetupEditField(symbol, false);
            }

            // Give the first input field the focus
            if (mFieldTabs.Count != 0)
            {
                mFieldInputs[0].Editor.CursorLoc = new TokenLoc(0, 1000);
                mFieldTabs[0].Focus();
            }


            // Setup input field locations
            int left = 4;
            int inY  = 4;
            int outY = 4;

            foreach (EditField field in mFieldInputs)
            {
                panelParams.Controls.Add(field);
                field.Location = new Point(left, inY);
                inY           += field.Height;
                field.Visible  = true;
            }
            // Setup output field locations
            foreach (EditField field in mFieldOutputs)
            {
                panelParams.Controls.Add(field);
                field.Location = new Point(left + field.Width, outY);
                outY          += field.Height;
                field.Visible  = true;
            }
            // Setup "Locals" label
            panelParams.Height = Math.Max(inY, outY) + 8;
            labelLocals.Top    = panelParams.Bottom + 8;
            panelLocals.Top    = labelLocals.Bottom;
            panelLocals.Height = Math.Max(1, ClientRectangle.Height - panelLocals.Top - 4);

            // Setup local field locations (two columns)
            int half = (mFieldLocals.Count + 1) / 2;

            for (int i = 0; i < mFieldLocals.Count; i++)
            {
                EditField field = mFieldLocals[i];
                panelLocals.Controls.Add(field);
                field.Location = new Point(4 + (i >= half ? field.Width : 0),
                                           4 + (i >= half ? i - half : i) * field.Height);
                field.Visible = true;
            }


            // Show this form before displaying an error message
            Show();

            // Initialize the simulation (wait for stabilization)
            if (!ResetSim(OpState.Zero))
            {
                MessageBox.Show(this, "Error: The simulation is un-stable.  This can be "
                                + "caused by something like: A = !A");
            }

            // Start thread running
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
            mThread = new Thread((ThreadStart) delegate { SimulationThread(); });
            mThread.Start();
        }