Ejemplo n.º 1
0
        private void picViewer_MouseMove(object sender, MouseEventArgs e)
        {
            Point pos = GetCycleScanline(e.Location);

            if (_lastPos == pos)
            {
                return;
            }

            EventViewerDisplayOptions options    = GetInteropOptions();
            DebugEventInfo            debugEvent = new DebugEventInfo();

            InteropEmu.GetEventViewerEvent(ref debugEvent, (Int16)(pos.Y - 1), (UInt16)pos.X, options);
            if (debugEvent.ProgramCounter == 0xFFFFFFFF)
            {
                ResetTooltip();
                UpdateOverlay(e.Location);
                return;
            }

            Dictionary <string, string> values = new Dictionary <string, string>()
            {
                { "Type", ResourceHelper.GetEnumText(debugEvent.Type) },
                { "Scanline", debugEvent.Scanline.ToString() },
                { "Cycle", debugEvent.Cycle.ToString() },
                { "PC", "$" + debugEvent.ProgramCounter.ToString("X4") },
            };

            switch (debugEvent.Type)
            {
            case DebugEventType.MapperRegisterRead:
            case DebugEventType.MapperRegisterWrite:
            case DebugEventType.PpuRegisterRead:
            case DebugEventType.PpuRegisterWrite:
                values["Register"] = "$" + debugEvent.Address.ToString("X4");
                values["Value"]    = "$" + debugEvent.Value.ToString("X2");

                if (debugEvent.PpuLatch >= 0)
                {
                    values["2nd Write"] = debugEvent.PpuLatch == 0 ? "false" : "true";
                }
                break;

            case DebugEventType.DmcDmaRead:
                values["Address"] = "$" + debugEvent.Address.ToString("X4");
                values["Value"]   = "$" + debugEvent.Value.ToString("X2");
                break;

            case DebugEventType.Breakpoint:
                ReadOnlyCollection <Breakpoint> breakpoints = BreakpointManager.Breakpoints;
                if (debugEvent.BreakpointId >= 0 && debugEvent.BreakpointId < breakpoints.Count)
                {
                    Breakpoint bp = breakpoints[debugEvent.BreakpointId];
                    values["BP Type"]      = bp.ToReadableType();
                    values["BP Addresses"] = bp.GetAddressString(true);
                    if (bp.Condition.Length > 0)
                    {
                        values["BP Condition"] = bp.Condition;
                    }
                }
                break;
            }

            ResetTooltip();
            UpdateOverlay(new Point((int)(debugEvent.Cycle * 2 * picViewer.ImageScale), (int)((debugEvent.Scanline + 1) * 2 * picViewer.ImageScale)));

            Form parentForm = this.FindForm();

            _tooltip             = new frmCodeTooltip(parentForm, values, null, null, null, 10);
            _tooltip.FormClosed += (s, evt) => { _tooltip = null; };
            Point location = Control.MousePosition;

            location.Offset(10, 10);
            _tooltip.SetFormLocation(location, this);
        }
Ejemplo n.º 2
0
        private void picPicture_MouseMove(object sender, MouseEventArgs e)
        {
            int cycle    = e.X * 341 / (picPicture.Width - 2);
            int scanline = e.Y * (int)_state.PPU.ScanlineCount / (picPicture.Height - 2) - 1;

            int[] offsets = new int[3] {
                0, -1, 1
            };

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    int key = (scanline + offsets[y] + 1) * 341 + cycle + offsets[x];

                    List <DebugEventInfo> eventList;
                    if (_debugEventsByCycle.TryGetValue(key, out eventList))
                    {
                        foreach (DebugEventInfo debugEvent in eventList)
                        {
                            if (ShowEvent(debugEvent.Type))
                            {
                                if (key != _lastKey)
                                {
                                    ResetTooltip();

                                    Dictionary <string, string> values = new Dictionary <string, string>()
                                    {
                                        { "Type", ResourceHelper.GetEnumText(debugEvent.Type) },
                                        { "Scanline", debugEvent.Scanline.ToString() },
                                        { "Cycle", debugEvent.Cycle.ToString() },
                                        { "PC", "$" + debugEvent.ProgramCounter.ToString("X4") },
                                    };

                                    switch (debugEvent.Type)
                                    {
                                    case DebugEventType.MapperRegisterRead:
                                    case DebugEventType.MapperRegisterWrite:
                                    case DebugEventType.PpuRegisterRead:
                                    case DebugEventType.PpuRegisterWrite:
                                        values["Register"] = "$" + debugEvent.Address.ToString("X4");
                                        values["Value"]    = "$" + debugEvent.Value.ToString("X2");

                                        if (debugEvent.PpuLatch >= 0)
                                        {
                                            values["2nd Write"] = debugEvent.PpuLatch == 0 ? "false" : "true";
                                        }
                                        break;

                                    case DebugEventType.Breakpoint:
                                        ReadOnlyCollection <Breakpoint> breakpoints = BreakpointManager.Breakpoints;
                                        if (debugEvent.BreakpointId >= 0 && debugEvent.BreakpointId < breakpoints.Count)
                                        {
                                            Breakpoint bp = breakpoints[debugEvent.BreakpointId];
                                            values["BP Type"]      = bp.ToReadableType();
                                            values["BP Addresses"] = bp.GetAddressString(true);
                                            if (bp.Condition.Length > 0)
                                            {
                                                values["BP Condition"] = bp.Condition;
                                            }
                                        }
                                        break;
                                    }

                                    Form parentForm = this.FindForm();
                                    _tooltip             = new frmCodeTooltip(parentForm, values);
                                    _tooltip.FormClosed += (s, evt) => { _tooltip = null; };
                                    Point location = PointToScreen(e.Location);
                                    location.Offset(10, 10);
                                    _tooltip.SetFormLocation(location, this);
                                    _lastKey = key;
                                }

                                //Found a matching write to display, stop processing
                                return;
                            }
                        }
                    }
                }
            }

            //No match found, make sure any existing tooltip is closed
            ResetTooltip();
        }