예제 #1
0
파일: ctrlChrViewer.cs 프로젝트: Rysm/Mesen
        private void ctxMenu_Opening(object sender, CancelEventArgs e)
        {
            int  baseAddress = _bottomBank ? 0x1000 : 0x0000;
            bool ppuMemory   = this.cboChrSelection.SelectedIndex == 0;

            if (this.cboChrSelection.SelectedIndex > 1)
            {
                baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000;
            }

            int tileIndex = GetLargeSpriteIndex(_tileIndex);

            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isChrRam)
            {
                for (int i = 0; i < 16; i++)
                {
                    sb.Append(InteropEmu.DebugGetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + i)).ToString("X2"));
                }
            }
            else
            {
                int absoluteTileIndex = ppuMemory ? InteropEmu.DebugGetAbsoluteChrAddress((uint)(baseAddress + tileIndex * 16)) / 16 : (baseAddress / 16 + tileIndex);
                sb.Append(absoluteTileIndex.ToString());
            }
            sb.Append(",");
            for (int i = 0; i < 4; i++)
            {
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(this._selectedPalette * 4 + i)).ToString("X2"));
            }

            _copyData = sb.ToString();
        }
예제 #2
0
        private void ctrlCodeViewer_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Location.X < this.ctrlCodeViewer.CodeMargin / 5)
            {
                this.ContextMenuStrip = contextMenuMargin;
            }
            else
            {
                this.ContextMenuStrip = contextMenuCode;
            }

            if (_previousLocation != e.Location)
            {
                string word = GetWordUnderLocation(e.Location);
                if (word.StartsWith("$"))
                {
                    UInt32 address     = UInt32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier);
                    Byte   memoryValue = InteropEmu.DebugGetMemoryValue(address);
                    string valueText   = "$" + memoryValue.ToString("X");
                    toolTip.Show(valueText, ctrlCodeViewer, e.Location.X + 5, e.Location.Y - 20, 3000);
                }
                else
                {
                    toolTip.Hide(ctrlCodeViewer);
                }
                _previousLocation = e.Location;
            }
        }
예제 #3
0
        private void UpdateVectorAddresses()
        {
            bool isNsf = InteropEmu.GetRomInfo().Format == RomFormat.Nsf;

            if (isNsf)
            {
                NsfHeader header = InteropEmu.NsfGetHeader();
                mnuGoToInitHandler.Text = "Init Handler ($" + header.InitAddress.ToString("X4") + ")";
                mnuGoToPlayHandler.Text = "Play Handler ($" + header.PlayAddress.ToString("X4") + ")";
            }
            else
            {
                int nmiHandler   = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
                int resetHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFC) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFD) << 8);
                int irqHandler   = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

                mnuGoToNmiHandler.Text   = "NMI Handler ($" + nmiHandler.ToString("X4") + ")";
                mnuGoToResetHandler.Text = "Reset Handler ($" + resetHandler.ToString("X4") + ")";
                mnuGoToIrqHandler.Text   = "IRQ Handler ($" + irqHandler.ToString("X4") + ")";
            }

            mnuGoToInitHandler.Visible  = isNsf;
            mnuGoToPlayHandler.Visible  = isNsf;
            mnuGoToIrqHandler.Visible   = !isNsf;
            mnuGoToNmiHandler.Visible   = !isNsf;
            mnuGoToResetHandler.Visible = !isNsf;
        }
예제 #4
0
 private void UpdateStack(UInt16 stackPointer)
 {
     lstStack.Items.Clear();
     for (UInt32 i = (UInt32)0x100 + stackPointer; i < 0x200; i++)
     {
         lstStack.Items.Add("$" + InteropEmu.DebugGetMemoryValue(i).ToString("X"));
     }
 }
예제 #5
0
        private void UpdateVectorAddresses()
        {
            int nmiHandler   = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
            int resetHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFC) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFD) << 8);
            int irqHandler   = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

            mnuGoToNmiHandler.Text   = "NMI Handler ($" + nmiHandler.ToString("X4") + ")";
            mnuGoToResetHandler.Text = "Reset Handler ($" + resetHandler.ToString("X4") + ")";
            mnuGoToIrqHandler.Text   = "IRQ Handler ($" + irqHandler.ToString("X4") + ")";
        }
