Пример #1
0
        private InteropTraceLoggerOptions GetInteropOptions(bool disableLogging = false)
        {
            _entityBinder.UpdateObject();
            TraceLoggerOptions options = (TraceLoggerOptions)_entityBinder.Entity;

            CoprocessorType coproc = EmuApi.GetRomInfo().CoprocessorType;

            InteropTraceLoggerOptions interopOptions = new InteropTraceLoggerOptions();

            interopOptions.LogCpu         = !disableLogging && options.LogCpu && coproc != CoprocessorType.Gameboy;
            interopOptions.LogSpc         = !disableLogging && options.LogSpc && coproc != CoprocessorType.Gameboy;
            interopOptions.LogNecDsp      = !disableLogging && options.LogNecDsp;
            interopOptions.LogSa1         = !disableLogging && options.LogSa1;
            interopOptions.LogGsu         = !disableLogging && options.LogGsu;
            interopOptions.LogCx4         = !disableLogging && options.LogCx4;
            interopOptions.LogGameboy     = !disableLogging && options.LogGameboy;
            interopOptions.IndentCode     = options.IndentCode;
            interopOptions.ShowExtraInfo  = options.ShowExtraInfo;
            interopOptions.UseLabels      = options.UseLabels;
            interopOptions.UseWindowsEol  = options.UseWindowsEol;
            interopOptions.ExtendZeroPage = options.ExtendZeroPage;

            interopOptions.Condition = Encoding.UTF8.GetBytes(txtCondition.Text);
            Array.Resize(ref interopOptions.Condition, 1000);

            interopOptions.Format = Encoding.UTF8.GetBytes(txtFormat.Text.Replace("\t", "\\t"));
            Array.Resize(ref interopOptions.Format, 1000);

            return(interopOptions);
        }
Пример #2
0
        private void SetOptions(bool disableLogging = false)
        {
            _entityBinder.UpdateObject();
            TraceLoggerOptions options = (TraceLoggerOptions)_entityBinder.Entity;

            _interopOptions                = new InteropTraceLoggerOptions();
            _interopOptions.LogCpu         = !disableLogging && options.LogCpu;
            _interopOptions.LogSpc         = !disableLogging && options.LogSpc;
            _interopOptions.LogNecDsp      = !disableLogging && options.LogNecDsp;
            _interopOptions.LogSa1         = !disableLogging && options.LogSa1;
            _interopOptions.LogGsu         = !disableLogging && options.LogGsu;
            _interopOptions.LogCx4         = !disableLogging && options.LogCx4;
            _interopOptions.IndentCode     = options.IndentCode;
            _interopOptions.ShowExtraInfo  = options.ShowExtraInfo;
            _interopOptions.UseLabels      = options.UseLabels;
            _interopOptions.UseWindowsEol  = options.UseWindowsEol;
            _interopOptions.ExtendZeroPage = options.ExtendZeroPage;

            _interopOptions.Condition = Encoding.UTF8.GetBytes(txtCondition.Text);
            Array.Resize(ref _interopOptions.Condition, 1000);

            _interopOptions.Format = Encoding.UTF8.GetBytes(txtFormat.Text.Replace("\t", "\\t"));
            Array.Resize(ref _interopOptions.Format, 1000);

            DebugApi.SetTraceOptions(_interopOptions);
        }
        private void SetOptions()
        {
            _entityBinder.UpdateObject();
            TraceLoggerOptions options = (TraceLoggerOptions)_entityBinder.Entity;

            InteropTraceLoggerOptions interopOptions = new InteropTraceLoggerOptions();

            interopOptions.IndentCode     = options.IndentCode;
            interopOptions.ShowExtraInfo  = options.ShowExtraInfo;
            interopOptions.UseLabels      = options.UseLabels;
            interopOptions.UseWindowsEol  = options.UseWindowsEol;
            interopOptions.ExtendZeroPage = options.ExtendZeroPage;

            interopOptions.Condition = Encoding.UTF8.GetBytes(txtCondition.Text);
            Array.Resize(ref interopOptions.Condition, 1000);

            interopOptions.Format = Encoding.UTF8.GetBytes(txtFormat.Text.Replace("\t", "\\t"));
            Array.Resize(ref interopOptions.Format, 1000);

            InteropEmu.DebugSetTraceOptions(interopOptions);
        }
Пример #4
0
        private void btnStartLogging_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog()) {
                sfd.SetFilter("Trace logs (*.txt)|*.txt");
                sfd.FileName         = "Trace.txt";
                sfd.InitialDirectory = ConfigManager.DebuggerFolder;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    _lastFilename   = sfd.FileName;
                    _interopOptions = GetInteropOptions();
                    SetCoreOptions();
                    DebugApi.StartTraceLogger(sfd.FileName);

                    btnStartLogging.Enabled = false;
                    btnStopLogging.Enabled  = true;
                    btnOpenTrace.Enabled    = false;

                    _loggingEnabled = true;
                }
            }
        }
Пример #5
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            _notifListener?.Dispose();

            tmrUpdateLog.Stop();
            while (_refreshRunning)
            {
                System.Threading.Thread.Sleep(50);
            }

            base.OnFormClosing(e);

            TraceLoggerInfo config = ConfigManager.Config.Debug.TraceLogger;

            config.AutoRefresh    = mnuAutoRefresh.Checked;
            config.LineCount      = _lineCount;
            config.WindowSize     = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
            config.WindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;

            config.FontFamily = txtTraceLog.BaseFont.FontFamily.Name;
            config.FontSize   = txtTraceLog.BaseFont.Size;
            config.FontStyle  = txtTraceLog.BaseFont.Style;
            config.TextZoom   = txtTraceLog.TextZoom;

            _entityBinder.UpdateObject();

            //Disable logging when we close the trace logger
            _interopOptions = GetInteropOptions(true);
            SetCoreOptions();

            ConfigManager.ApplyChanges();

            if (_loggingEnabled)
            {
                DebugApi.StopTraceLogger();
            }
        }
Пример #6
0
        private void RefreshLog(bool scrollToBottom, bool forceUpdate)
        {
            if (_refreshRunning)
            {
                return;
            }

            _refreshRunning = true;
            _interopOptions = GetInteropOptions();
            Task.Run(() => {
                SetCoreOptions();

                //Update trace log in another thread for performance
                DebugState state = DebugApi.GetState();
                if (_previousMasterClock != state.MasterClock || forceUpdate)
                {
                    string newTrace      = DebugApi.GetExecutionTrace((UInt32)_lineCount);
                    _previousMasterClock = state.MasterClock;
                    _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> lineFlags      = new List <int>(30000);
                    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');
                        lineFlags.Add((int)parts[0][0]);
                        programCounter.Add(Int32.Parse(parts[1], System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(parts[2]);

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

                        txtTraceLog.DataProvider = new TraceLoggerCodeDataProvider(lineContent, programCounter, byteCode, lineFlags);
                        txtTraceLog.StyleProvider = new TraceLoggerStyleProvider(lineFlags);

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