Beispiel #1
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Sets break point marker. </summary>
        ///
        /// <remarks> 08/09/2018. </remarks>
        ///
        /// <param name="active">   True to active. </param>
        /// <param name="filename"> Filename of the file. </param>
        /// <param name="linenum">  The linenum. </param>
        ///
        /// <returns> True if it succeeds, false if it fails. </returns>
        /// -------------------------------------------------------------------------------------------------
        public static bool SetBreakPointMarker(bool active, string filename, int linenum)
        {
            TraceFile  tf   = TraceFile.FindTraceFile(filename);
            const uint mask = (1 << BREAKPOINT_MARKER);

            if (tf.IsLineLegal(linenum))
            {
                var line = tf.codefile.codewindow.Lines[linenum];

                if (active)
                {
                    if ((line.MarkerGet() & mask) == 0)
                    {
                        line.MarkerAdd(BREAKPOINT_MARKER);
                        return(true);
                    }
                }
                else
                {
                    if ((line.MarkerGet() & mask) != 0)
                    {
                        line.MarkerDelete(BREAKPOINT_MARKER);
                        return(true);
                    }
                }
            }



            return(false);
        }
Beispiel #2
0
 // -------------------------------------------------------------------------------------------------
 // Updates the margin address described by tf
 //
 // \param   tf  The tf.
 // -------------------------------------------------------------------------------------------------
 public void UpdateMarginAddress(TraceFile tf)
 {
     foreach (LineData ld in tf.lines)
     {
         var line = tf.codefile.codewindow.Lines[ld.lineNumber];
         line.MarginText = ld.nextAddress.ToString("b");
     }
 }
Beispiel #3
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Parse trace data. </summary>
        ///
        /// <remarks> 06/09/2018. </remarks>
        ///
        /// <param name="filename"> Filename of the file. </param>
        /// -------------------------------------------------------------------------------------------------
        public static void ParseTraceData(string filename)
        {
            //z80.asm|25|5|32828
            traceFiles = new List <TraceFile>();


            Regex registersregex = new Regex(@"^(?<filename>[_a-zA-Z0-9\\.]*)\|(?<line>[0-9]*)\|(?<bank>[0-9]*)\|(?<addr>[0-9]*)\|(?<type>[LFT])");

            string[] lines = File.ReadAllLines(filename);

            foreach (string s in lines)
            {
                if (!string.IsNullOrEmpty(s))
                {
                    var match = registersregex.Match(s);
                    //Console.WriteLine(match.Groups["label"] + " " + match.Groups["address"] + " " + match.Groups["type"] + " " + match.Groups["section"]);

                    string fn   = match.Groups["filename"].ToString();
                    int    bank = 0;
                    int.TryParse(match.Groups["bank"].ToString(), NumberStyles.Integer, null, out bank);
                    int line = 0;
                    int.TryParse(match.Groups["line"].ToString(), NumberStyles.Integer, null, out line);
                    int addr = 0;
                    int.TryParse(match.Groups["addr"].ToString(), NumberStyles.Integer, null, out addr);

                    if (match.Groups["type"].ToString() == "T")
                    {
                        TraceFile tracefile = TraceFile.FindTraceFile(fn);
                        if (tracefile == null)
                        {
                            Console.WriteLine("Adding file " + fn);
                            tracefile = new TraceFile(fn);
                            traceFiles.Add(tracefile);
                        }



                        //found source level debug symbol
                        LineData ld = new LineData();

                        ld.address    = addr;
                        ld.bank       = bank;
                        ld.lineNumber = line - 1;


                        tracefile.lines.Add(ld);
                    }
                    else if (match.Groups["type"].ToString() == "L")
                    {
                        Labels.AddLabel(fn, addr, bank, false);
                    }
                    else if (match.Groups["type"].ToString() == "F")
                    {
                        Labels.AddLabel(fn, addr, bank, true);
                    }
                }
            }
        }