예제 #6
0
        private string GetTileKey(int nametableIndex, int index)
        {
            byte tileIndex = _tileData[nametableIndex][index];

            for (int i = 0; i < 16; i++)
            {
                _tmpTileData[i] = InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (UInt32)(_state.PPU.ControlFlags.BackgroundPatternAddr + tileIndex * 16 + i));
            }

            return(ctrlCharacterMapping.GetColorIndependentKey(_tmpTileData));
        }
예제 #7
0
        public string ToHdPackFormat(int tileAddr, int palette, bool forSprite, bool isAbsoluteAddress)
        {
            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isAbsoluteAddress)
            {
                if (isChrRam)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.ChrRam, (uint)(tileAddr + i)).ToString("X2"));
                    }
                }
                else
                {
                    sb.Append((tileAddr / 16).ToString());
                }
            }
            else
            {
                if (isChrRam)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        sb.Append(_ppuMemory[tileAddr + i].ToString("X2"));
                    }
                }
                else
                {
                    sb.Append(_absoluteTileIndexes[tileAddr / 16].ToString("X2"));
                }
            }

            if (forSprite)
            {
                sb.Append(",FF");
                for (int i = 1; i < 4; i++)
                {
                    sb.Append(_paletteRam[palette * 4 + i].ToString("X2"));
                }
            }
            else
            {
                sb.Append(",");
                for (int i = 0; i < 4; i++)
                {
                    sb.Append(_paletteRam[palette * 4 + i].ToString("X2"));
                }
            }

            return(sb.ToString());
        }
예제 #8
0
        public frmOpCodeTooltip(Form parent, string opcode, int relativeAddress)
        {
            _parentForm = parent;
            InitializeComponent();

            OpCodeDesc desc = _descriptions[opcode.ToLowerInvariant()];

            if (relativeAddress >= 0)
            {
                byte opCode = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress);
                int  opSize = GetOpSize(opCode);

                string byteCode = "";
                for (int i = 0; i < opSize; i++)
                {
                    byte value = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)(relativeAddress + i));
                    byteCode += "$" + value.ToString("X2") + " ";
                }

                lblByteCode.Text       = byteCode;
                lblAddressingMode.Text = ResourceHelper.GetEnumText(AddressingModes[opCode]);
                lblCycleCount.Text     = OpCycles[opCode].ToString();
                if (OpCycles[opCode] != OpCyclesCrossed[opCode])
                {
                    lblCycleCount.Text += $" ({OpCyclesCrossed[opCode]} if page crossed)";
                }
            }
            else
            {
                tlpOpCodeInfo.Visible = false;
            }

            ctrlFlagCarry.Letter     = "C";
            ctrlFlagDecimal.Letter   = "D";
            ctrlFlagInterrupt.Letter = "I";
            ctrlFlagNegative.Letter  = "N";
            ctrlFlagOverflow.Letter  = "V";
            ctrlFlagZero.Letter      = "Z";

            lblName.Text = desc.Name;
            lblOpCodeDescription.Text = desc.Description;

            ctrlFlagCarry.Active     = desc.Flags.HasFlag(CpuFlag.Carry);
            ctrlFlagDecimal.Active   = desc.Flags.HasFlag(CpuFlag.Decimal);
            ctrlFlagInterrupt.Active = desc.Flags.HasFlag(CpuFlag.Interrupt);
            ctrlFlagNegative.Active  = desc.Flags.HasFlag(CpuFlag.Negative);
            ctrlFlagOverflow.Active  = desc.Flags.HasFlag(CpuFlag.Overflow);
            ctrlFlagZero.Active      = desc.Flags.HasFlag(CpuFlag.Zero);

            this.TopLevel = false;
            this.Parent   = _parentForm;
            _parentForm.Controls.Add(this);
        }
예제 #9
0
 private void UpdateStack(UInt16 stackPointer)
 {
     lstStack.BeginUpdate();
     lstStack.Items.Clear();
     ListViewItem[] itemsToAdd = new ListViewItem[256 - stackPointer];
     for (UInt32 i = (UInt32)0x100 + stackPointer; i < 0x200; i++)
     {
         itemsToAdd[i - stackPointer - 0x100] = new ListViewItem("$" + InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, i).ToString("X2"));
     }
     lstStack.Items.AddRange(itemsToAdd);
     lstStack.EndUpdate();
 }
