basic ui display

This commit is contained in:
Mike Schwörer 2017-05-10 16:30:58 +02:00
parent 65864ecd4e
commit 7b4a5ed4fe
4 changed files with 137 additions and 48 deletions

View File

@ -29,9 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("INDF");
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.box_CodeView = new System.Windows.Forms.RichTextBox(); this.box_CodeView = new System.Windows.Forms.RichTextBox();
this.lbl_path = new System.Windows.Forms.Label(); this.lbl_path = new System.Windows.Forms.Label();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
@ -47,7 +45,7 @@
this.cmdOpenDoc = new System.Windows.Forms.ToolStripMenuItem(); this.cmdOpenDoc = new System.Windows.Forms.ToolStripMenuItem();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.listView1 = new System.Windows.Forms.ListView(); this.lvMemory = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -59,6 +57,9 @@
this.cmd_Stop = new System.Windows.Forms.Button(); this.cmd_Stop = new System.Windows.Forms.Button();
this.lbl_Timer = new System.Windows.Forms.Label(); this.lbl_Timer = new System.Windows.Forms.Label();
this.insertTime = new System.Windows.Forms.TextBox(); this.insertTime = new System.Windows.Forms.TextBox();
this.lvSpecial = new System.Windows.Forms.ListView();
this.c1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.c2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -72,23 +73,13 @@
this.label1.Size = new System.Drawing.Size(0, 13); this.label1.Size = new System.Drawing.Size(0, 13);
this.label1.TabIndex = 1; this.label1.TabIndex = 1;
// //
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 469);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(78, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Programmpfad:";
//
// box_CodeView // box_CodeView
// //
this.box_CodeView.Location = new System.Drawing.Point(8, 77); this.box_CodeView.Location = new System.Drawing.Point(8, 77);
this.box_CodeView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.box_CodeView.Margin = new System.Windows.Forms.Padding(2);
this.box_CodeView.Name = "box_CodeView"; this.box_CodeView.Name = "box_CodeView";
this.box_CodeView.ReadOnly = true; this.box_CodeView.ReadOnly = true;
this.box_CodeView.Size = new System.Drawing.Size(626, 376); this.box_CodeView.Size = new System.Drawing.Size(626, 476);
this.box_CodeView.TabIndex = 3; this.box_CodeView.TabIndex = 3;
this.box_CodeView.Text = ""; this.box_CodeView.Text = "";
this.box_CodeView.WordWrap = false; this.box_CodeView.WordWrap = false;
@ -109,7 +100,7 @@
// cmd_Start // cmd_Start
// //
this.cmd_Start.Location = new System.Drawing.Point(11, 29); this.cmd_Start.Location = new System.Drawing.Point(11, 29);
this.cmd_Start.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.cmd_Start.Margin = new System.Windows.Forms.Padding(2);
this.cmd_Start.Name = "cmd_Start"; this.cmd_Start.Name = "cmd_Start";
this.cmd_Start.Size = new System.Drawing.Size(50, 23); this.cmd_Start.Size = new System.Drawing.Size(50, 23);
this.cmd_Start.TabIndex = 5; this.cmd_Start.TabIndex = 5;
@ -120,7 +111,7 @@
// cmd_next // cmd_next
// //
this.cmd_next.Location = new System.Drawing.Point(126, 31); this.cmd_next.Location = new System.Drawing.Point(126, 31);
this.cmd_next.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.cmd_next.Margin = new System.Windows.Forms.Padding(2);
this.cmd_next.Name = "cmd_next"; this.cmd_next.Name = "cmd_next";
this.cmd_next.Size = new System.Drawing.Size(50, 21); this.cmd_next.Size = new System.Drawing.Size(50, 21);
this.cmd_next.TabIndex = 6; this.cmd_next.TabIndex = 6;
@ -131,7 +122,7 @@
// cmd_reset // cmd_reset
// //
this.cmd_reset.Location = new System.Drawing.Point(190, 31); this.cmd_reset.Location = new System.Drawing.Point(190, 31);
this.cmd_reset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.cmd_reset.Margin = new System.Windows.Forms.Padding(2);
this.cmd_reset.Name = "cmd_reset"; this.cmd_reset.Name = "cmd_reset";
this.cmd_reset.Size = new System.Drawing.Size(50, 21); this.cmd_reset.Size = new System.Drawing.Size(50, 21);
this.cmd_reset.TabIndex = 7; this.cmd_reset.TabIndex = 7;
@ -214,9 +205,9 @@
// //
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
// //
// listView1 // lvMemory
// //
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.lvMemory.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1, this.columnHeader1,
this.columnHeader2, this.columnHeader2,
this.columnHeader3, this.columnHeader3,
@ -225,53 +216,58 @@
this.columnHeader6, this.columnHeader6,
this.columnHeader7, this.columnHeader7,
this.columnHeader8}); this.columnHeader8});
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { this.lvMemory.Location = new System.Drawing.Point(733, 78);
listViewItem2}); this.lvMemory.Margin = new System.Windows.Forms.Padding(2);
this.listView1.Location = new System.Drawing.Point(680, 77); this.lvMemory.Name = "lvMemory";
this.listView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.lvMemory.Size = new System.Drawing.Size(304, 297);
this.listView1.Name = "listView1"; this.lvMemory.TabIndex = 14;
this.listView1.Size = new System.Drawing.Size(326, 285); this.lvMemory.UseCompatibleStateImageBehavior = false;
this.listView1.TabIndex = 14; this.lvMemory.View = System.Windows.Forms.View.Details;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
// //
// columnHeader1 // columnHeader1
// //
this.columnHeader1.Text = "0"; this.columnHeader1.Text = "0";
this.columnHeader1.Width = 32;
// //
// columnHeader2 // columnHeader2
// //
this.columnHeader2.Text = "1"; this.columnHeader2.Text = "1";
this.columnHeader2.Width = 32;
// //
// columnHeader3 // columnHeader3
// //
this.columnHeader3.Text = "2"; this.columnHeader3.Text = "2";
this.columnHeader3.Width = 32;
// //
// columnHeader4 // columnHeader4
// //
this.columnHeader4.Text = "3"; this.columnHeader4.Text = "3";
this.columnHeader4.Width = 32;
// //
// columnHeader5 // columnHeader5
// //
this.columnHeader5.Text = "4"; this.columnHeader5.Text = "4";
this.columnHeader5.Width = 32;
// //
// columnHeader6 // columnHeader6
// //
this.columnHeader6.Text = "5"; this.columnHeader6.Text = "5";
this.columnHeader6.Width = 62; this.columnHeader6.Width = 32;
// //
// columnHeader7 // columnHeader7
// //
this.columnHeader7.Text = "6"; this.columnHeader7.Text = "6";
this.columnHeader7.Width = 32;
// //
// columnHeader8 // columnHeader8
// //
this.columnHeader8.Text = "7"; this.columnHeader8.Text = "7";
this.columnHeader8.Width = 32;
// //
// cmd_Stop // cmd_Stop
// //
this.cmd_Stop.Location = new System.Drawing.Point(64, 30); this.cmd_Stop.Location = new System.Drawing.Point(64, 30);
this.cmd_Stop.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.cmd_Stop.Margin = new System.Windows.Forms.Padding(2);
this.cmd_Stop.Name = "cmd_Stop"; this.cmd_Stop.Name = "cmd_Stop";
this.cmd_Stop.Size = new System.Drawing.Size(50, 22); this.cmd_Stop.Size = new System.Drawing.Size(50, 22);
this.cmd_Stop.TabIndex = 15; this.cmd_Stop.TabIndex = 15;
@ -292,21 +288,45 @@
// insertTime // insertTime
// //
this.insertTime.Location = new System.Drawing.Point(894, 31); this.insertTime.Location = new System.Drawing.Point(894, 31);
this.insertTime.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.insertTime.Margin = new System.Windows.Forms.Padding(2);
this.insertTime.Name = "insertTime"; this.insertTime.Name = "insertTime";
this.insertTime.Size = new System.Drawing.Size(47, 20); this.insertTime.Size = new System.Drawing.Size(47, 20);
this.insertTime.TabIndex = 17; this.insertTime.TabIndex = 17;
this.insertTime.Text = "100"; this.insertTime.Text = "500";
//
// lvSpecial
//
this.lvSpecial.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.c1,
this.c2});
this.lvSpecial.Location = new System.Drawing.Point(638, 378);
this.lvSpecial.Margin = new System.Windows.Forms.Padding(2);
this.lvSpecial.Name = "lvSpecial";
this.lvSpecial.Size = new System.Drawing.Size(399, 175);
this.lvSpecial.TabIndex = 18;
this.lvSpecial.UseCompatibleStateImageBehavior = false;
this.lvSpecial.View = System.Windows.Forms.View.Details;
//
// c1
//
this.c1.Text = "Name";
this.c1.Width = 128;
//
// c2
//
this.c2.Text = "Wert";
this.c2.Width = 128;
// //
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1048, 488); this.ClientSize = new System.Drawing.Size(1048, 585);
this.Controls.Add(this.lvSpecial);
this.Controls.Add(this.insertTime); this.Controls.Add(this.insertTime);
this.Controls.Add(this.lbl_Timer); this.Controls.Add(this.lbl_Timer);
this.Controls.Add(this.cmd_Stop); this.Controls.Add(this.cmd_Stop);
this.Controls.Add(this.listView1); this.Controls.Add(this.lvMemory);
this.Controls.Add(this.label4); this.Controls.Add(this.label4);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.cmd_reset); this.Controls.Add(this.cmd_reset);
@ -314,11 +334,10 @@
this.Controls.Add(this.cmd_Start); this.Controls.Add(this.cmd_Start);
this.Controls.Add(this.lbl_path); this.Controls.Add(this.lbl_path);
this.Controls.Add(this.box_CodeView); this.Controls.Add(this.box_CodeView);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1; this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "Form1"; this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "PIC Simulator"; this.Text = "PIC Simulator";
@ -332,7 +351,6 @@
#endregion #endregion
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.RichTextBox box_CodeView; private System.Windows.Forms.RichTextBox box_CodeView;
private System.Windows.Forms.Label lbl_path; private System.Windows.Forms.Label lbl_path;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1;
@ -347,7 +365,7 @@
private System.Windows.Forms.ToolStripMenuItem cmdOpenDoc; private System.Windows.Forms.ToolStripMenuItem cmdOpenDoc;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ListView listView1; private System.Windows.Forms.ListView lvMemory;
private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2; private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3; private System.Windows.Forms.ColumnHeader columnHeader3;
@ -360,6 +378,9 @@
private System.Windows.Forms.Button cmd_Stop; private System.Windows.Forms.Button cmd_Stop;
private System.Windows.Forms.Label lbl_Timer; private System.Windows.Forms.Label lbl_Timer;
private System.Windows.Forms.TextBox insertTime; private System.Windows.Forms.TextBox insertTime;
private System.Windows.Forms.ListView lvSpecial;
private System.Windows.Forms.ColumnHeader c1;
private System.Windows.Forms.ColumnHeader c2;
} }
} }