Beispiel #4
0
        // -------------------------------------------------------------------------------------------------
        // Updates the dism window
        // -------------------------------------------------------------------------------------------------
        public void UpdateDismWindow()
        {
            int maxlines = DisasmCodeFile.codefile.codewindow.LinesOnScreen;

            Console.WriteLine("vis" + maxlines);

            int currentline = DisasmCodeFile.codefile.codewindow.FirstVisibleLine;

            //stop scroll off top
            int fl = (MainForm.myDisassembly.DissasemblyLinesPC - (maxlines / 2) + DisOffset);

            if (fl < 0)
            {
                DisOffset -= fl;
                fl         = 0;
            }

            if ((fl + maxlines) >= MainForm.myDisassembly.DissasemblyLines.Count)
            {
                DisOffset -= ((fl + maxlines) - MainForm.myDisassembly.DissasemblyLines.Count);
            }


            int FirstLine = Math.Max(0, MainForm.myDisassembly.DissasemblyLinesPC - (maxlines / 2) + DisOffset);

            string codetext = MainForm.myDisassembly.GetDissasemblySource(ref DisasmCodeFile, maxlines, FirstLine);

            if (DisasmCodeFile.codefile.codewindow.Text == codetext)
            {
                return;
            }

            DisasmCodeFile.codefile.codewindow.ReadOnly = false;
            DisasmCodeFile.codefile.codewindow.Text     = codetext;
            DisasmCodeFile.codefile.codewindow.ReadOnly = true;

            UpdateMarginAddress(DisasmCodeFile);

            //update disassembly
            int pc     = MainForm.myNewRegisters.GetRegisterValueint(Registers.Z80Register.pc);
            int nextpc = MainForm.myDisassembly.GetStepAddress();
            int bank   = MainForm.banks[TraceFile.GetBankIndex(pc)];

            SetDismPC(nextpc, pc, bank);
            DisasmCodeFile.codefile.codewindow.FirstVisibleLine = currentline;


            //Update Breakpoints
            foreach (BreakpointDisplay bp in BreakpointDisplayList)
            {
                LineData ld = DisasmCodeFile.DoesFileHaveAddress(bp.nextAddress.GetAddr(), bp.nextAddress.GetBank());

                DisasmCodeFile.codefile.codewindow.Lines[ld.lineNumber].MarkerAdd(BREAKPOINT_MARKER);
            }
        }
Beispiel #5
0
        // -------------------------------------------------------------------------------------------------
        // Removes the break point display described by bd
        //
        // \param   bd  The bd.
        // -------------------------------------------------------------------------------------------------
        private void RemoveBreakPointDisplay(BreakpointDisplay bd)
        {
            LineData lineData = TraceFile.GetLineDatafromAddr(bd.nextAddress);

            if (lineData != null)
            {
                lineData.tf.codefile.codewindow.Lines[lineData.lineNumber].MarkerDelete(BREAKPOINT_MARKER);
            }

            BreakpointDisplayList.Remove(bd);
        }
Beispiel #6
0
        private void ContextGotoAddress(object sender, EventArgs e)
        {
            CustomMenuItem customMenuItem = sender as CustomMenuItem;

            Labels.Label l = (Labels.Label)customMenuItem.value;

            if (l != null)
            {
                TraceFile.FocusAddr(l.nextAddress.GetAddr(), l.nextAddress.GetBank());
            }
        }
Beispiel #7
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by TextArea for margin click events. </summary>
        ///
        /// <remarks> 19/09/2018. </remarks>
        ///
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">	  Margin click event information. </param>
        /// -------------------------------------------------------------------------------------------------
        private void TextArea_MarginClick(object sender, MarginClickEventArgs e)
        {
            if (!Program.InStepMode)
            {
                return;
            }

            MarginClicked = true;

            //Console.WriteLine("TextArea_MarginClick");



            Scintilla s = (Scintilla)sender;

            if (e.Margin == CODE_MARGIN || e.Margin == BREAKPOINT_MARGIN)
            {
                const uint mask    = (1 << BREAKPOINT_MARKER);
                int        linenum = s.LineFromPosition(e.Position);
                var        line    = s.Lines[linenum];

                TraceFile tf = TraceFile.FindTraceFile((string)s.Tag);

                if ((string)s.Tag == "Dissassembly")
                {
                    tf = DisasmCodeFile;
                }

                //Section sec = FindSection((string)s.Tag);

                if (tf != null && tf.IsLineLegal(linenum))
                {
                    //Console.WriteLine("Line Ok");
                    LineData ld = tf.GetLine(linenum);

                    if ((line.MarkerGet() & mask) > 0)
                    {
                        // Remove existing breakpoint

                        Program.serialport.RemoveBreakpoint(null, ld.nextAddress.GetAddr(), ld.nextAddress.GetBank());
                        MainForm.myBreakpoints.RequestUpdate();
                    }
                    else
                    {
                        // Add breakpoint
                        Program.serialport.SetBreakpoint(null, ld.nextAddress.GetAddr(), ld.nextAddress.GetBank());
                        MainForm.myBreakpoints.RequestUpdate();

                        Console.WriteLine("Add breakpoint " + ld.nextAddress.GetAddr().ToString("X4") + " " + ld.nextAddress.GetBank());
                    }
                }
            }
        }