예제 #10
0
        private void DisplayAddressTooltip(string word, UInt32 address)
        {
            byte   byteValue = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address);
            UInt16 wordValue = (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address + 1) << 8));

            var values = new Dictionary <string, string>()
            {
                { "Address", "$" + address.ToString("X4") },
                { "Value", $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" }
            };

            ShowTooltip(word, values);
        }
예제 #11
0
        private void ctxMenu_Opening(object sender, CancelEventArgs e)
        {
            if (_selectedSprite < 0)
            {
                _contextMenuSpriteIndex = -1;
                return;
            }

            _contextMenuSpriteIndex = _selectedSprite;

            int ramAddr   = _selectedSprite * 4;
            int spriteY   = _spriteRam[ramAddr];
            int tileIndex = _spriteRam[ramAddr + 1];
            int palette   = (_spriteRam[ramAddr + 2] & 0x03) + 4;
            int spriteX   = _spriteRam[ramAddr + 3];

            int tileAddr;

            if (_largeSprites)
            {
                tileAddr = ((tileIndex & 0x01) == 0x01 ? 0x1000 : 0x0000) + ((tileIndex & 0xFE) << 4);
            }
            else
            {
                tileAddr = _spritePatternAddr + (tileIndex << 4);
            }

            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isChrRam)
            {
                for (int i = 0; i < 16; i++)
                {
                    sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (UInt32)(tileAddr + i)).ToString("X2"));
                }
            }
            else
            {
                int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16;
                sb.Append(absoluteTileIndex.ToString());
            }
            sb.Append(",FF");
            for (int i = 1; i < 4; i++)
            {
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(palette * 4 + i)).ToString("X2"));
            }

            _copyData = sb.ToString();
        }
예제 #12
0
파일: ctrlCallstack.cs 프로젝트: Rysm/Mesen
        private List <StackInfo> GetStackInfo()
        {
            int nmiHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
            int irqHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

            InteropEmu.DebugGetCallstack(out _absoluteCallstack, out _relativeCallstack);
            DebugState state = new DebugState();

            InteropEmu.DebugGetState(ref state);
            _programCounter = state.CPU.DebugPC;

            int relDestinationAddr = -1, absDestinationAddr = -1;

            List <StackInfo> stack = new List <StackInfo>();

            for (int i = 0, len = _relativeCallstack.Length; i < len; i += 2)
            {
                if (_relativeCallstack[i] == -2)
                {
                    break;
                }

                int relSubEntryAddr = i == 0 ? -1 : _relativeCallstack[i - 1] & 0xFFFF;
                int absSubEntryAddr = i == 0 ? -1 : _absoluteCallstack[i - 1];

                stack.Add(new StackInfo()
                {
                    SubName             = this.GetFunctionName(relSubEntryAddr, absSubEntryAddr, nmiHandler, irqHandler),
                    IsMapped            = (_relativeCallstack[i] & 0x10000) != 0x10000,
                    CurrentRelativeAddr = _relativeCallstack[i] & 0xFFFF,
                    CurrentAbsoluteAddr = _absoluteCallstack[i]
                });

                relDestinationAddr = _relativeCallstack[i + 1] & 0xFFFF;
                absDestinationAddr = _absoluteCallstack[i + 1];
            }

            //Add current location
            stack.Add(new StackInfo()
            {
                SubName             = this.GetFunctionName(relDestinationAddr, absDestinationAddr, nmiHandler, irqHandler),
                IsMapped            = true,
                CurrentRelativeAddr = _programCounter,
                CurrentAbsoluteAddr = InteropEmu.DebugGetAbsoluteAddress((UInt32)_programCounter)
            });

            return(stack);
        }
예제 #13
0
        public void DisplayAddressTooltip(string word, UInt32 address)
        {
            byte   byteValue = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address);
            UInt16 wordValue = (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address + 1) << 8));

            var values = new Dictionary <string, string>()
            {
                { "Address", "$" + address.ToString("X4") },
                { "Value", $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" }
            };

            AddressTypeInfo addressInfo = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType(address, addressInfo);
            this.ShowTooltip(word, values, -1, addressInfo);
        }
