This commit is contained in:
Mike Schwörer 2017-05-11 18:50:26 +02:00
parent f1e5bfa845
commit f2fa5b9f96
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 27 additions and 42 deletions

View File

@ -35,7 +35,6 @@
this.cmd_Start = new System.Windows.Forms.Button(); this.cmd_Start = new System.Windows.Forms.Button();
this.cmd_next = new System.Windows.Forms.Button(); this.cmd_next = new System.Windows.Forms.Button();
this.cmd_reset = new System.Windows.Forms.Button(); this.cmd_reset = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.cmdOpenFile = new System.Windows.Forms.ToolStripMenuItem(); this.cmdOpenFile = new System.Windows.Forms.ToolStripMenuItem();
this.programmÖffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.programmÖffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -62,7 +61,6 @@
this.columnHeader15 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader15 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader16 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader16 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
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.insertTime = new System.Windows.Forms.TextBox(); this.insertTime = new System.Windows.Forms.TextBox();
this.lvSpecial = new System.Windows.Forms.ListView(); this.lvSpecial = new System.Windows.Forms.ListView();
this.c1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.c1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -182,16 +180,6 @@
this.cmd_reset.UseVisualStyleBackColor = true; this.cmd_reset.UseVisualStyleBackColor = true;
this.cmd_reset.Click += new System.EventHandler(this.cmd_reset_Click); this.cmd_reset.Click += new System.EventHandler(this.cmd_reset_Click);
// //
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(248, 34);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(82, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Programmzähler";
//
// menuStrip1 // menuStrip1
// //
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
@ -379,16 +367,6 @@
this.cmd_Stop.UseVisualStyleBackColor = true; this.cmd_Stop.UseVisualStyleBackColor = true;
this.cmd_Stop.Click += new System.EventHandler(this.cmd_Stop_Click); this.cmd_Stop.Click += new System.EventHandler(this.cmd_Stop_Click);
// //
// lbl_Timer
//
this.lbl_Timer.AutoSize = true;
this.lbl_Timer.Location = new System.Drawing.Point(705, 28);
this.lbl_Timer.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_Timer.Name = "lbl_Timer";
this.lbl_Timer.Size = new System.Drawing.Size(33, 13);
this.lbl_Timer.TabIndex = 16;
this.lbl_Timer.Text = "Timer";
//
// insertTime // insertTime
// //
this.insertTime.Location = new System.Drawing.Point(894, 31); this.insertTime.Location = new System.Drawing.Point(894, 31);
@ -844,6 +822,7 @@
this.edCLockFreq.Name = "edCLockFreq"; this.edCLockFreq.Name = "edCLockFreq";
this.edCLockFreq.Size = new System.Drawing.Size(140, 20); this.edCLockFreq.Size = new System.Drawing.Size(140, 20);
this.edCLockFreq.TabIndex = 62; this.edCLockFreq.TabIndex = 62;
this.edCLockFreq.Text = "1500";
// //
// Form1 // Form1
// //
@ -896,11 +875,9 @@
this.Controls.Add(this.lbStack); this.Controls.Add(this.lbStack);
this.Controls.Add(this.lvSpecial); 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.cmd_Stop); this.Controls.Add(this.cmd_Stop);
this.Controls.Add(this.lvMemory); this.Controls.Add(this.lvMemory);
this.Controls.Add(this.label4); this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.cmd_reset); this.Controls.Add(this.cmd_reset);
this.Controls.Add(this.cmd_next); this.Controls.Add(this.cmd_next);
this.Controls.Add(this.cmd_Start); this.Controls.Add(this.cmd_Start);
@ -929,7 +906,6 @@
private System.Windows.Forms.Button cmd_Start; private System.Windows.Forms.Button cmd_Start;
private System.Windows.Forms.Button cmd_next; private System.Windows.Forms.Button cmd_next;
private System.Windows.Forms.Button cmd_reset; private System.Windows.Forms.Button cmd_reset;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem cmdOpenFile; private System.Windows.Forms.ToolStripMenuItem cmdOpenFile;
private System.Windows.Forms.ToolStripMenuItem programmÖffnenToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem programmÖffnenToolStripMenuItem;
@ -947,7 +923,6 @@
private System.Windows.Forms.ColumnHeader columnHeader8; private System.Windows.Forms.ColumnHeader columnHeader8;
private System.Windows.Forms.ToolStripMenuItem beendenToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem beendenToolStripMenuItem;
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.TextBox insertTime; private System.Windows.Forms.TextBox insertTime;
private System.Windows.Forms.ListView lvSpecial; private System.Windows.Forms.ListView lvSpecial;
private System.Windows.Forms.ColumnHeader c1; private System.Windows.Forms.ColumnHeader c1;

View File

