private void RefreshPreview(int tileIndex, bool bottomBank) { int baseAddress = bottomBank ? 0x1000 : 0x0000; if (this.cboChrSelection.SelectedIndex > 1) { baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000; } int tileX = tileIndex % 16; int tileY = tileIndex / 16; int realIndex = GetLargeSpriteIndex(tileIndex); ctrlTilePalette.PaletteColors = _paletteData[bottomBank ? 1 : 0][realIndex]; int relativeAddress = 0; int absoluteAddress = 0; if (cboChrSelection.SelectedIndex > 1) { absoluteAddress = baseAddress + realIndex * 16; relativeAddress = InteropEmu.DebugGetRelativePpuAddress((uint)absoluteAddress, GetChrMemoryType().ToPpuAddressType()); } else { relativeAddress = baseAddress + realIndex * 16; absoluteAddress = InteropEmu.DebugGetPpuAbsoluteAddressAndType((uint)relativeAddress).Address; } _hoverTileInfo = new TileInfo() { BaseAddress = baseAddress, TileIndex = realIndex, TileAddress = relativeAddress, AbsoluteTileAddress = absoluteAddress }; this.txtTileIndex.Text = _hoverTileInfo.TileIndex.ToString("X2"); this.txtTileAddress.Text = _hoverTileInfo.TileAddress.ToString("X4"); _tilePreview = PpuViewerHelper.GetPreview(new Point(tileX * 16, tileY * 16), new Size(16, 16), 8, bottomBank ? this._chrBanks[1] : this._chrBanks[0]); Bitmap tile = new Bitmap(128, 128); using (Graphics g = Graphics.FromImage(tile)) { g.DrawImageUnscaled(_tilePreview, 0, 0); using (Brush brush = new SolidBrush(Color.FromArgb(128, Color.White))) { g.FillRectangle(brush, _tilePosX * 16, _tilePosY * 16, 16, 16); } } this.picTile.Image = tile; }
private void AddBreakpoint(int address) { PpuAddressTypeInfo addressInfo = InteropEmu.DebugGetPpuAbsoluteAddressAndType((uint)address); BreakpointManager.EditBreakpoint(new Breakpoint() { MemoryType = addressInfo.Type.ToMemoryType(), BreakOnExec = false, BreakOnRead = true, BreakOnWrite = true, Address = (UInt32)addressInfo.Address, StartAddress = (UInt32)addressInfo.Address, EndAddress = (UInt32)addressInfo.Address, AddressType = BreakpointAddressType.SingleAddress }); }
private void mnuViewInMemoryType_Click(object sender, EventArgs e) { if (_memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo addressInfo = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)SelectionStartAddress, addressInfo); if (addressInfo.Address >= 0 && (addressInfo.Type == AddressType.PrgRom || addressInfo.Type == AddressType.WorkRam || addressInfo.Type == AddressType.SaveRam)) { MemoryViewer.ShowAddress(addressInfo.Address, addressInfo.Type.ToMemoryType()); } } else { PpuAddressTypeInfo addressInfo = InteropEmu.DebugGetPpuAbsoluteAddressAndType((UInt32)SelectionStartAddress); if (addressInfo.Address >= 0) { MemoryViewer.ShowAddress(addressInfo.Address, addressInfo.Type.ToMemoryType()); } } }
private void mnuToggleBreakpoint_Click(object sender, EventArgs e) { if (DebugWindowManager.GetDebugger() == null) { return; } PpuAddressTypeInfo addressInfo = InteropEmu.DebugGetPpuAbsoluteAddressAndType((uint)_currentPpuAddress); BreakpointManager.EditBreakpoint(new Breakpoint() { MemoryType = addressInfo.Type.ToMemoryType(), BreakOnExec = false, BreakOnRead = true, BreakOnWrite = true, Address = (UInt32)addressInfo.Address, StartAddress = (UInt32)addressInfo.Address, EndAddress = (UInt32)addressInfo.Address, AddressType = BreakpointAddressType.SingleAddress }); }
private void UpdateActionAvailability() { UInt32 startAddress = (UInt32)SelectionStartAddress; UInt32 endAddress = (UInt32)SelectionEndAddress; string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddToWatch.Text = $"Add to Watch ({addressRange})"; mnuViewInDisassembly.Text = $"View in disassembly ({address})"; bool viewInCpuMemoryVisible = false; bool viewInPpuMemoryVisible = false; if (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam) { viewInCpuMemoryVisible = true; } else if (_memoryType == DebugMemoryType.ChrRom || _memoryType == DebugMemoryType.ChrRam || _memoryType == DebugMemoryType.NametableRam || _memoryType == DebugMemoryType.PaletteMemory) { viewInPpuMemoryVisible = true; } bool viewInMemoryTypeVisible = _memoryType == DebugMemoryType.CpuMemory || _memoryType == DebugMemoryType.PpuMemory; mnuViewInCpuMemory.Visible = viewInCpuMemoryVisible || viewInPpuMemoryVisible; mnuViewInMemoryType.Visible = viewInMemoryTypeVisible; mnuViewInDisassembly.Visible = (viewInCpuMemoryVisible || viewInMemoryTypeVisible); sepViewActions.Visible = (viewInCpuMemoryVisible || viewInPpuMemoryVisible || viewInMemoryTypeVisible); if (viewInMemoryTypeVisible) { bool viewInMemoryTypeEnabled = false; if (_memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo addressInfo = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, addressInfo); mnuViewInMemoryType.Text = $"View in " + ResourceHelper.GetEnumText(addressInfo.Type) + $" ({address})"; viewInMemoryTypeEnabled = addressInfo.Address >= 0 && (addressInfo.Type == AddressType.PrgRom || addressInfo.Type == AddressType.WorkRam || addressInfo.Type == AddressType.SaveRam); } else { PpuAddressTypeInfo addressInfo = InteropEmu.DebugGetPpuAbsoluteAddressAndType(startAddress); mnuViewInMemoryType.Text = $"View in " + ResourceHelper.GetEnumText(addressInfo.Type) + $" ({address})"; viewInMemoryTypeEnabled = addressInfo.Address >= 0 && (addressInfo.Type == PpuAddressType.ChrRam || addressInfo.Type == PpuAddressType.ChrRom || addressInfo.Type == PpuAddressType.NametableRam || addressInfo.Type == PpuAddressType.PaletteRam); } mnuViewInDisassembly.Enabled = DebugWindowManager.GetDebugger() != null; mnuViewInMemoryType.Enabled = viewInMemoryTypeEnabled; mnuViewInMemoryType.Visible = viewInMemoryTypeEnabled; mnuViewInCpuMemory.Enabled = false; } else if (viewInCpuMemoryVisible || viewInPpuMemoryVisible) { int relativeAddress = -1; if (viewInCpuMemoryVisible) { relativeAddress = InteropEmu.DebugGetRelativeAddress(startAddress, _memoryType.ToAddressType()); mnuViewInCpuMemory.Text = $"View in CPU memory ({address})"; } else { relativeAddress = InteropEmu.DebugGetRelativePpuAddress(startAddress, _memoryType.ToPpuAddressType()); mnuViewInCpuMemory.Text = $"View in PPU memory ({address})"; } mnuViewInCpuMemory.Enabled = relativeAddress >= 0; mnuViewInDisassembly.Enabled = viewInCpuMemoryVisible && DebugWindowManager.GetDebugger() != null && relativeAddress >= 0; mnuViewInMemoryType.Enabled = false; } else { mnuViewInMemoryType.Enabled = false; mnuViewInCpuMemory.Enabled = false; mnuViewInDisassembly.Enabled = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1)); mnuFreeze.Enabled = !freezeState.All((frozen) => frozen); mnuUnfreeze.Enabled = freezeState.Any((frozen) => frozen); mnuFreeze.Text = $"Freeze ({addressRange})"; mnuUnfreeze.Text = $"Unfreeze ({addressRange})"; } else { mnuFreeze.Text = $"Freeze"; mnuUnfreeze.Text = $"Unfreeze"; mnuFreeze.Enabled = false; mnuUnfreeze.Enabled = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { int absStart = InteropEmu.DebugGetAbsoluteAddress(startAddress); int absEnd = InteropEmu.DebugGetAbsoluteAddress(endAddress); if (absStart >= 0 && absEnd >= 0 && absStart <= absEnd) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } } else if (this._memoryType == DebugMemoryType.PrgRom) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } bool disableEditLabel = false; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, info); disableEditLabel = info.Address == -1; } mnuEditLabel.Enabled = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue); mnuEditBreakpoint.Enabled = DebugWindowManager.GetDebugger() != null && ( this._memoryType == DebugMemoryType.CpuMemory || this._memoryType == DebugMemoryType.PpuMemory || this._memoryType == DebugMemoryType.PrgRom || this._memoryType == DebugMemoryType.WorkRam || this._memoryType == DebugMemoryType.SaveRam || this._memoryType == DebugMemoryType.ChrRam || this._memoryType == DebugMemoryType.ChrRom || this._memoryType == DebugMemoryType.PaletteMemory ); mnuAddToWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory; mnuCopy.Enabled = ctrlHexBox.CanCopy(); mnuPaste.Enabled = ctrlHexBox.CanPaste(); mnuSelectAll.Enabled = ctrlHexBox.CanSelectAll(); mnuUndo.Enabled = InteropEmu.DebugHasUndoHistory(); }