예제 #14
0
        private void UpdateStack(UInt16 stackPointer)
        {
            StringBuilder sb = new StringBuilder();

            for (UInt32 i = (UInt32)0x100 + stackPointer + 1; i < 0x200; i++)
            {
                sb.Append("$");
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, i).ToString("X2"));
                sb.Append(", ");
            }
            string stack = sb.ToString();

            if (stack.Length > 2)
            {
                stack = stack.Substring(0, stack.Length - 2);
            }
            txtStack.Text = stack;
        }
예제 #15
0
        private static string ProcessArrayDisplaySyntax(bool useHex, ref bool forceHasChanged, Match match)
        {
            string newValue;
            int    address;

            if (match.Groups[2].Value.Length > 0)
            {
                address = int.Parse(match.Groups[2].Value.Substring(1), System.Globalization.NumberStyles.HexNumber);
            }
            else if (match.Groups[3].Value.Length > 0)
            {
                address = int.Parse(match.Groups[3].Value);
            }
            else
            {
                CodeLabel label = LabelManager.GetLabel(match.Groups[4].Value);
                if (label == null)
                {
                    forceHasChanged = true;
                    return("<invalid label>");
                }
                address = label.GetRelativeAddress();
            }
            int elemCount = int.Parse(match.Groups[5].Value);

            if (address >= 0)
            {
                List <string> values = new List <string>(elemCount);
                for (int j = address, end = address + elemCount; j < end; j++)
                {
                    int memValue = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (uint)j);
                    values.Add(useHex ? memValue.ToString("X2") : memValue.ToString());
                }
                newValue = string.Join(" ", values);
            }
            else
            {
                newValue        = "<label out of scope>";
                forceHasChanged = true;
            }

            return(newValue);
        }
예제 #16
0
        private void DisplayLabelTooltip(string word, CodeLabel label)
        {
            Int32  relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType);
            byte   byteValue       = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0;
            UInt16 wordValue       = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;
            var    values          = new Dictionary <string, string>()
            {
                { "Label", label.Label },
                { "Address", "$" + InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType).ToString("X4") },
                { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") },
            };

            if (!string.IsNullOrWhiteSpace(label.Comment))
            {
                values["Comment"] = label.Comment;
            }

            ShowTooltip(word, values);
        }
예제 #17
0
        private List <StackInfo> GetStackInfo()
        {
            int nmiHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
            int irqHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

            _stackFrames = InteropEmu.DebugGetCallstack();
            DebugState state = new DebugState();

            InteropEmu.DebugGetState(ref state);
            _programCounter = state.CPU.DebugPC;

            int relDestinationAddr = -1, absDestinationAddr = -1;

            List <StackInfo> stack = new List <StackInfo>();

            for (int i = 0, len = _stackFrames.Length; i < len; i++)
            {
                int relSubEntryAddr = i == 0 ? -1 : _stackFrames[i - 1].JumpTarget;
                int absSubEntryAddr = i == 0 ? -1 : _stackFrames[i - 1].JumpTargetAbsolute;

                stack.Add(new StackInfo()
                {
                    SubName             = this.GetFunctionName(relSubEntryAddr, absSubEntryAddr, nmiHandler, irqHandler),
                    IsMapped            = _stackFrames[i].JumpSourceAbsolute < 0 ? false : InteropEmu.DebugGetRelativeAddress((uint)_stackFrames[i].JumpSourceAbsolute, AddressType.PrgRom) >= 0,
                    CurrentRelativeAddr = _stackFrames[i].JumpSource,
                    CurrentAbsoluteAddr = _stackFrames[i].JumpSourceAbsolute
                });

                relDestinationAddr = _stackFrames[i].JumpTarget;
                absDestinationAddr = _stackFrames[i].JumpTargetAbsolute;
            }

            //Add current location
            stack.Add(new StackInfo()
            {
                SubName             = this.GetFunctionName(relDestinationAddr, absDestinationAddr, nmiHandler, irqHandler),
                IsMapped            = true,
                CurrentRelativeAddr = _programCounter,
                CurrentAbsoluteAddr = InteropEmu.DebugGetAbsoluteAddress((UInt32)_programCounter)
            });

            return(stack);
        }
