Example #1
0
        // Adds an instruction passed from an instruction view and updates the view
        public void addInstruction(string label, string opcode, string operand, int position)
        {
            // Add instruction to the instruction list
            ProgramInstruction x = new ProgramInstruction(label, opcode, operand);

            switch (position)
            {
                case 1:
                    // Add before currently selected instruction
                    if (programView.SelectedIndices.Count > 0)
                    {
                        if ((programView.SelectedIndices[0]) >= 0)
                        {
                            instructions.Insert(programView.SelectedIndices[0], x);
                        }
                        else
                        {
                            MessageBox.Show("Error 18, Could not add instruction at that place. Check it is possible");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error 18, Could not add instruction at that place. Check it is possible");
                    }
                    break;

                case 2:
                    // Add after currently selected instruction
                    if (programView.SelectedIndices.Count > 0)
                    {
                        instructions.Insert(programView.SelectedIndices[0] + 1, x);

                    }
                    else
                    {
                        MessageBox.Show("Error 18, Could not add instruction at that place. Check it is possible");
                    }
                    break;

                case 3:
                    // Add at end
                    instructions.Add(x);
                    break;

                default:
                    instructions.Add(x);
                    break;
            }

            updateProgramView();

            // Set the ram view needs to update
            RAM_OutOfDate = true;
        }
Example #2
0
        // Display a dialog for opening a saved project and open it
        private void openButton_Click(object sender, EventArgs e)
        {
            if (new_program() == DialogResult.Yes)
            {
                try
                {
                    OpenFileDialog open = new OpenFileDialog();
                    open.RestoreDirectory = true;
                    open.Filter = "Assembly Simulator Files(*.as)\"|*.as";
                    if (open.ShowDialog() == DialogResult.OK)
                    {

                        StreamReader s;
                        string i;
                        s = File.OpenText(open.FileName);
                        i = s.ReadLine();
                        while (i != null)
                        {
                            // Add instruction
                            ProgramInstruction x = new ProgramInstruction(
                                i.Substring(0, 20).Trim(),
                                i.Substring(19, 20).Trim(),
                                i.Substring(39, 20).Trim()
                            );
                            instructions.Add(x);
                            // Read in new instruction
                            i = s.ReadLine();
                        }
                        updateProgramView();
                        s.Close();
                    }
                }
                catch
                {
                    MessageBox.Show("Error 23, The file you attempted to load was invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }