public override void Paint(Graphics graphics, Rectangle bounds) { var lineAddressColor = textArea.Document.HighlightingStrategy.GetColorFor("CPU Addresses"); graphics.FillRectangle(BrushRegistry.GetBrush(lineAddressColor.BackgroundColor), bounds); var font = lineAddressColor.GetFont(TextEditorProperties.FontContainer); var brush = BrushRegistry.GetBrush(lineAddressColor.Color); for (var y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / textArea.TextView.FontHeight + 1; ++y) { var backgroundRectangle = new Rectangle(drawingPosition.X, 2 + drawingPosition.Y + textArea.TextView.FontHeight * y - textArea.TextView.VisibleLineDrawingRemainder, drawingPosition.Width + 10, textArea.TextView.FontHeight); if (!bounds.IntersectsWith(backgroundRectangle)) { continue; } var currentLine = textArea.Document.GetFirstLogicalLine(textArea.TextView.FirstPhysicalLine + y); if (currentLine < textArea.Document.TotalNumberOfLines) { var debugLine = _getDebugLine(currentLine); if (debugLine == null || !debugLine.CpuAddress.HasValue) { continue; } graphics.DrawString(WatchValue.FormatHexAddress(debugLine.CpuAddress.Value, _addressWidth), font, brush, backgroundRectangle); } } }
public string GetAddressDescription() { return(string.Format("{0}{1} ({2})", WatchValue.FormatHexAddress(StartAddress), EndAddress == null ? "" : ("-" + WatchValue.FormatHexAddress(EndAddress.Value)), AddressType.ToString().ToUpper())); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (_lastLocation == e.Location) { return; } var address = GetAddressFromPoint(e.Location); if (_focusAddress != address) { Invalidate(); } _focusAddress = address; _lastLocation = e.Location; if (_focusAddress == -1) { AddressDetails.Active = false; return; } AddressDetails.Active = true; var addressHex = WatchValue.FormatHexAddress(_focusAddress); var value = _focusAddress >= _data.Length ? 0 : _data[_focusAddress]; var valueHex = Convert.ToString(value, 16).ToUpper().PadLeft(2, '0'); var wordValue = _focusAddress + 1 >= _data.Length ? 0 : (_data[_focusAddress + 1] * 256); wordValue += value; var wordValueHex = Convert.ToString(wordValue, 16).ToUpper().PadLeft(4, '0'); var text = string.Format("Address: {0}\nValue: ${1} ({2})\nWord value: ${3} ({4})", addressHex, valueHex, value, wordValueHex, wordValue); AddressDetails.Show(text, this, e.Location.X + 20, e.Location.Y + 2); }
protected string GetParsedAddress(string word) { var memoryState = GetCpuMemory(); if (memoryState == null) { return(word); } var addressReference = new AddressReference(word, s => File.Project.DebugSymbols.ContainsKey(s) ? File.Project.DebugSymbols[s] : null); var val8 = memoryState.ReadAddress(addressReference.BaseAddress, false, addressReference.OffsetRegister, out var address); var val16 = memoryState.ReadAddress(addressReference.BaseAddress, true, addressReference.OffsetRegister); return(string.Format("{0} ({1})\n\nValue: {2} ({3})\nWord value: {4} ({5})", word, WatchValue.FormatHexAddress(address), WatchValue.FormatHex(val8, 2), val8, WatchValue.FormatHex(val16, 4), val16 )); }
protected string GetSymbolDescription(string word) { //TODO: Watch manually written addresses, too! //TODO: X/Y offsets, maybe even DP? if (!File.Project.DebugSymbols.ContainsKey(word)) { var macro = File.LocalSymbols.FirstOrDefault(s => s.Text == word) as MacroSymbol; if (macro != null) { return(macro.ToString()); } return(word); } var symbol = File.Project.DebugSymbols[word]; var memoryState = GetCpuMemory(); if (memoryState == null) { return(string.Format("{0} ({1})", word, WatchValue.FormatHexAddress(symbol.Value))); } return(GetParsedAddress(word)); }
public CodeEditor(AsmProjectFile file, Events events) { File = file; ModuleEvents = events; Document.FormattingStrategy = new Ca65Formatting(); _fileCompletionDataProvider = new FileCompletion(new[] { file.Project.Directory, file.File.Directory }, () => { _forcedAutoCompleteWindow = true; ShowIntellisense('/', 0); }); ActiveTextAreaControl.TextArea.InsertLeftMargin(1, new CpuAddressMargin(ActiveTextAreaControl.TextArea, GetDebugLine, file.Project.Type == ProjectType.Snes ? 6 : 4)); Menu = new CodeMenu(events); Menu.Enabled = true; Menu.Name = "Menu"; Menu.Size = new Size(108, 70); ActiveTextAreaControl.TextArea.ContextMenuStrip = Menu; Menu.Opening += (sender, e) => { var word = GetAsmWord(ActiveTextAreaControl.Caret.Position); Menu.CurrentWord = word; }; Menu.GoToDefinition = GoToSymbol; Menu.AddToWatch = () => { var word = GetAsmWord(ActiveTextAreaControl.Caret.Position); if (word == null) { return; } switch (word.WordType) { case AsmWord.AsmWordType.NumberWord: case AsmWord.AsmWordType.NumberByte: AddToWatch(word.Word, word.WordType == AsmWord.AsmWordType.NumberWord); break; case AsmWord.AsmWordType.LabelReference: case AsmWord.AsmWordType.LabelAbsolute: case AsmWord.AsmWordType.LabelDefinition: case AsmWord.AsmWordType.AddressReference: AddToWatch(word.Word, false); break; } }; Menu.BreakOnAccess = (type) => { var word = GetAsmWord(ActiveTextAreaControl.Caret.Position); if (word == null) { return; } switch (word.WordType) { case AsmWord.AsmWordType.NumberWord: case AsmWord.AsmWordType.NumberByte: AddAddressBreakpoint(AddressReference.ParseNumber(word.Word), type); break; case AsmWord.AsmWordType.LabelReference: case AsmWord.AsmWordType.LabelAbsolute: case AsmWord.AsmWordType.LabelDefinition: AddSymbolBreakpoint(word.Word, type); break; } }; Menu.ToggleBreakpoint = ToggleBreakpointAtCaret; Document.HighlightingStrategy = new Ca65Highlighting(File.Project.Type); var testMarker = new TextMarker(0, 0, TextMarkerType.SolidBlock, Document.HighlightingStrategy.GetColorFor("Highlighted word").BackgroundColor); Document.MarkerStrategy.AddMarker(testMarker); /*ActiveTextAreaControl.TextArea.MouseMove += (sender, e) => * { * //Document.MarkerStrategy.RemoveMarker(testMarker); * //ActiveTextAreaControl.TextArea.Invalidate(); * * var textPosition = new Point(e.Location.X - ActiveTextAreaControl.TextArea.LeftMargins.Where(m => m.IsVisible).Sum(m => m.Size.Width), e.Location.Y); * if (textPosition.X < 0 || textPosition.Y < 0) return; * * var position = ActiveTextAreaControl.TextArea.TextView.GetLogicalPosition(textPosition); * if (position.Line >= Document.TotalNumberOfLines) return; * * var line = Document.GetLineSegment(position.Line); * if (line == null) return; * var word = line.GetWord(position.Column); * if (word == null || word.IsWhiteSpace) return; * * return; * //word.SyntaxColor = new HighlightColor(word.Color, Color.DarkGray, true, false); * Document.MarkerStrategy.AddMarker(testMarker); * testMarker.Offset = word.Offset + line.Offset; * testMarker.Length = word.Length; * ActiveTextAreaControl.TextArea.Invalidate(); * };*/ var lineAddressToolTip = new ToolTip(); ActiveTextAreaControl.TextArea.ToolTipRequest += (s, e) => { Document.MarkerStrategy.RemoveMarker(testMarker); ActiveTextAreaControl.TextArea.Invalidate(); if (e.ToolTipShown || e.LogicalPosition.Line >= Document.TotalNumberOfLines) { return; } var line = Document.GetLineSegment(e.LogicalPosition.Line); if (line == null) { return; } lineAddressToolTip.Hide(FindForm()); var word = e.InDocument ? GetAsmWord(e.LogicalPosition) : null; if (word == null || word.IsWhiteSpace || word.WordType == AsmWord.AsmWordType.Comment) { var debugLine = GetDebugLine(line.LineNumber); if (debugLine == null || debugLine.CpuAddress == null) { return; } testMarker.Offset = line.Offset; testMarker.Length = line.Length; Document.MarkerStrategy.AddMarker(testMarker); //e.ShowToolTip(WatchValue.FormatHexAddress(debugLine.Address)); lineAddressToolTip.Show( WatchValue.FormatHexAddress(debugLine.CpuAddress.Value), FindForm(), PointToScreen(new Point(-60, e.MousePosition.Y)) , 3000 // TODO: Use a custom form object, not tooltips ); return; } testMarker.Offset = word.Offset + line.Offset; testMarker.Length = word.Length; Document.MarkerStrategy.AddMarker(testMarker); ActiveTextAreaControl.TextArea.Invalidate(); switch (word.WordType) { case AsmWord.AsmWordType.LabelAbsolute: case AsmWord.AsmWordType.LabelReference: case AsmWord.AsmWordType.LabelDefinition: case AsmWord.AsmWordType.Macro: e.ShowToolTip(GetSymbolDescription(word.Word)); break; case AsmWord.AsmWordType.AddressReference: e.ShowToolTip(GetParsedAddress(word.Word)); break; case AsmWord.AsmWordType.Command: var command = Ca65Parser.GetCommandFromWord(word.Word); if (command != null) { e.ShowToolTip(command.ToString()); } break; case AsmWord.AsmWordType.Opcode: var opcode = OpcodeParser.GetOpcodeFromWord(word.Word, File.Project.Type); if (opcode != null) { e.ShowToolTip(opcode.ToString()); } break; default: e.ShowToolTip(word.Word); break; } }; Document.DocumentAboutToBeChanged += (s, arts) => { _changedSinceLastCheck = true; }; //Document.LineCountChanged += (sender, args) => RefreshErrorInfo(); Document.LineLengthChanged += (s, args) => { if (Document.MarkerStrategy.GetMarkers(args.LineSegment.Offset).Any(m => m is ErrorMarker)) { RefreshErrorInfo(); } }; ActiveTextAreaControl.Caret.PositionChanged += (s, a) => { QueueCareInformation(); if (ActiveTextAreaControl.Caret.Line == _caretLine) { return; } _caretLine = ActiveTextAreaControl.Caret.Line; RefreshErrorInfo(); }; ActiveTextAreaControl.TextArea.KeyUp += delegate(object sender, KeyEventArgs e) { /*if (e.KeyCode == Program.Keys[Brewmaster.Settings.Feature.GoToDefinition]) * { * GoToSymbol(); * return; * }*/ //if (e.KeyCode == Keys.Escape) return; if (NavigationKeys.Contains(e.KeyCode)) { return; } ShowIntellisense((char)e.KeyValue, 1); _forcedAutoCompleteWindow = false; HighlightOpcodeOnLine(); }; ActiveTextAreaControl.TextArea.IconBarMargin.MouseDown += (sender, mousepos, buttons) => { if (buttons != MouseButtons.Left) { return; } var line = ActiveTextAreaControl.TextArea.TextView.GetLogicalLine(mousepos.Y); AddBreakpointMarker(line); RefreshBreakpointsInProject(); }; Document.DocumentChanged += (sender, args) => { var changed = false; foreach (var bp in Document.BookmarkManager.Marks.OfType <BreakpointMarker>()) { if (bp.GlobalBreakpoint.CurrentLine != bp.LineNumber + 1) { changed = true; } bp.GlobalBreakpoint.CurrentLine = bp.LineNumber + 1; } if (changed) { RefreshBreakpointsInProject(); } }; }
public override string ToString() { return(File != null ? string.Format("{0}:{1}", File.File.Name, CurrentLine) : Symbol != null ? Symbol + (StartAddress >= 0 ? string.Format(" ({0})", WatchValue.FormatHexAddress(StartAddress)) : "") : GetAddressDescription()); }