예제 #18
0
        private void DisplaySymbolTooltip(Ld65DbgImporter.SymbolInfo symbol, int?arrayIndex = null)
        {
            AddressTypeInfo addressInfo = SymbolProvider.GetSymbolAddressInfo(symbol);

            if (addressInfo != null && addressInfo.Address >= 0)
            {
                int    relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)(addressInfo.Address + (arrayIndex ?? 0)), addressInfo.Type);
                byte   byteValue       = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0;
                UInt16 wordValue       = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;

                var values = new Dictionary <string, string>()
                {
                    { "Symbol", symbol.Name + (arrayIndex != null ? $"+{arrayIndex.Value}" : "") }
                };

                if (relativeAddress >= 0)
                {
                    values["CPU Address"] = "$" + relativeAddress.ToString("X4");
                }
                else
                {
                    values["CPU Address"] = "<out of scope>";
                }

                if (addressInfo.Type == AddressType.PrgRom)
                {
                    values["PRG Offset"] = "$" + (addressInfo.Address + (arrayIndex ?? 0)).ToString("X4");
                }

                values["Value"] = (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a");

                ShowTooltip(symbol.Name, values, -1, addressInfo);
            }
            else
            {
                var values = new Dictionary <string, string>()
                {
                    { "Symbol", symbol.Name },
                    { "Constant", symbol.Address.HasValue ? ("$" + symbol.Address.Value.ToString("X2")) : "<unknown>" }
                };
                ShowTooltip(symbol.Name, values, -1, addressInfo);
            }
        }
예제 #19
0
        private string ToHdPackFormat(int spriteIndex)
        {
            int ramAddr   = spriteIndex * 4;
            int spriteY   = _spriteRam[ramAddr];
            int tileIndex = _spriteRam[ramAddr + 1];
            int palette   = (_spriteRam[ramAddr + 2] & 0x03) + 4;
            int spriteX   = _spriteRam[ramAddr + 3];

            int tileAddr;

            if (_largeSprites)
            {
                tileAddr = ((tileIndex & 0x01) == 0x01 ? 0x1000 : 0x0000) + ((tileIndex & 0xFE) << 4);
            }
            else
            {
                tileAddr = _spritePatternAddr + (tileIndex << 4);
            }

            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isChrRam)
            {
                for (int i = 0; i < 16; i++)
                {
                    sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (UInt32)(tileAddr + i)).ToString("X2"));
                }
            }
            else
            {
                int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16;
                sb.Append(absoluteTileIndex.ToString());
            }
            sb.Append(",FF");
            for (int i = 1; i < 4; i++)
            {
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(palette * 4 + i)).ToString("X2"));
            }

            return(sb.ToString());
        }
예제 #20
0
        private void DisplaySymbolTooltip(Ld65DbgImporter.SymbolInfo symbol)
        {
            int    relativeAddress = symbol.Address.HasValue ? symbol.Address.Value : -1;
            byte   byteValue       = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0;
            UInt16 wordValue       = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;

            AddressTypeInfo?addressInfo = SymbolProvider.GetSymbolAddressInfo(symbol);

            if (addressInfo != null)
            {
                var values = new Dictionary <string, string>()
                {
                    { "Symbol", symbol.Name }
                };

                if (relativeAddress >= 0)
                {
                    values["CPU Address"] = "$" + relativeAddress.ToString("X4");
                }
                ;

                if (addressInfo.Value.Type == AddressType.PrgRom)
                {
                    values["PRG Offset"] = "$" + addressInfo.Value.Address.ToString("X4");
                }

                values["Value"] = (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a");

                ShowTooltip(symbol.Name, values, -1, addressInfo);
            }
            else
            {
                var values = new Dictionary <string, string>()
                {
                    { "Symbol", symbol.Name },
                    { "Constant", "$" + relativeAddress.ToString("X2") }
                };
                ShowTooltip(symbol.Name, values, -1, addressInfo);
            }
        }
예제 #21
0
        private void DrawPixel(bool leftButton, int x, int y)
        {
            int  baseAddress = _bottomBank ? 0x1000 : 0x0000;
            bool ppuMemory   = this.cboChrSelection.SelectedIndex == 0;

            if (this.cboChrSelection.SelectedIndex > 1)
            {
                baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000;
            }

            int tileIndex = GetLargeSpriteIndex(_tileIndex);

            bool            isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            DebugMemoryType memType  = ppuMemory? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom);

            byte orgByte1 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y));
            byte orgByte2 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8));

            byte byte1 = (byte)(orgByte1 & ~(0x80 >> x));
            byte byte2 = (byte)(orgByte2 & ~(0x80 >> x));

            byte value = 0;

            if (leftButton)
            {
                value  = (byte)ctrlTilePalette.SelectedColor;
                byte1 |= (byte)(((value << 7) & 0x80) >> x);
                byte2 |= (byte)(((value << 6) & 0x80) >> x);
            }

            if (byte1 != orgByte1 || byte2 != orgByte2)
            {
                InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y), byte1);
                InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8), byte2);

                GetData();
                RefreshViewer();
            }
        }
