Simple Computer

I'm trying to create a Simple Computer simulator in C#. Its been going well up until ive reached a point where i need to have actions performed step by step when a button is clicked.

A little background:
The simple computer is a simulator that helps show students how lower level languages interpret commands.

In the program:
I have 99 Text boxes representing memory cells, 99 Text boxes representing input cards, 99 Text boxes representing output cards, a text box representing the accumulator (basic arithmatic portion of the simple computer), a text box representing the Instruction Register, a text box representing the Program Counter, a button that manually steps through the program entered in to the memory cells, and a button that should step through automatically.

problem:
Basically, my problem is that i need to perform the same action a number of times and have the GUI update so you can see the actions take place step by step. This must be done automatically after the button is pressed. I already have a step button programmed well. Is there any way to do this

Thanks in advance.


Answer this question

Simple Computer

  • Xzarian

    I'd suggest getting rid of those 397 text boxes for memory, input & output and replacing them with 3 grids (each one column width). Well, memory probably should be a grid, although for input/output listboxes may work better.

  • Bluehunter

    You are doing your processing on the applications GUI thread. The GUI gets no chance to update itself while you are processing the loop.

    You should look into threading etc, but for now you should be able to force the GUI to update by calling Control.Refresh() either on the form object or per control, inside your loop.

    ....

    if(c.getOp() == 9)
                    {
                        PC.Text = c.getMemCell().ToString();
                        IR.Text = memoryCells.Text;
                        j = false;

                        PC.Refresh();

                        IR.Refresh();
                    }
    ...



  • Saurabh Kulkarni

    I should probably mention that the events need to take place in a while loop.

    example(actual code that doesnt work):

    int i;

    Checker c = new Checker();

    Boolean j = true;
    while (j)
    {
    i = int.Parse(PC.Text);
    c.opCode(memoryCellsIdea.Text);
    if(c.getOp() == 9)
    {
    PC.Text = c.getMemCell().ToString();
    IR.Text = memoryCellsIdea.Text;
    j = false;
    }

    if (!j)
    break;

    //this.MyEvent += new System.EventHandler(this.Start_Go);
    //myEvent(sender, e);
    //Step.PerformClick();
    //Step_Click(Step, e);

    switch (stepSpeed)
    {
    case 1:
    Thread.Sleep(5);
    break;
    case 2:
    Thread.Sleep(4);
    break;
    case 3:
    Thread.Sleep(3);
    break;
    case 4:
    Thread.Sleep(2);
    break;
    case 5:
    Thread.Sleep(1);
    break;
    }

  • CoreyMc

    It sounds like you need to put a timer into your code to execute each step every 1/2 to full second so that you can see the results. Instead of using the while loop try putting the code inside the Timer event and see if that helps you watch the steps happen.

  • Keithyboy1

    I've tried that, the problem is im unable to see each event take place. It just shows the end result. Im trying to find a ways to show each step separately, but done automatically.

    thanks for the help:).


  • JosB

    I'm not sure I understand exactly what the steps are that you need to perform, but if you have your StepButton working correctly then you should just be able to call that method from within a loop. You will probably just need to add a variable to say when there are no more steps to execute.

    Example:
    while( moreStepsToExecute ) {
    StepButton_Click( StepButton , EventArgs.e );
    }

  • Simple Computer