@ -34,6 +34,10 @@ namespace PIC_Simulator
lvSpecial.Items.Add(new ListViewItem(new[] { "PC", "0x00" })); lvSpecial.Items.Add(new ListViewItem(new[] { "PC", "0x00" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status", "0b00000000" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Status", "0b00000000" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Time", "0ms" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Time", "0ms" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[DC]", "0" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[C]", "0" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[Z]", "0" }));
} }
private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
@ -155,6 +159,8 @@ namespace PIC_Simulator
{ {
// Zeile highlighten // Zeile highlighten
var a = box_CodeView.SelectionStart;
if (programm.befehle.Count > 0 && programm.PCCounter < programm.befehle.Count) if (programm.befehle.Count > 0 && programm.PCCounter < programm.befehle.Count)
{ {
Highlight(programm.befehle[programm.PCCounter].zeilennummer); Highlight(programm.befehle[programm.PCCounter].zeilennummer);
@ -169,7 +175,7 @@ namespace PIC_Simulator
} }
} }
box_CodeView.SelectionStart = 0; box_CodeView.SelectionStart = a;
box_CodeView.SelectionLength = 0; box_CodeView.SelectionLength = 0;
// Memory aktualisieren // Memory aktualisieren
@ -188,7 +194,10 @@ namespace PIC_Simulator
lvSpecial.Items[0].SubItems[1].Text = string.Format("0x{0:X2}", programm.Register_W); 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[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[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)); lvSpecial.Items[3].SubItems[1].Text = string.Format("{0}ms", programm.Stepcount * int.Parse(insertTime.Text));
lvSpecial.Items[4].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_C) ? "1" : "0";
lvSpecial.Items[5].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_DC) ? "1" : "0";
lvSpecial.Items[6].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_Z) ? "1" : "0";
lbStack.Items.Clear(); lbStack.Items.Clear();
foreach (var u in programm.Stack) lbStack.Items.Add(u.ToString()); foreach (var u in programm.Stack) lbStack.Items.Add(u.ToString());

View File

@ -243,10 +243,10 @@ namespace PIC_Simulator.PIC
// in the W register.If 'd' is 1 the result is // in the W register.If 'd' is 1 the result is
// stored back in register 'f'. // stored back in register 'f'.
uint a = GetRegister(aktueller_befehl.parameter_f); byte a = GetRegister(aktueller_befehl.parameter_f);
uint b = Register_W; byte b = Register_W;
var Result = a + b; uint Result = (uint) (a + b);
bool dc = AdditionDigitCarry(a, b); bool dc = AdditionDigitCarry(a, b);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
@ -256,7 +256,7 @@ namespace PIC_Simulator.PIC
Result %= 0x100; Result %= 0x100;
if (aktueller_befehl.parameter_d != 0) if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result); SetRegister(aktueller_befehl.parameter_f, (byte)Result);
else else
Register_W = (byte)Result; Register_W = (byte)Result;
} }
@ -512,11 +512,11 @@ namespace PIC_Simulator.PIC
uint a = GetRegister(aktueller_befehl.parameter_f); uint a = GetRegister(aktueller_befehl.parameter_f);
uint b = Register_W; uint b = Register_W;
bool carry; bool carry = (a + ((~b) & 0xFF)) > 0xFF;
bool dc = SubtractionDigitCarry(a, b); bool dc = SubtractionDigitCarry((byte)a, (byte)b);
if (carry = a < b) if (a < b)
{ {
a += 0x100; a += 0x100;
} }
@ -525,7 +525,7 @@ namespace PIC_Simulator.PIC
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, !carry); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, carry);
Result %= 0x100; Result %= 0x100;
@ -618,7 +618,7 @@ namespace PIC_Simulator.PIC
uint b = aktueller_befehl.parameter_k; uint b = aktueller_befehl.parameter_k;
uint Result = a + b; uint Result = a + b;
bool dc = AdditionDigitCarry(a, b); bool dc = AdditionDigitCarry((byte)a, (byte)b);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc); SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
@ -753,7 +753,7 @@ namespace PIC_Simulator.PIC
bool carry; bool carry;
bool dc = SubtractionDigitCarry(a, b); bool dc = SubtractionDigitCarry((byte)a, (byte)b);
if (carry = a < b) if (carry = a < b)
{ {
@ -879,7 +879,7 @@ namespace PIC_Simulator.PIC
return GetBit(GetRegisterOhneBank(index), bit); return GetBit(GetRegisterOhneBank(index), bit);
} }
public static bool AdditionDigitCarry(uint a, uint b) public static bool AdditionDigitCarry(byte a, byte b)
{ {
a &= 0x0F; a &= 0x0F;
b &= 0x0F; b &= 0x0F;
@ -887,11 +887,12 @@ namespace PIC_Simulator.PIC
return (a + b) > 0x0F; return (a + b) > 0x0F;
} }
public static bool SubtractionDigitCarry(uint a, uint b) public static bool SubtractionDigitCarry(byte a, byte b)
{ {
b = (~b) + 1; int xa = a & 0x0F;
int xb = ((~b) & 0x0F);
return AdditionDigitCarry(a, b); return (xa + xb) > 0x0F;
} }
public static bool GetBit(uint val, uint pos) public static bool GetBit(uint val, uint pos)