예제 #22
0
        private string ToHdPackFormat(int nametableIndex, int nametableTileIndex)
        {
            int x = nametableTileIndex % 32;
            int y = nametableTileIndex / 32;

            int        baseAddress     = 0x2000 + _nametableIndex * 0x400;
            int        tileIndex       = _tileData[_nametableIndex][nametableTileIndex];
            int        attributeData   = _attributeData[_nametableIndex][nametableTileIndex];
            int        shift           = (x & 0x02) | ((y & 0x02) << 1);
            int        paletteBaseAddr = ((attributeData >> shift) & 0x03) << 2;
            DebugState state           = new DebugState();

            InteropEmu.DebugGetState(ref state);
            int bgAddr   = state.PPU.ControlFlags.BackgroundPatternAddr;
            int tileAddr = bgAddr + tileIndex * 16;

            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isChrRam)
            {
                for (int i = 0; i < 16; i++)
                {
                    sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (uint)(tileAddr + i)).ToString("X2"));
                }
            }
            else
            {
                int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16;
                sb.Append(absoluteTileIndex.ToString());
            }
            sb.Append(",");
            for (int i = 0; i < 4; i++)
            {
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(paletteBaseAddr + i)).ToString("X2"));
            }
            return(sb.ToString());
        }
예제 #23
0
        private void DisplayLabelTooltip(string word, CodeLabel label, int?arrayIndex = null)
        {
            int    relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)(label.Address + (arrayIndex ?? 0)), label.AddressType);
            byte   byteValue       = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0;
            UInt16 wordValue       = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;

            var values = new Dictionary <string, string>()
            {
                { "Label", label.Label + (arrayIndex != null ? $"+{arrayIndex.Value}" : "") },
                { "Address", "$" + relativeAddress.ToString("X4") },
                { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") },
            };

            if (!string.IsNullOrWhiteSpace(label.Comment))
            {
                values["Comment"] = label.Comment;
            }

            ShowTooltip(word, values, -1, new AddressTypeInfo()
            {
                Address = (int)label.Address, Type = label.AddressType
            });
        }
예제 #24
0
        private void ctxMenu_Opening(object sender, CancelEventArgs e)
        {
            int        baseAddress     = 0x2000 + _nametableIndex * 0x400;
            int        tileIndex       = _tileData[_nametableIndex][_tileY * 32 + _tileX];
            int        attributeData   = _attributeData[_nametableIndex][_tileY * 32 + _tileX];
            int        shift           = (_tileX & 0x02) | ((_tileY & 0x02) << 1);
            int        paletteBaseAddr = ((attributeData >> shift) & 0x03) << 2;
            DebugState state           = new DebugState();

            InteropEmu.DebugGetState(ref state);
            int bgAddr   = state.PPU.ControlFlags.BackgroundPatternAddr;
            int tileAddr = bgAddr + tileIndex * 16;

            bool          isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
            StringBuilder sb       = new StringBuilder();

            if (isChrRam)
            {
                for (int i = 0; i < 16; i++)
                {
                    sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (uint)(tileAddr + i)).ToString("X2"));
                }
            }
            else
            {
                int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16;
                sb.Append(absoluteTileIndex.ToString());
            }
            sb.Append(",");
            for (int i = 0; i < 4; i++)
            {
                sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(paletteBaseAddr + i)).ToString("X2"));
            }

            _copyData = sb.ToString();
        }
