Пример #1
0
        // Should be in SkinManager, but how to access getMMRowOfPosition from there?
        public void changeSkin(Skins skin)
        {
            ResourceDictionary selectedDictionary = SkinManager.GetSkin(skin);

            App.Current.MainWindow.Resources.MergedDictionaries.Add(selectedDictionary);

            if (_assemblerModel.undoStack().size() == 0)
            {
                _currentTextBox.Foreground = (Brush)FindResource("TextBoxForegroundOff");
            }
            else
            {
                _currentTextBox.Foreground = (Brush)FindResource("TextBoxForegroundOn");
            }

            for (int i = 0; i <= 255; i++)
            {
                getMMRowOfPosition(255 - i).ChangeSkin(selectedDictionary);
            }

            for (int i = 0; i < 5; i++)
            {
                getStackRowOfPosition(i).ChangeSkin(selectedDictionary);
            }

            ValueRow_InstructionPointer.ChangeSkin(selectedDictionary);
            ValueRow_Input.ChangeSkin(selectedDictionary);
            ValueRow_Output.ChangeSkin(selectedDictionary);
            ValueRow_WorkingRegister.ChangeSkin(selectedDictionary);
        }
Пример #2
0
        /******************************************************
         * 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()));
        }
Пример #3
0
        /******************************************************
         * 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();
        }
Пример #4
0
        /******************************************************
         * CALL: stopProgram();
         * TASK: Stops the execution of the program and resets
         *     various elements.
         *****************************************************/
        private void stopProgram()
        {
            _runTimer.Stop();
            _assemblerModel.reset();
            updateGUIMemory(0, 255, _currentTextBox);

            ValueRow_WorkingRegister.ShowMemoryAdress(_assemblerModel.workingRegister());
            ValueRow_Output.ShowMemoryAdress(_assemblerModel.output());
            ValueRow_InstructionPointer.ShowMemoryAdress(new Bit12(_assemblerModel.instructionPtr()));

            showButtonAsEnabled(ButtonType.Stop);
            lightOff();
            Keyboard.ClearFocus();
            _currentTextBox.Foreground = (Brush)FindResource("TextBoxForegroundOff");
            clearUserMsg();
            userMsg("Execution was stopped.");

            _currentTextBox.IsReadOnly = false;

            // Mark current row
            markRow(getMMRowOfPosition(255 - _assemblerModel.instructionPtr()));
        }
Пример #5
0
        public MainWindow()
        {
            InitializeComponent();
            _assemblerModel = new AssemblerModel();
            _assemblerModel.SelfTest();
            showMemoryRowNumbers();
            _currentTextBox = TextBox_Assembler;
            updateGUIMemory(0, 255, _currentTextBox);
            _inputTimerAssembly = new System.Windows.Threading.DispatcherTimer();
            _inputTimerMK       = new System.Windows.Threading.DispatcherTimer();
            _runTimer           = new System.Windows.Threading.DispatcherTimer();
            _commandWindow      = new Commands();
            _aboutWin           = new About();
            Closing            += OnClosing;
            _assemblySaved      = true;
            _mkSaved            = true;

            _keyPressStack = new CircularStack <Key>(20);
            _password      = "******";

            _inputTimerAssembly.Interval = new TimeSpan(0, 0, 0, 0, 500);
            _inputTimerAssembly.Tick    += OnInputTimerAssemblyElapsed;
            _inputTimerMK.Interval       = new TimeSpan(0, 0, 0, 0, 500);
            _inputTimerMK.Tick          += OnInputTimerMKElapsed;
            _runTimer.Interval           = new TimeSpan(0, 0, 0, 0, (int)Slider_FastForward.Value);
            _runTimer.Tick += OnInputTimerRunElapsed;

            markRow(getMMRowOfPosition(255 - _assemblerModel.instructionPtr())); // Mark current row
            Slider_FastForward.Value = 200;                                      // Can't be specified in the XAML file, bug

            ValueRow_WorkingRegister.ShowMemoryAdress(_assemblerModel.workingRegister());
            ValueRow_Output.ShowMemoryAdress(_assemblerModel.output());
            ValueRow_Input.ShowMemoryAdress(_assemblerModel.input());
            ValueRow_InstructionPointer.ShowMemoryAdress(new Bit12(_assemblerModel.instructionPtr()));
            ValueRow_InstructionPointer.HideChildElements();

            EventManager.RegisterClassHandler(typeof(Window), Keyboard.KeyDownEvent, new KeyEventHandler(keyDown), true);
        }