private void RefreshLog(bool scrollToBottom, bool forceUpdate)
        {
            if (_refreshRunning)
            {
                return;
            }

            //Make sure labels are up to date
            DebugWorkspaceManager.GetWorkspace();

            _refreshRunning = true;
            SetOptions();
            Task.Run(() => {
                //Update trace log in another thread for performance
                DebugState state = new DebugState();
                InteropEmu.DebugGetState(ref state);
                if (_previousCycleCount != state.CPU.CycleCount || forceUpdate)
                {
                    string newTrace     = InteropEmu.DebugGetExecutionTrace((UInt32)_lineCount);
                    _previousCycleCount = state.CPU.CycleCount;
                    _previousTrace      = newTrace;

                    int index            = 0;
                    string line          = null;
                    Func <bool> readLine = () => {
                        if (index < newTrace.Length)
                        {
                            int endOfLineIndex = newTrace.IndexOf('\n', index);
                            line  = newTrace.Substring(index, endOfLineIndex - index);
                            index = endOfLineIndex + 1;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    };

                    List <int> programCounter = new List <int>(30000);
                    List <string> byteCode    = new List <string>(30000);
                    List <string> lineContent = new List <string>(30000);
                    List <int> indent         = new List <int>(30000);

                    bool showByteCode = false;
                    while (readLine())
                    {
                        string[] parts = line.Split('\x1');
                        programCounter.Add(Int32.Parse(parts[0], System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(parts[1]);

                        string content = parts[2];
                        while (true)
                        {
                            string str = content.TrimStart();
                            if (str.StartsWith(parts[0]))
                            {
                                content = str.Substring(4);
                            }
                            else if (str.StartsWith(parts[1]))
                            {
                                content      = str.Substring(11);
                                showByteCode = true;
                            }
                            else if (str.StartsWith(parts[1].Replace("$", "")))
                            {
                                content      = str.Substring(8);
                                showByteCode = true;
                            }
                            else
                            {
                                break;
                            }
                        }
                        lineContent.Add(content);
                        indent.Add(0);
                    }
                    this.BeginInvoke((Action)(() => {
                        txtTraceLog.ShowContentNotes = showByteCode;
                        txtTraceLog.ShowSingleContentLineNotes = showByteCode;

                        txtTraceLog.LineIndentations = indent.ToArray();
                        txtTraceLog.LineNumbers = programCounter.ToArray();
                        txtTraceLog.TextLineNotes = byteCode.ToArray();
                        txtTraceLog.TextLines = lineContent.ToArray();

                        if (scrollToBottom)
                        {
                            txtTraceLog.ScrollToLineIndex(txtTraceLog.LineCount - 1);
                        }
                    }));
                }
                _refreshRunning = false;
            });
        }
Exemple #2
0
        private void RefreshLog(bool scrollToBottom)
        {
            if (_refreshRunning)
            {
                return;
            }

            //Make sure labels are up to date
            DebugWorkspaceManager.GetWorkspace();

            _refreshRunning = true;
            SetOptions();
            Task.Run(() => {
                //Update trace log in another thread for performance
                DebugState state = new DebugState();
                InteropEmu.DebugGetState(ref state);
                if (_previousCycleCount != state.CPU.CycleCount)
                {
                    string newTrace     = InteropEmu.DebugGetExecutionTrace((UInt32)_lineCount);
                    _previousCycleCount = state.CPU.CycleCount;
                    _previousTrace      = newTrace;

                    int index            = 0;
                    string line          = null;
                    Func <bool> readLine = () => {
                        if (index < newTrace.Length)
                        {
                            int endOfLineIndex = newTrace.IndexOf('\n', index);
                            line  = newTrace.Substring(index, endOfLineIndex - index);
                            index = endOfLineIndex + 1;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    };

                    List <int> programCounter = new List <int>(30000);
                    List <string> byteCode    = new List <string>(30000);
                    List <string> lineContent = new List <string>(30000);
                    List <int> indent         = new List <int>(30000);

                    char[] splitter = new char[] { ' ' };
                    while (readLine())
                    {
                        programCounter.Add(Int32.Parse(line.Substring(0, 4), System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(line.Substring(6, 11));
                        lineContent.Add(line.Substring(19));
                        indent.Add(6);
                    }
                    this.BeginInvoke((Action)(() => {
                        txtTraceLog.ShowContentNotes = chkShowByteCode.Checked;
                        txtTraceLog.ShowSingleContentLineNotes = chkShowByteCode.Checked;

                        txtTraceLog.LineIndentations = indent.ToArray();
                        txtTraceLog.LineNumbers = programCounter.ToArray();
                        txtTraceLog.TextLineNotes = byteCode.ToArray();
                        txtTraceLog.TextLines = lineContent.ToArray();

                        if (scrollToBottom)
                        {
                            txtTraceLog.ScrollToLineIndex(txtTraceLog.LineCount - 1);
                        }
                    }));
                }
                _refreshRunning = false;
            });
        }