コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Voroz/GUIProjekt
        /******************************************************
         * CALL: Clicking the step back button.
         * TASK: Rolls back the program one step i.e. undo the
         *     previous operation.
         *****************************************************/
        private void Button_StepBack_Click(object sender, RoutedEventArgs e)
        {
            if (_runTimer.IsEnabled)
            {
                errorCode("Cannot undo while running the application.");
                return;
            }

            if (_assemblerModel.undoStack().size() == 0)
            {
                errorCode("Nothing to undo.");
                return;
            }

            if (_assemblerModel.undoStack().size() == 1)
            {
                Keyboard.ClearFocus();
                _currentTextBox.Foreground = (Brush)FindResource("TextBoxForegroundOff");
                clearUserMsg();
                _currentTextBox.IsReadOnly = false;
                showButtonAsEnabled(ButtonType.Stop);
            }

            UndoStorage undoValues  = _assemblerModel.undo();
            Bit12       currentAddr = _assemblerModel.getAddr(_assemblerModel.instructionPtr());
            Operations  opr         = Operations.LOAD;

            _assemblerModel.extractOperation(currentAddr.value(), out opr);

            // Mark current row
            markRow(getMMRowOfPosition(255 - _assemblerModel.instructionPtr()));

            // Update graphics of changed memory
            byte index;

            if (_assemblerModel.addrIdxToUpdate(currentAddr, out index))
            {
                if (opr == Operations.RETURN)
                {
                    index += 2;
                }

                MemoryRow row = getMMRowOfPosition(255 - index);
                row.ShowMemoryAdress(_assemblerModel.getAddr(index));

                if (index > 250)
                {
                    MemoryRow stackRow = getStackRowOfPosition(255 - index);
                    stackRow.ShowMemoryAdress(_assemblerModel.getAddr(index));
                }
            }

            ValueRow_WorkingRegister.ShowMemoryAdress(_assemblerModel.workingRegister());
            ValueRow_Output.ShowMemoryAdress(_assemblerModel.output());

            lightIfOutputIsOn();

            ValueRow_InstructionPointer.ShowMemoryAdress(new Bit12(_assemblerModel.instructionPtr()));
        }
コード例 #2
0
ファイル: AssemblerModel.cs プロジェクト: Voroz/GUIProjekt
        /******************************************************
         * CALL: UndoStorage valuesUndone = undo();
         * TASK: Returns an object which contains the previous
         *     state of various objects.
         *****************************************************/
        public UndoStorage undo()
        {
            UndoStorage undoValues = _undoStack.top();

            _undoStack.pop();
            _memory          = undoValues._memory;
            _memoryStack     = undoValues._memoryStack;
            _instructionPtr  = undoValues._instructionPtr;
            _workingRegister = undoValues._workingRegister;
            _output          = undoValues._output;

            return(undoValues);
        }