Beispiel #8
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by Codewindow for mouse down events. </summary>
        ///
        /// <remarks> 18/09/2018. </remarks>
        ///
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">	  Mouse event information. </param>
        /// -------------------------------------------------------------------------------------------------
        private void Codewindow_MouseDown(object sender,
                                          System.Windows.Forms.MouseEventArgs e)
        {
            Scintilla s = (Scintilla)sender;

            if (e.Button == MouseButtons.Right)
            {
                ContextMenu cm = new ContextMenu();

                int position = s.CharPositionFromPoint(e.X, e.Y);


                int linenum = s.LineFromPosition(position);
                var line    = s.Lines[linenum];

                TraceFile tf = TraceFile.FindTraceFile((string)s.Tag);
                if (tf != null)
                {
                    LineData ld   = tf.GetLine(linenum);
                    string   word = s.GetWordFromPosition(position);

                    //step mode and on valid line add a set pc option
                    if (tf.IsLineLegal(linenum) && Program.InStepMode)
                    {
                        cm.MenuItems.Add(new CustomMenuItem("Set PC to $" + ld.address.ToString("X4"), new EventHandler(ContextSetPC), (object)ld.address));
                    }

                    if (!string.IsNullOrEmpty(word))
                    {
                        Labels.Label l = Labels.FindLabel(word);
                        if (l != null)
                        {
                            if (!l.function)
                            {
                                cm.MenuItems.Add(new CustomMenuItem("Add Variable " + l.label + " to Watch", new EventHandler(ContextAddToWatch), (object)l));
                            }
                        }
                    }


                    cm.MenuItems.Add("item2");
                    //ContextMenu cm = new ContextMenu();
                    //{
                    //	MenuItem mi = new MenuItem("coming soon2 "+word);//  ,   (s, ea) => this.UndoRedo.Undo());
                    //	cm.MenuItems.Add(mi);
                    //}
                    tf.codefile.codewindow.ContextMenu = cm;
                }
            }

            Console.WriteLine("hello");
        }
Beispiel #9
0
        // -------------------------------------------------------------------------------------------------
        // Adds a break point display
        //
        // \param   longaddr    The longaddr.
        //
        // \return  A BreakpointDisplay.
        // -------------------------------------------------------------------------------------------------
        private BreakpointDisplay AddBreakPointDisplay(int longaddr)
        {
            BreakpointDisplay pd = new BreakpointDisplay();

            pd.nextAddress.SetAddressLong(longaddr);


            pd.lineData = TraceFile.GetLineDatafromAddr(pd.nextAddress);
            if (pd.lineData != null)
            {
                pd.lineData.tf.codefile.codewindow.Lines[pd.lineData.lineNumber].MarkerAdd(BREAKPOINT_MARKER);
            }

            BreakpointDisplayList.Add(pd);

            return(pd);
        }
Beispiel #10
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by Codewindow for dwell events. </summary>
        ///
        /// <remarks> 10/09/2018. </remarks>
        ///
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">	  Dwell event information. </param>
        /// -------------------------------------------------------------------------------------------------
        private void Codewindow_Dwell(object sender, DwellEventArgs e)
        {
            Scintilla s = (Scintilla)sender;

            if (s.CallTipActive)
            {
                return;
            }

            TraceFile tf = TraceFile.FindTraceFile((string)s.Tag);

            if (tf != null)
            {
                //tf.codefile.codewindow.sh
                string word = s.GetWordFromPosition(e.Position);

                DoHoverTip(s, e.Position, word);
            }
        }