예제 #25
0
        private void lstCounters_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            AddressCounters counts = _counts[e.ItemIndex];
            ListViewItem    item   = new ListViewItem("$" + counts.Address.ToString("X4"));

            item.Selected = false;
            item.Focused  = false;

            item.SubItems.Add("$" + InteropEmu.DebugGetMemoryValue(_memoryType, counts.Address).ToString("X2"));
            item.SubItems.Add(FormatNumber(counts.ReadCount));
            item.SubItems.Add(counts.ReadStamp > 0 ? FormatNumber(_cycleCount - counts.ReadStamp) : "n/a");
            item.SubItems.Add(FormatNumber(counts.WriteCount));
            item.SubItems.Add(counts.WriteStamp > 0 ? FormatNumber(_cycleCount - counts.WriteStamp) : "n/a");
            item.SubItems.Add(FormatNumber(counts.ExecCount));
            item.SubItems.Add(counts.ExecStamp > 0 ? FormatNumber(_cycleCount - counts.ExecStamp) : "n/a");
            item.SubItems.Add(counts.UninitRead != 0 ? "☑" : "☐");

            if (counts.ReadCount == 0 && counts.WriteCount == 0 && counts.ExecCount == 0)
            {
                item.ForeColor = Color.Gray;
            }

            e.Item = item;
        }
예제 #26
0
        private void mnuGoToResetHandler_Click(object sender, EventArgs e)
        {
            int address = (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFD) << 8) | InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFC);

            this.OnGotoLocation?.Invoke(address, null);
        }
예제 #27
0
        private void mnuGoToResetHandler_Click(object sender, EventArgs e)
        {
            int address = (InteropEmu.DebugGetMemoryValue(0xFFFD) << 8) | InteropEmu.DebugGetMemoryValue(0xFFFC);

            _lastCodeWindow.ScrollToLineNumber(address);
        }
