private bool OnMemoryChanged(Word addr, int count, bool written) { int stop = addr + count; if (!sess.Machine.IsRunning) // Don't add boxes if machine is running. (They will be added only when stepping). { if (written) { for (int i = addr; i < stop; ++i) { ByteMarker newBox = new ByteMarker(i, MEMORY_WRITTEN_COLOR, sess.Machine.InstructionsExecuted); hexDisplay.Boxes.Add(newBox); } } else { for (int i = addr; i < stop; ++i) { ByteMarker newBox = new ByteMarker(i, MEMORY_READ_COLOR, sess.Machine.InstructionsExecuted); hexDisplay.Boxes.Add(newBox); } } } if (breakpointsEnabled) { foreach (Breakpoint b in breakpoints) { int diff = b.Address - addr; if (diff < 0 || diff > count) { continue; // This breakpoint is out of range. } if (b.Enabled) { if (b.BreakOnWrite == written || b.BreakOnRead == !written) { Log("Breakpoint hit at {0}.", addr); return(true); // Tell machine to break. } } } } return(false); // Allow VM execution to continue. }
private void InitializeMachineDisplay() { if (sess?.Machine != null) { hexDisplay.Data = sess.Machine.Memory; sess.Machine.MemoryChanged += OnMemoryChanged; sess.Machine.RegisterChanged += OnRegisterChanged; } hexDisplay.Boxes.Clear(); pcMarker = new ByteMarker(sess.Machine.ProgramCounter, PC_MARKER_COLOR, sess.Machine.InstructionsExecuted, false, PC_MARKER_ID); ResetTextboxColors(); }
private void UpdateMachineDisplay() { if (InvokeRequired) { Invoke(new Action(UpdateMachineDisplay)); return; } // Update labels. Machine m = sess.Machine; regATB.Text = m.RegisterA.ToString("X6"); regBTB.Text = m.RegisterB.ToString("X6"); regSTB.Text = m.RegisterS.ToString("X6"); regTTB.Text = m.RegisterT.ToString("X6"); regXTB.Text = m.RegisterX.ToString("X6"); regLTB.Text = m.RegisterL.ToString("X6"); pcTB.Text = m.ProgramCounter.ToString("X6"); switch (m.ConditionCode) { case ConditionCode.EqualTo: ccCB.SelectedIndex = 1; break; case ConditionCode.LessThan: ccCB.SelectedIndex = 0; break; case ConditionCode.GreaterThan: ccCB.SelectedIndex = 2; break; } // Cull old markers. int instr = (int)m.InstructionsExecuted - 1; int removed = hexDisplay.Boxes.RemoveWhere(bm => { BigInteger?expiry = bm.ExpiresAfter; bool ret = expiry.HasValue && instr > expiry.Value; //Debug.WriteLineIf(ret, $"Culling byte marker {bm.ToString()}. Instr = {instr}."); return(ret); } ); //Debug.WriteLine($"Removed {removed} byte markers."); // Remove old program counter. hexDisplay.Boxes.RemoveWhere(bm => bm.GetHashCode() == PC_MARKER_ID); // Add new program counter marker. pcMarker = new ByteMarker(m.ProgramCounter, PC_MARKER_COLOR, null, false, PC_MARKER_ID); hexDisplay.Boxes.Add(pcMarker); // Update memory display. hexDisplay.Invalidate(); }