Beispiel #11
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Sets a PC. </summary>
        ///
        /// <remarks> 06/09/2018. </remarks>
        ///
        /// <param name="pc"> The PC. </param>
        /// -------------------------------------------------------------------------------------------------
        public static void SetPC(int pc, int bank, bool focus = false)
        {
            if (CurrentExecuteFile != null)
            {
                if (CurrentExecuteFile.codefile != null && CurrentExecuteFile.codefile.codewindow != null)
                {
                    Line line = CurrentExecuteFile.codefile.codewindow.Lines[CurrentExecuteLine];
                    if (line != null)
                    {
                        line.MarkerDelete(SourceCodeView.EXECUTE_MARKER);
                    }
                }
                CurrentExecuteFile = null;
                CurrentExecuteLine = 0;
            }

            if (traceFiles == null)
            {
                return;
            }



            foreach (TraceFile t in traceFiles)
            {
                LineData ld = t.DoesFileHaveAddress(pc, bank);
                if (ld != null)
                {
                    MainForm.sourceCodeView.UpdateMarginAddress(t);

                    CurrentExecuteFile = t;
                    CurrentExecuteLine = ld.lineNumber;
                    Line line = t.codefile.codewindow.Lines[CurrentExecuteLine];
                    line.MarkerAdd(SourceCodeView.EXECUTE_MARKER);


                    if (focus)
                    {
                        MainForm.mySourceWindow.FocusLine(t.codefile, ld.lineNumber);
                    }
                }
            }
        }
Beispiel #12
0
            // -------------------------------------------------------------------------------------------------
            // Query if 'line' is line legal
            //
            // \param   line
            // The line.
            //
            // \return  True if line legal, false if not.
            // -------------------------------------------------------------------------------------------------
            public bool IsLineLegal(int line)
            {
                TraceFile s = TraceFile.FindTraceFile(TraceFileName);

                return(s.IsLineLegal(line));
            }
Beispiel #13
0
        // -------------------------------------------------------------------------------------------------
        // Initialises the disassembly file
        //
        // \param   tab
        // The tab.
        // -------------------------------------------------------------------------------------------------
        public void initDisassemblyFile(TabControl tab)
        {
            DisasmCodeFile = new TraceFile("Dissassembly");


            CodeFile cf = new CodeFile();

            DisasmCodeFile.codefile = cf;
            cf.TraceFileName        = "Dissassembly";


            var page = new TabPage("Dissassembly");

            cf.tab             = page;
            cf.codewindow      = new ScintillaNET.Scintilla(); //new RichTextBox();
            cf.codewindow.Dock = DockStyle.Fill;
            cf.codewindow.Tag  = (object)"Dissassembly";
            page.Controls.Add(cf.codewindow);
            tab.TabPages.Add(page);
            page.Select();

            cf.codewindow.VScrollBar = false;
            cf.codewindow.HScrollBar = false;

            cf.codewindow.SetSelectionBackColor(true, IntToColor(0x114D9C));
            cf.codewindow.TabWidth = 8;
            // Configure the default style
            cf.codewindow.StyleResetDefault();
            cf.codewindow.Styles[Style.Default].Font      = "Consolas";
            cf.codewindow.Styles[Style.Default].Size      = 14;
            cf.codewindow.Styles[Style.Default].BackColor = IntToColor(0x272822);
            cf.codewindow.Styles[Style.Default].ForeColor = IntToColor(0xFFFFFF);
            cf.codewindow.StyleClearAll();

            // Configure lexer styles
            cf.codewindow.Styles[Style.Asm.Operator].ForeColor   = IntToColor(0x48A8EE);
            cf.codewindow.Styles[Style.Asm.Identifier].ForeColor = IntToColor(0x67d9ff);

            cf.codewindow.Styles[Style.Asm.Comment].ForeColor          = Color.ForestGreen;
            cf.codewindow.Styles[Style.Asm.CommentDirective].ForeColor = Color.ForestGreen;

            cf.codewindow.Styles[Style.Asm.Number].ForeColor    = IntToColor(0x60b48a);
            cf.codewindow.Styles[Style.Asm.String].ForeColor    = Color.AliceBlue;
            cf.codewindow.Styles[Style.Asm.Character].ForeColor = Color.Aqua;


            cf.codewindow.Lexer = Lexer.Asm;
            cf.codewindow.SetKeywords(2, "hl de bc a b c h l d e hl' de' bc' af af' sp ix iy ixl ixh iyl iyh");
            cf.codewindow.Styles[Style.Asm.Register].ForeColor = IntToColor(0xdfaf8f);
            cf.codewindow.SetKeywords(3, "macro endm setbank ord pcorg equ include incbin savebin message stack end defl pc align rb rw db dw defb defw hex");
            cf.codewindow.Styles[Style.Asm.Directive].ForeColor = IntToColor(0x8ca4dc);
            cf.codewindow.SetKeywords(0, "nop inc dec ex exx djnz rrca rla jr jp call cpl scf mul halt ld add sub adc sbc and or xor cp test ret rst out in push pop swapnib ldir ldirx lddrx lddrx ldpirx ldirscale ldws mirror pixeldn pixelad setae outinb nextreg");
            cf.codewindow.Styles[Style.Asm.CpuInstruction].ForeColor = IntToColor(0xc15c95);
            cf.codewindow.Styles[Style.LineNumber].BackColor         = IntToColor(BACK_COLOR);
            cf.codewindow.Styles[Style.LineNumber].ForeColor         = IntToColor(FORE_COLOR);
            cf.codewindow.Styles[Style.IndentGuide].ForeColor        = IntToColor(FORE_COLOR);
            cf.codewindow.Styles[Style.IndentGuide].BackColor        = IntToColor(BACK_COLOR);



            //line number space
            var nums = cf.codewindow.Margins[NUMBER_MARGIN];

            nums.BackColor = Color.Black;
            nums.Width     = 30;
            nums.Type      = MarginType.Number;
            nums.Sensitive = true;
            nums.Mask      = 0;


            //addr space
            var cmargin = cf.codewindow.Margins[CODE_MARGIN];

            cmargin.Width     = 90;
            cmargin.BackColor = Color.Black;
            cmargin.Sensitive = true;
            cmargin.Type      = MarginType.Text;
            cmargin.Mask      = (1 << CODE_MARKER);
//            cmargin.BackColor = IntToColor(0xFF003B);


            //breakpoint space
            var cpmargin = cf.codewindow.Margins[BREAKPOINT_MARGIN];

            cpmargin.BackColor = Color.Black;
            cpmargin.Width     = 10;
            cpmargin.Sensitive = true;
            cpmargin.Type      = MarginType.Symbol;
            cpmargin.Mask      = (1 << BREAKPOINT_MARKER);


            var bpmarker = cf.codewindow.Markers[BREAKPOINT_MARKER];

            bpmarker.Symbol = MarkerSymbol.Circle;
            bpmarker.SetBackColor(IntToColor(0xFF003B));
            bpmarker.SetForeColor(IntToColor(0x000000));
            bpmarker.SetAlpha(100);

            cf.codewindow.MarginClick += TextArea_MarginClick;
            cf.codewindow.Click       += Codewindow_Click;
            //cf.codewindow.DwellStart += Codewindow_Dwell;
            //cf.codewindow.DwellEnd += Codewindow_DwellEnd;
            //cf.codewindow.MouseDwellTime = 1000;
            //cf.codewindow.MouseDown += Codewindow_MouseDown;
            cf.codewindow.KeyDown    += Disasm_KeyDown;
            cf.codewindow.MouseWheel += Disasm_MouseWheel;

            var ecmarker = cf.codewindow.Markers[EXECUTE_MARKER];

            ecmarker.Symbol = MarkerSymbol.RoundRect;
            ecmarker.SetBackColor(Color.DarkBlue);
            ecmarker.SetAlpha(100);

            var npmarker = cf.codewindow.Markers[NEXT_PC_MARKER];

            npmarker.Symbol = MarkerSymbol.RoundRect;
            npmarker.SetBackColor(Color.Red);
            npmarker.SetAlpha(30);
        }