예제 #28
0
파일: frmGoToAll.cs 프로젝트: sdefkk/Mesen
        private void UpdateResults()
        {
            string searchString = txtSearch.Text.Trim();

            List <string> searchStrings = new List <string>();

            searchStrings.Add(searchString.ToLower());
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            for (int i = 0; i < searchString.Length; i++)
            {
                char ch = searchString[i];
                if (ch >= 'A' && ch <= 'Z')
                {
                    searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A'));
                }
            }
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            searchStrings = searchStrings.Distinct().ToList();

            _resultCount = 0;

            HashSet <int> entryPoints = new HashSet <int>(InteropEmu.DebugGetFunctionEntryPoints());

            byte[] cdlData = InteropEmu.DebugGetPrgCdlData();

            List <SearchResultInfo> searchResults = new List <SearchResultInfo>();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                if (_symbolProvider != null)
                {
                    if (_showFilesAndConstants)
                    {
                        foreach (Ld65DbgImporter.FileInfo file in _symbolProvider.Files.Values)
                        {
                            if (Contains(file.Name, searchStrings))
                            {
                                searchResults.Add(new SearchResultInfo()
                                {
                                    Caption          = Path.GetFileName(file.Name),
                                    AbsoluteAddress  = -1,
                                    MemoryType       = AddressType.InternalRam,
                                    SearchResultType = SearchResultType.File,
                                    Filename         = file.Name,
                                    FileLineNumber   = 0,
                                    RelativeAddress  = -1,
                                    CodeLabel        = null
                                });
                            }
                        }
                    }

                    foreach (Ld65DbgImporter.SymbolInfo symbol in _symbolProvider.GetSymbols())
                    {
                        if (Contains(symbol.Name, searchStrings))
                        {
                            Ld65DbgImporter.ReferenceInfo def = _symbolProvider.GetSymbolDefinition(symbol);
                            AddressTypeInfo addressInfo       = _symbolProvider.GetSymbolAddressInfo(symbol);
                            int             value             = 0;
                            int             relAddress        = -1;
                            bool            isConstant        = addressInfo == null;
                            if (!_showFilesAndConstants && isConstant)
                            {
                                continue;
                            }

                            if (addressInfo != null)
                            {
                                value      = InteropEmu.DebugGetMemoryValue(addressInfo.Type.ToMemoryType(), (uint)addressInfo.Address);
                                relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
                            }
                            else
                            {
                                //For constants, the address field contains the constant's value
                                value = symbol.Address ?? 0;
                            }

                            SearchResultType resultType = SearchResultType.Data;
                            if (addressInfo?.Type == AddressType.PrgRom && entryPoints.Contains(addressInfo.Address))
                            {
                                resultType = SearchResultType.Function;
                            }
                            else if (addressInfo?.Type == AddressType.PrgRom && addressInfo.Address < cdlData.Length && (cdlData[addressInfo.Address] & (byte)CdlPrgFlags.JumpTarget) != 0)
                            {
                                resultType = SearchResultType.JumpTarget;
                            }
                            else if (isConstant)
                            {
                                resultType = SearchResultType.Constant;
                            }

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = symbol.Name,
                                AbsoluteAddress  = addressInfo?.Address ?? -1,
                                MemoryType       = addressInfo?.Type ?? AddressType.InternalRam,
                                SearchResultType = resultType,
                                Value            = value,
                                Filename         = def?.FileName ?? "",
                                FileLineNumber   = def?.LineNumber ?? 0,
                                RelativeAddress  = relAddress,
                                CodeLabel        = LabelManager.GetLabel(symbol.Name)
                            });
                        }
                    }
                }
                else
                {
                    foreach (CodeLabel label in LabelManager.GetLabels())
                    {
                        if (Contains(label.Label, searchStrings))
                        {
                            SearchResultType resultType = SearchResultType.Data;
                            if (label.AddressType == AddressType.PrgRom && entryPoints.Contains((int)label.Address))
                            {
                                resultType = SearchResultType.Function;
                            }
                            else if (label.AddressType == AddressType.PrgRom && label.Address < cdlData.Length && (cdlData[label.Address] & (byte)CdlPrgFlags.JumpTarget) != 0)
                            {
                                resultType = SearchResultType.JumpTarget;
                            }

                            int relativeAddress = label.GetRelativeAddress();

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = label.Label,
                                AbsoluteAddress  = (int)label.Address,
                                Value            = label.GetValue(),
                                MemoryType       = label.AddressType,
                                SearchResultType = resultType,
                                Filename         = "",
                                Disabled         = !_allowOutOfScope && relativeAddress < 0,
                                RelativeAddress  = relativeAddress,
                                CodeLabel        = label
                            });
                        }
                    }
                }
            }

            searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => {
                int comparison = a.Disabled.CompareTo(b.Disabled);

                if (comparison == 0)
                {
                    bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);
                    bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);

                    comparison = bStartsWithSearch.CompareTo(aStartsWithSearch);
                    if (comparison == 0)
                    {
                        comparison = a.Caption.CompareTo(b.Caption);
                    }
                }
                return(comparison);
            });

            _resultCount   = Math.Min(searchResults.Count, MaxResultCount);
            SelectedResult = 0;

            if (searchResults.Count == 0)
            {
                searchResults.Add(new SearchResultInfo()
                {
                    Caption = "No results found.", AbsoluteAddress = -1
                });
                pnlResults.BackColor = SystemColors.ControlLight;
            }
            else
            {
                pnlResults.BackColor = SystemColors.ControlDarkDark;
            }

            if (Program.IsMono)
            {
                pnlResults.Visible = false;
            }
            else
            {
                //Suspend layout causes a crash on Mono
                tlpResults.SuspendLayout();
            }

            for (int i = 0; i < _resultCount; i++)
            {
                _results[i].Initialize(searchResults[i]);
                _results[i].Tag     = searchResults[i];
                _results[i].Visible = true;
            }

            for (int i = searchResults.Count; i < MaxResultCount; i++)
            {
                _results[i].Visible = false;
            }

            pnlResults.VerticalScroll.Value = 0;
            tlpResults.Height = (_results[0].Height + 1) * _resultCount;

            pnlResults.ResumeLayout();
            if (Program.IsMono)
            {
                pnlResults.Visible = true;
                tlpResults.Width   = pnlResults.ClientSize.Width - 17;
            }
            else
            {
                tlpResults.ResumeLayout();
                tlpResults.Width = pnlResults.ClientSize.Width - 1;
            }
        }
예제 #29
0
 public byte GetValue()
 {
     return(InteropEmu.DebugGetMemoryValue(AddressType.ToMemoryType(), Address));
 }
예제 #30
0
        private void mnuGoToNmiHandler_Click(object sender, EventArgs e)
        {
            int address = (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8) | InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA);

            _lastCodeWindow.ScrollToLineNumber(address);
        }