using PIC_Simulator.PIC; using PIC_Simulator.Properties; using System; using System.Drawing; using System.IO; using System.Windows.Forms; namespace PIC_Simulator { public partial class Form1 : Form { private PICProgramm programm; private Timer quartztimer = new Timer(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { box_CodeView.Font = new Font("Consolas", 8); box_CodeView.Text = Resources.TPicSim1; programm = new PICProgramm(); programm.Laden(Resources.TPicSim1); } private void cmd_Start_Click(object sender, EventArgs e) { quartztimer.Stop(); quartztimer.Interval = int.Parse(insertTime.Text); quartztimer.Start(); } private void cmd_next_Click(object sender, EventArgs e) { StepProgramm(); } private void programmÖffnenToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string datei = File.ReadAllText(openFileDialog1.FileName); box_CodeView.Text = datei; programm = new PICProgramm(); programm.Laden(datei); } } private void cmdOpenDoc_Click(object sender, EventArgs e) { string path = Path.GetTempFileName() + ".pdf"; File.WriteAllBytes(path, Resources.DataSheet); System.Diagnostics.Process.Start(path); } //Funktion um Zeile aktuell ausgeführte Zeile zu markieren void Highlight(int line) { int i1 = box_CodeView.GetFirstCharIndexFromLine(line); int i2 = box_CodeView.GetFirstCharIndexFromLine(line + 1); if (i2 < 0 || i1 < 0) { box_CodeView.SelectionColor = Color.Transparent; } else { box_CodeView.SelectionStart = i1; box_CodeView.SelectionLength = i2 - i1; box_CodeView.SelectionBackColor = Color.SteelBlue; } } private void cmd_reset_Click(object sender, EventArgs e) { //TODO } private void beendenToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void timer1_Tick(object sender, EventArgs e) { StepProgramm(); } private void cmd_Stop_Click(object sender, EventArgs e) { quartztimer.Stop(); } private void StepProgramm() { bool finished = programm.Step(); if (finished) { quartztimer.Stop(); return; } Highlight(programm.befehle[programm.PCCounter].zeilennummer); } } }