View File

@ -11,12 +11,25 @@ namespace PIC_Simulator
{ {
private PICProgramm programm; private PICProgramm programm;
private Timer quartztimer = new Timer(); private Timer quartztimer;
public Form1() public Form1()
{ {
InitializeComponent(); 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) private void Form1_Load(object sender, EventArgs e)
@ -27,6 +40,8 @@ namespace PIC_Simulator
programm = new PICProgramm(); programm = new PICProgramm();
programm.Laden(Resources.TPicSim1); programm.Laden(Resources.TPicSim1);
OberflaecheAktualisieren();
} }
private void cmd_Start_Click(object sender, EventArgs e) private void cmd_Start_Click(object sender, EventArgs e)
@ -51,6 +66,8 @@ namespace PIC_Simulator
programm = new PICProgramm(); programm = new PICProgramm();
programm.Laden(datei); programm.Laden(datei);
OberflaecheAktualisieren();
} }
} }
@ -68,10 +85,15 @@ namespace PIC_Simulator
int i2 = box_CodeView.GetFirstCharIndexFromLine(line + 1); int i2 = box_CodeView.GetFirstCharIndexFromLine(line + 1);
if (i2 < 0 || i1 < 0) if (i2 < 0 || i1 < 0)
{ {
box_CodeView.SelectionColor = Color.Transparent; box_CodeView.SelectionStart = 0;
box_CodeView.SelectionLength = box_CodeView.TextLength;
box_CodeView.SelectionBackColor = box_CodeView.BackColor;
} }
else else
{ {
box_CodeView.SelectionStart = 0;
box_CodeView.SelectionLength = box_CodeView.TextLength;
box_CodeView.SelectionBackColor = box_CodeView.BackColor;
box_CodeView.SelectionStart = i1; box_CodeView.SelectionStart = i1;
box_CodeView.SelectionLength = i2 - i1; box_CodeView.SelectionLength = i2 - i1;
box_CodeView.SelectionBackColor = Color.SteelBlue; box_CodeView.SelectionBackColor = Color.SteelBlue;
@ -80,7 +102,12 @@ namespace PIC_Simulator
private void cmd_reset_Click(object sender, EventArgs e) private void cmd_reset_Click(object sender, EventArgs e)
{ {
//TODO quartztimer.Stop();
programm = new PICProgramm();
programm.Laden(box_CodeView.Text);
OberflaecheAktualisieren();
} }
private void beendenToolStripMenuItem_Click(object sender, EventArgs e) private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
@ -102,10 +129,38 @@ namespace PIC_Simulator
{ {
bool finished = programm.Step(); bool finished = programm.Step();
if (finished) { quartztimer.Stop(); return; } 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); 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));
}
} }
} }