Beispiel #14
0
            // -------------------------------------------------------------------------------------------------
            // Gets a line
            //
            // \param   line
            // The line.
            //
            // \return  The line.
            // -------------------------------------------------------------------------------------------------
            public LineData GetLine(int line)
            {
                TraceFile s = TraceFile.FindTraceFile(TraceFileName);

                return(s.GetLine(line));
            }
Beispiel #15
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by TextArea for margin click events. </summary>
        ///
        /// <remarks> 19/09/2018. </remarks>
        ///
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">	  Margin click event information. </param>
        /// -------------------------------------------------------------------------------------------------
        private void TextArea_MarginClick(object sender, MarginClickEventArgs e)
        {
            if (!Program.InStepMode)
            {
                return;
            }

            MarginClicked = true;

            //Console.WriteLine("TextArea_MarginClick");



            Scintilla s = (Scintilla)sender;

            if (e.Margin == CODE_MARGIN || e.Margin == BREAKPOINT_MARGIN)
            {
                const uint mask    = (1 << BREAKPOINT_MARKER);
                int        linenum = s.LineFromPosition(e.Position);
                var        line    = s.Lines[linenum];

                TraceFile tf = TraceFile.FindTraceFile((string)s.Tag);
                //Section sec = FindSection((string)s.Tag);

                if (tf != null && tf.IsLineLegal(linenum))
                {
                    //Console.WriteLine("Line Ok");
                    LineData ld = tf.GetLine(linenum);

                    //Form1.commsthread.AddCommand(Command.disassmblememory, 50, " " + ld.Addess.ToString("X4") + "H 256");


                    //now request memory and display is asm window


                    if ((line.MarkerGet() & mask) > 0)
                    {
                        // Remove existing breakpoint
                        //line.MarkerDelete(BOOKMARK_MARKER);
                        //line.MarkerDelete(BREAKPOINT_MARKER);
                        if (Breakpoint.RemoveBreakPointAtAddress(ld.address))
                        {
                        }


                        //Form1.commsthread.AddCommand(Command.direct, 76, "disable-breakpoint 1");
                    }
                    else
                    {
                        // Add breakpoint
                        if (Breakpoint.SetBreakPoint(ld.address, Breakpoint.BreakpointType.PC,
                                                     "PC=" + ld.address.ToString("X4") + "H", tf.filename, linenum))
                        {
                        }
                        //
                        //
                        //
                        //if (Program.AddBreakpoint(ld.address))
                        //{
                        //	line.MarkerAdd(BREAKPOINT_MARKER);

                        //}
                        //
                        //line.MarkerAdd(BOOKMARK_MARKER);

                        //LineData ld = cf.GetLine(linenum);

                        //Form1.commsthread.AddCommand(Command.setbreakpointaction, 76, " 1 break");
                        //Form1.commsthread.AddCommand(Command.setbreakpoint, 75, " 1 PC="+ld.Addess.ToString("x4")+"H");
                        //Form1.commsthread.AddCommand(Command.direct, 74, "enable-breakpoint 1");
                    }
                }
            }


/*			if (e.Margin == BOOKMARK_MARGIN)
 *                      {
 *
 *                              CodeFile cf = GetCodeFileFromSection((string)s.Tag);
 *
 *
 *
 *                              // Do we have a marker for this line?
 *                              const uint mask = (1 << BOOKMARK_MARKER);
 *                              int linenum = s.LineFromPosition(e.Position);
 *                              var line = s.Lines[linenum];
 *
 *
 *                              if (cf.IsLineLegal(linenum))
 *                              {
 *                                      if ((line.MarkerGet() & mask) > 0)
 *                                      {
 *                                              // Remove existing breakpoint
 *                                              line.MarkerDelete(BOOKMARK_MARKER);
 *                                              line.MarkerDelete(BREAKPOINT_MARKER);
 *
 *
 *                                              //Form1.commsthread.AddCommand(Command.direct, 76, "disable-breakpoint 1");
 *
 *
 *                                      }
 *                                      else
 *                                      {
 *                                              // Add breakpoint
 *                                              line.MarkerAdd(BOOKMARK_MARKER);
 *                                              line.MarkerAdd(BREAKPOINT_MARKER);
 *
 *                                              LineData ld = cf.GetLine(linenum);
 *
 *                                              //Form1.commsthread.AddCommand(Command.setbreakpointaction, 76, " 1 break");
 *                                              Form1.commsthread.AddCommand(Command.setbreakpoint, 75, " 1 PC="+ld.Addess.ToString("x4")+"H");
 *                                              //Form1.commsthread.AddCommand(Command.direct, 74, "enable-breakpoint 1");
 *
 *                                      }
 *
 *                              }
 *
 *
 *
 *                      }*/
        }
