/****************************************************** * 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())); }
/****************************************************** * CALL: programTick(); * TASK: Progresses the execution of the program * one instruction. *****************************************************/ private void programTick() { Bit12 currentAddr = _assemblerModel.getAddr(_assemblerModel.instructionPtr()); Operations opr; byte val = (byte)_assemblerModel.extractVal(currentAddr.value()); _assemblerModel.extractOperation(currentAddr.value(), out opr); if (opr == Operations.RETURN && _assemblerModel.stack().size() == 0) { errorCode("Attempted Return on an empty stack."); pauseProgram(); return; } if (!_assemblerModel.processCurrentAddr()) { errorCode("Invalid operation."); pauseProgram(); return; } // Mark current row markRow(getMMRowOfPosition(255 - _assemblerModel.instructionPtr())); // Update graphics of changed memory byte index; if (_assemblerModel.addrIdxToUpdate(currentAddr, out index)) { if (opr != Operations.STORE) { index++; } 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()); ValueRow_InstructionPointer.ShowMemoryAdress(new Bit12(_assemblerModel.instructionPtr())); //First bit on output sets the light lightIfOutputIsOn(); }
/****************************************************** * CALL: markRow(MemoryRow row); * TASK: Marks which row to be executed in runtime. *****************************************************/ private void markRow(MemoryRow row) { if (_previousInstructionPtr != -1) { MemoryRow previousRow = getMMRowOfPosition((byte)(255 - _previousInstructionPtr)); previousRow.MemoryRow_Border.Visibility = System.Windows.Visibility.Hidden; Grid.SetZIndex(previousRow, 999); } row.MemoryRow_Border.Visibility = System.Windows.Visibility.Visible; Grid.SetZIndex(row, 1000); _previousInstructionPtr = _assemblerModel.instructionPtr(); }
/****************************************************** * CALL: createMemoryRowNumbers(); * TASK: Displays row numbers for the memory. *****************************************************/ private void showMemoryRowNumbers() { for (int i = 0; i <= 255; i++) { MemoryRow row = getMMRowOfPosition(255 - i); row.ShowMemoryRowNumber((byte)i); } for (int i = 0; i < 5; i++) { MemoryRow stackRow = getStackRowOfPosition(i); stackRow.ShowMemoryRowNumber((byte)(255 - i)); } }
/****************************************************** * CALL: updateGUIMemory(byte, byte, TextBox); * TASK: Updates the graphics of the different parts * of the memory. *****************************************************/ private void updateGUIMemory(byte from, byte to, TextBox textBox) { for (int i = from; i <= to; i++) { string str = ""; if (i < textBox.LineCount) { str = textBox.GetLineText(i); } char[] trimChars = new char[3] { '\r', '\n', ' ' }; str = str.TrimEnd(trimChars); Bit12 val = new Bit12(0); if (!string.IsNullOrWhiteSpace(str)) { if (textBox == TextBox_Assembler) { _assemblerModel.assemblyToMachine(str, out val); } else { if (_assemblerModel.checkSyntaxMachine(str)) { short tempval = Convert.ToInt16(str, 2); val = new Bit12(tempval); } } } if (i > 250) { MemoryRow stackRow = getStackRowOfPosition(255 - i); stackRow.ShowMemoryAdress(val); } MemoryRow rad = getMMRowOfPosition(255 - i); rad.ShowMemoryAdress(val); } }