diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs index 2ecf5ca62..9791e8ff8 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs @@ -316,6 +316,7 @@ namespace Cosmos.Compiler.DebugStub { Call(); ESI = Memory["DebugEBP", 32]; + ESI.Add(4); // Dont transmit [EBP], its the saved EIP and not needed for (int i = 1; i <= xCount; i++) { Call("WriteByteToComPort"); } @@ -347,7 +348,7 @@ namespace Cosmos.Compiler.DebugStub { } } - public class ProcessCommand : CodeBlock { + public class ProcessCommand : CodeBlock { // Modifies: AL, DX (ReadALFromComPort) // Returns: AL public override void Assemble() { diff --git a/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs b/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs index e6e239884..855557946 100644 --- a/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs +++ b/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs @@ -46,7 +46,7 @@ namespace Cosmos.Cosmos_VS_Windows { Queue mCommand; Queue mMessage; - System.Timers.Timer mTimer = new System.Timers.Timer(250); + System.Timers.Timer mTimer = new System.Timers.Timer(100); /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require @@ -140,62 +140,65 @@ namespace Cosmos.Cosmos_VS_Windows } } - void ProcessMessage(object sender, EventArgs e) - { - byte xCmd = 0x0; - byte[] xMsg = {0x0}; - if ((mCommand.Count > 0) && (mMessage.Count > 0)) - { - xCmd = mCommand.Dequeue(); - xMsg = mMessage.Dequeue(); + void ProcessMessage(object sender, EventArgs e) { + byte xCmd; + byte[] xMsg; + while (true) { + lock (mCommand) { + if (mCommand.Count == 0) { + break; + } + xCmd = mCommand.Dequeue(); + xMsg = mMessage.Dequeue(); } - switch (xCmd) - { - case DwMsgType.Noop: - break; + switch (xCmd) { + case DwMsgType.Noop: + break; - case DwMsgType.Stack: - if (StackTW.mUC != null) { - StackTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - StackTW.mUC.UpdateStack(xMsg); - }); - } - break; + case DwMsgType.Stack: + if (StackTW.mUC != null) { + StackTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { + StackTW.mUC.UpdateStack(xMsg); + }); + } + break; - case DwMsgType.Frame: - if (StackTW.mUC != null) { - StackTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - StackTW.mUC.UpdateFrame(xMsg); - }); - } - break; + case DwMsgType.Frame: + if (StackTW.mUC != null) { + StackTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { + StackTW.mUC.UpdateFrame(xMsg); + }); + } + break; - case DwMsgType.Registers: - if (RegistersTW.mUC != null) { - RegistersTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - RegistersTW.mUC.Update(xMsg); - }); - } - break; + case DwMsgType.Registers: + if (RegistersTW.mUC != null) { + RegistersTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { + RegistersTW.mUC.Update(xMsg); + }); + } + break; - case DwMsgType.Quit: - //Close(); - break; + case DwMsgType.Quit: + //Close(); + break; - case DwMsgType.AssemblySource: - if (AssemblyTW.mUC != null) { - AssemblyTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - AssemblyTW.mUC.Update(xMsg); - }); - } - break; + case DwMsgType.AssemblySource: + if (AssemblyTW.mUC != null) { + AssemblyTW.mUC.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { + AssemblyTW.mUC.Update(xMsg); + }); + } + break; } + } } - void PipeThread_DataPacketReceived(byte aCmd, byte[] aMsg) - { + void PipeThread_DataPacketReceived(byte aCmd, byte[] aMsg) { + lock (mCommand) { mCommand.Enqueue(aCmd); mMessage.Enqueue(aMsg); + } } } } diff --git a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs index 7a8138250..55bc9eca6 100644 --- a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs +++ b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs @@ -12,50 +12,50 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; -namespace Cosmos.Cosmos_VS_Windows -{ - public partial class StackUC : UserControl - { - public StackUC() - { - InitializeComponent(); +namespace Cosmos.Cosmos_VS_Windows { + public partial class StackUC : UserControl { + public StackUC() { + InitializeComponent(); - tboxSourceFrame.Text = ""; - tboxSourceStack.Text = ""; - } - - public void UpdateFrame(byte[] aData) - { - string xData = BitConverter.ToString(aData); - xData = xData.Trim(); - xData = xData.Replace("-", ""); - - var xSB = new StringBuilder(); - for (int i = 0; i < aData.Length; i += 8) { - xSB.Insert(0, "[EBP + " + (i / 2) + "] 0x" + xData.Substring(i, 8) + "\n"); - } - xSB.Insert(0, "Arguments\n"); - tboxSourceFrame.Text = xSB.ToString(); - } - - public void UpdateStack(byte[] aData) - { - string xData = BitConverter.ToString(aData); - xData = xData.Trim(); - xData = xData.Replace("-", ""); - - int xCount = xData.Length / 8; - var xValues = new List(xCount); - for (int i = 0; i < xCount; i++) { - xValues.Add(xData.Substring(i * 8, 8)); - } - - var xSB = new StringBuilder(); - xSB.AppendLine("Stack Contents"); - for (int i = xCount - 1; i >= 0; i--) { - xSB.AppendLine("[EBP - " + ((xCount - i) * 4) + "] 0x" + xValues[i]); - } - tboxSourceStack.Text = xSB.ToString(); - } + tboxSourceFrame.Text = ""; + tboxSourceStack.Text = ""; } + + protected List SplitValues(byte[] aData) { + string xData = BitConverter.ToString(aData); + xData = xData.Trim(); + xData = xData.Replace("-", ""); + + int xCount = xData.Length / 8; + var xResult = new List(xCount); + for (int i = 0; i < xCount; i++) { + xResult.Add(xData.Substring(i * 8, 8)); + } + return xResult; + } + + public void UpdateFrame(byte[] aData) { + var xValues = SplitValues(aData); + int xCount = xValues.Count; + var xSB = new StringBuilder(); + xSB.AppendLine("Arguments"); + for (int i = 0; i < xCount; i++) { + // We start at EBP + 4, because [EBP] is not transmitted + // ([EBP] is saved EIP, not needed) + xSB.AppendLine("[EBP + " + (i * 4 + 4) + "] 0x" + xValues[i]); + } + tboxSourceFrame.Text = xSB.ToString(); + } + + public void UpdateStack(byte[] aData) { + var xValues = SplitValues(aData); + int xCount = xValues.Count; + var xSB = new StringBuilder(); + xSB.AppendLine("Locals and Stack"); + for (int i = 0; i < xCount; i++) { + xSB.AppendLine("[EBP - " + ((xCount - i) * 4) + "] 0x" + xValues[i]); + } + tboxSourceStack.Text = xSB.ToString(); + } + } } \ No newline at end of file