Beispiel #16
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by Codewindow for mouse down events. </summary>
        ///
        /// <remarks> 18/09/2018. </remarks>
        ///
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">	  Mouse event information. </param>
        /// -------------------------------------------------------------------------------------------------
        private void Codewindow_MouseDown(object sender,
                                          System.Windows.Forms.MouseEventArgs e)
        {
            Scintilla s = (Scintilla)sender;

            if (e.Button == MouseButtons.Right)
            {
                ContextMenu cm = new ContextMenu();

                int position = s.CharPositionFromPoint(e.X, e.Y);


                int linenum = s.LineFromPosition(position);
                var line    = s.Lines[linenum];

                TraceFile tf = TraceFile.FindTraceFile((string)s.Tag);
                if (tf != null)
                {
                    LineData ld   = tf.GetLine(linenum);
                    string   word = s.GetWordFromPosition(position);

                    //step mode and on valid line add a set pc option
                    if (tf.IsLineLegal(linenum) && Program.InStepMode)
                    {
                        //cm.MenuItems.Add(new CustomMenuItem( "Set PC to $"+ld.address.ToString("X4"),new EventHandler(ContextSetPC),(object)ld.address ) );

                        const uint mask = (1 << BREAKPOINT_MARKER);
                        if ((line.MarkerGet() & mask) > 0)
                        {
                            cm.MenuItems.Add(new CustomMenuItem("Clear breakpoint", new EventHandler(ContextClearBreakpoint), (object)ld.nextAddress.GetLongAddress()));
                        }
                        else
                        {
                            cm.MenuItems.Add(new CustomMenuItem("Set breakpoint", new EventHandler(ContextSetBreakpoint), (object)ld.nextAddress.GetLongAddress()));
                        }
                    }

                    if (!string.IsNullOrEmpty(word))
                    {
                        Labels.Label l = Labels.FindLabel(word);
                        if (l != null)
                        {
                            //if (!l.function)
                            //{
                            cm.MenuItems.Add(new CustomMenuItem("ADD TO WATCH: " + l.label + " " + l.nextAddress.ToString("b") + "", new EventHandler(ContextAddToWatch), (object)l));
                            cm.MenuItems.Add(new CustomMenuItem("JUMP TO: " + l.label + " " + l.nextAddress.ToString("b"), new EventHandler(ContextGotoAddress), (object)l));
                            //}
                        }
                    }


                    //cm.MenuItems.Add("item3");
                    //ContextMenu cm = new ContextMenu();
                    //{
                    //	MenuItem mi = new MenuItem("coming soon2 "+word);//  ,   (s, ea) => this.UndoRedo.Undo());
                    //	cm.MenuItems.Add(mi);
                    //}
                    tf.codefile.codewindow.ContextMenu = cm;
                }
            }
        }
