using PIC_Simulator.PIC; using PIC_Simulator.Properties; using System; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; namespace PIC_Simulator { public partial class Form1 : Form { private PICProgramm programm; private Timer quartztimer; public Form1() { InitializeComponent(); quartztimer = new Timer(); quartztimer.Tick += timer1_Tick; for (int i = 0; i < 32; i++) { var item = new ListViewItem(new[] {"00", "00", "00", "00", "00", "00", "00", "00"}); lvMemory.Items.Add(item); } lvSpecial.Items.Add(new ListViewItem(new[] { "W", "0x00" })); lvSpecial.Items.Add(new ListViewItem(new[] { "PC", "0x00" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Status", "0b00000000" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Time", "0ms" })); } 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); OberflaecheAktualisieren(); } 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); OberflaecheAktualisieren(); } } 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.SelectionStart = 0; box_CodeView.SelectionLength = box_CodeView.TextLength; box_CodeView.SelectionBackColor = box_CodeView.BackColor; } else { box_CodeView.SelectionStart = 0; box_CodeView.SelectionLength = box_CodeView.TextLength; box_CodeView.SelectionBackColor = box_CodeView.BackColor; box_CodeView.SelectionStart = i1; box_CodeView.SelectionLength = i2 - i1; box_CodeView.SelectionBackColor = Color.SteelBlue; } } private void cmd_reset_Click(object sender, EventArgs e) { quartztimer.Stop(); programm = new PICProgramm(); programm.Laden(box_CodeView.Text); OberflaecheAktualisieren(); } 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(); MessageBox.Show("Finished"); return; } OberflaecheAktualisieren(); } private void OberflaecheAktualisieren() { // Zeile highlighten if (programm.befehle.Count > 0 && programm.PCCounter < programm.befehle.Count) { Highlight(programm.befehle[programm.PCCounter].zeilennummer); } // Memory aktualisieren for (int y = 0; y < 32; y++) { for (int x = 0; x < 8; x++) { string nummer = string.Format("{0:X2}", programm.Register[y*8 + x]); if (nummer != lvMemory.Items[y].SubItems[x].Text) lvMemory.Items[y].SubItems[x].Text = nummer; } } // Spezialregister aktualisieren lvSpecial.Items[0].SubItems[1].Text = string.Format("0x{0:X2}", programm.Register_W); lvSpecial.Items[1].SubItems[1].Text = string.Format("{0,4}", programm.PCCounter); lvSpecial.Items[2].SubItems[1].Text = string.Format("0b{0}", Convert.ToString(programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS), 2).PadLeft(8, '0')); lvSpecial.Items[1].SubItems[1].Text = string.Format("{0}ms", programm.Stepcount * int.Parse(insertTime.Text)); lbStack.Items.Clear(); foreach (var u in programm.Stack) lbStack.Items.Add(u.ToString()); } } }