View File

@ -14,6 +14,8 @@ namespace PIC_Simulator.PIC
public uint parameter_k; public uint parameter_k;
public uint parameter_b; public uint parameter_b;
public int labelnummer;
public int zeilennummer; public int zeilennummer;
} }
@ -108,6 +110,7 @@ namespace PIC_Simulator.PIC
public List<PICBefehl> befehle; public List<PICBefehl> befehle;
public int PCCounter = 0; // -> nächster befehl public int PCCounter = 0; // -> nächster befehl
public int Stepcount = 0;
public uint Register_W = 0; public uint Register_W = 0;
public uint[] Register = new uint[0x100]; public uint[] Register = new uint[0x100];
@ -121,7 +124,7 @@ namespace PIC_Simulator.PIC
{ {
befehle = new List<PICBefehl>(); befehle = new List<PICBefehl>();
int zn = 0; int zn = -1;
foreach (var zeile in Regex.Split(code, @"\r?\n")) foreach (var zeile in Regex.Split(code, @"\r?\n"))
{ {
zn++; zn++;
@ -177,6 +180,7 @@ namespace PIC_Simulator.PIC
b.parameter_x = p_x; b.parameter_x = p_x;
b.parameter_b = p_b; b.parameter_b = p_b;
b.zeilennummer = zeilennummer; b.zeilennummer = zeilennummer;
b.labelnummer = Convert.ToInt32(zeile.Substring(0, 4), 16);
return b; return b;
} }
} }
@ -496,7 +500,7 @@ namespace PIC_Simulator.PIC
} }
else if (aktueller_befehl.befehl == GOTO) else if (aktueller_befehl.befehl == GOTO)
{ {
//TODO PCCounter = befehle.FindIndex(b => b.labelnummer == aktueller_befehl.parameter_k) - 1;
} }
else if (aktueller_befehl.befehl == IORLW) else if (aktueller_befehl.befehl == IORLW)
{ {
@ -559,6 +563,10 @@ namespace PIC_Simulator.PIC
Register_W = Result; ; Register_W = Result; ;
} }
PCCounter++;
Stepcount++;
return PCCounter >= befehle.Count;
} }
private uint GetRegister(uint index) private uint GetRegister(uint index)
@ -602,11 +610,16 @@ namespace PIC_Simulator.PIC
Register[index] = SetBit(Register[index], bit, wert); Register[index] = SetBit(Register[index], bit, wert);
} }
private bool GetRegisterOhneBank(uint index, uint bit) public bool GetRegisterOhneBank(uint index, uint bit)
{ {
return GetBit(Register[index], bit); return GetBit(Register[index], bit);
} }
public uint GetRegisterOhneBank(uint index)
{
return Register[index];
}
public static bool AdditionDigitCarry(uint a, uint b) public static bool AdditionDigitCarry(uint a, uint b)
{ {
a &= 0x0F; a &= 0x0F;

Binary file not shown.