Beispiel #17
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Sets a PC. </summary>
        ///
        /// <remarks> 06/09/2018. </remarks>
        ///
        /// <param name="pc"> The PC. </param>
        /// -------------------------------------------------------------------------------------------------
        public static void SetPC(int pc, bool focus = false)
        {
            if (CurrentExecuteFile != null)
            {
                if (CurrentExecuteFile.codefile != null && CurrentExecuteFile.codefile.codewindow != null)
                {
                    Line line = CurrentExecuteFile.codefile.codewindow.Lines[CurrentExecuteLine];
                    if (line != null)
                    {
                        line.MarkerDelete(SourceCodeView.EXECUTE_MARKER);
                    }
                }
                CurrentExecuteFile = null;
                CurrentExecuteLine = 0;
            }

            if (traceFiles == null)
            {
                return;
            }


            int bank = MainForm.banks[GetBankIndex(pc)];

            foreach (TraceFile t in traceFiles)
            {
                LineData ld = t.DoesFileHaveAddress(pc, bank);
                if (ld != null)
                {
                    CurrentExecuteFile = t;
                    CurrentExecuteLine = ld.lineNumber;
                    var line = t.codefile.codewindow.Lines[CurrentExecuteLine];
                    line.MarkerAdd(SourceCodeView.EXECUTE_MARKER);


                    if (focus)
                    {
                        MainForm.mySourceWindow.FocusLine(t.codefile, ld.lineNumber);
                    }
                }
            }



/*			if (CurrentExecuteLine>=0)
 *                      {
 *                              Section s = FindSection(CurrentExecuteSection);
 *                              CodeFile cf = GetCodeFileFromSection(CurrentExecuteSection);
 *
 *                              var line = cf.codewindow.Lines[CurrentExecuteLine];
 *                              line.MarkerDelete(EXECUTE_MARKER);
 *
 *                              CurrentExecuteLine = -1;
 *                      }
 *
 *
 *
 *                      foreach (Section s in Sections)
 *                      {
 *                              LineData ld = s.DoesSectionHaveAddress(address);
 *                              if (ld != null)
 *                              {
 *                                      CodeFile cf = GetCodeFileFromSection(s.section);
 *
 *                                      var line = cf.codewindow.Lines[(int)ld.lineNumber];
 *                                      line.MarkerAdd(EXECUTE_MARKER);
 *
 *                                      CurrentExecuteLine = (int)ld.lineNumber;
 *                                      CurrentExecuteSection = s.section;
 *
 *                                      Console.WriteLine("Focus Line!");
 *                                      Form1.Instance.SourceTab.SelectedTab = cf.tab;
 *                                      cf.codewindow.Lines[(int)ld.lineNumber].EnsureVisible();
 *
 *                                      int linesOnScreen = cf.codewindow.LinesOnScreen - 2; // Fudge factor
 *
 *                                      int linenum = (int)ld.lineNumber;
 *                                      var start = cf.codewindow.Lines[linenum - (linesOnScreen / 2)].Position;
 *                                      var end = cf.codewindow.Lines[linenum + (linesOnScreen / 2)].Position;
 *
 *                                      cf.codewindow.ScrollRange(start, end);
 *
 *                                      //Form1.Instance.FocusOnFile(s, ld.lineNumber);
 *
 *                                      return;
 *                              }
 *                      }*/
        }
Beispiel #18
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary> Parse trace data. </summary>
        ///
        /// <remarks> 06/09/2018. </remarks>
        ///
        /// <param name="filename"> Filename of the file. </param>
        /// -------------------------------------------------------------------------------------------------
        public static void ParseTraceData(string filename)
        {
            //z80.asm|25|5|32828
            traceFiles = new List <TraceFile>();

            string filenameregexchars = @"[_a-zA-Z0-9\\., :/@#$%^(){}\[\]!+=~-]";
            Regex  registersregex     = new Regex(
                @"^(?<filename>" + filenameregexchars + @"*)\|"
                + @"(?<line>[0-9:]+)\|"
                + @"(?<macrofile>" + filenameregexchars + @"*)\|"
                + @"(?<macroline>[0-9:]+)\|"
                + @"(?<bank>-?[0-9]+)\|"
                + @"(?<value>-?[0-9]+)\|"
                + @"(?<type>[LFTDZ])\|"
                + @"(?<label>.*)"
                );



            int index = 0;

            string[] lines = File.ReadAllLines(filename);

            foreach (string s in lines)
            {
                index++;
                if (!string.IsNullOrEmpty(s))
                {
                    if (s.StartsWith("||"))
                    {
                        Console.WriteLine("# comment: " + s.Substring(2));
                        continue;
                    }
                    if (s.StartsWith("|SLD.data.version|"))
                    {
                        var sldversion = s.Substring(18);
                        if (!"0".Equals(sldversion))
                        {
                            Console.WriteLine("# Unknown SLD version: " + sldversion);
                            //TODO some warning about unsupported SLD version
                        }
                        continue;
                    }
                    var match = registersregex.Match(s);
                    if (!match.Success)
                    {
                        Console.WriteLine("! matching failed for line: " + s);
                        continue;
                    }
                    Console.WriteLine(s);
                    //Console.WriteLine(match.Groups["label"] + " " + match.Groups["address"] + " " + match.Groups["type"] + " " + match.Groups["section"]);

                    string mfn   = match.Groups["macrofile"].ToString();
                    var    mline = ParseLineNumber(match.Groups["macroline"].ToString());

                    string fn    = match.Groups["filename"].ToString();
                    string label = match.Groups["label"].ToString();

                    int bank = 0;
                    int.TryParse(match.Groups["bank"].ToString(), NumberStyles.Integer, null, out bank);
                    var line  = ParseLineNumber(match.Groups["line"].ToString());
                    int value = 0;
                    int.TryParse(match.Groups["value"].ToString(), NumberStyles.Integer, null, out value);



                    if (match.Groups["type"].ToString() == "T")                         //Trace Data
                    {
                        fn = Path.GetFileName(fn);

                        TraceFile tracefile = TraceFile.FindTraceFile(fn);
                        if (tracefile == null)
                        {
                            Console.WriteLine("Adding file " + fn);
                            tracefile = new TraceFile(fn);
                            traceFiles.Add(tracefile);
                        }



                        //found source level debug symbol
                        LineData ld = new LineData();

                        //ld.address = addr;
                        //ld.bank = bank;
                        ld.lineNumber  = line.Item1 - 1;
                        ld.nextAddress = new NextAddress(value, bank);
                        ld.tf          = tracefile;

                        tracefile.lines.Add(ld);
                    }
                    else if (match.Groups["type"].ToString() == "L")                            //Label
                    {
                        Labels.AddLabel(label, value, bank, false, false);
                    }
                    else if (match.Groups["type"].ToString() == "D")        //Define
                    {
                        Labels.AddLabel(label, value, bank, false, true);
                    }
                    else if (match.Groups["type"].ToString() == "F")                            //Function
                    {
                        Labels.AddLabel(label, value, bank, true, false);
                    }
                }
            }
        }