Example #1
0
        private void UpdateTileInfo(int ramAddr)
        {
            _forceRefresh   = false;
            _selectedSprite = ramAddr / 4;

            int spriteY    = _spriteRam[ramAddr];
            int tileIndex  = _spriteRam[ramAddr + 1];
            int attributes = _spriteRam[ramAddr + 2];
            int spriteX    = _spriteRam[ramAddr + 3];

            int tileAddr;

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

            this.ctrlTilePalette.SelectedPalette = (attributes & 0x03) + 4;

            int  paletteAddr        = 0x3F10 + ((attributes & 0x03) << 2);
            bool verticalMirror     = (attributes & 0x80) == 0x80;
            bool horizontalMirror   = (attributes & 0x40) == 0x40;
            bool backgroundPriority = (attributes & 0x20) == 0x20;

            _spriteInfo = new SpriteInfo()
            {
                SpriteIndex        = _selectedSprite,
                SpriteX            = spriteX,
                SpriteY            = spriteY,
                TileIndex          = tileIndex,
                HorizontalMirror   = horizontalMirror,
                VerticalMirror     = verticalMirror,
                BackgroundPriority = backgroundPriority,
                PaletteIndex       = (attributes & 0x03)
            };

            this.txtSpriteIndex.Text            = _selectedSprite.ToString("X2");
            this.txtTileIndex.Text              = tileIndex.ToString("X2");
            this.txtTileAddress.Text            = tileAddr.ToString("X4");
            this.txtPosition.Text               = spriteX.ToString() + ", " + spriteY.ToString();
            this.txtPaletteAddress.Text         = paletteAddr.ToString("X4");
            this.chkVerticalMirroring.Checked   = verticalMirror;
            this.chkHorizontalMirroring.Checked = horizontalMirror;
            this.chkBackgroundPriority.Checked  = backgroundPriority;

            int tileX = _selectedSprite % 8;
            int tileY = _selectedSprite / 8;

            int spriteHeight = _largeSprites ? 64 : 32;

            picTile.Image = PpuViewerHelper.GetPreview(new Point(tileX * 32, tileY * spriteHeight), new Size(32, spriteHeight), 2, _scaledSprites);

            this.CreateScreenPreview();
        }
Example #2
0
        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;
        }
Example #3
0
        private void DrawHud(int chrBank)
        {
            Bitmap chrBankImage = new Bitmap(256, 256);

            using (Graphics g = Graphics.FromImage(chrBankImage)) {
                g.DrawImage(_chrBanks[chrBank], 0, 0);

                if (_bottomBank == (chrBank == 1))
                {
                    int tileX = _tileIndex % 16;
                    int tileY = _tileIndex / 16;
                    using (Brush brush = new SolidBrush(Color.FromArgb(192, Color.White))) {
                        g.FillRectangle(brush, tileX * 16, tileY * 16, 16, 16);
                        g.DrawRectangle(Pens.Black, tileX * 16, tileY * 16, 16, 16);
                    }
                }

                if (_hoverTileIndex >= 0)
                {
                    int tileX = _hoverTileIndex % 16;
                    int tileY = _hoverTileIndex / 16;
                    if (_hoverBottomBank == (chrBank == 1))
                    {
                        using (Brush brush = new SolidBrush(Color.FromArgb(192, Color.LightBlue))) {
                            g.FillRectangle(brush, tileX * 16, tileY * 16, 16, 16);
                            g.DrawRectangle(Pens.White, tileX * 16 - 1, tileY * 16 - 1, 17, 17);
                        }
                    }
                    else
                    {
                        if (ConfigManager.Config.DebugInfo.PpuShowInformationOverlay)
                        {
                            string tooltipText = (
                                "Tile:      $" + _hoverTileInfo.TileIndex.ToString("X2") + Environment.NewLine +
                                "PPU Addr.: $" + _hoverTileInfo.TileAddress.ToString("X4") + Environment.NewLine +
                                "CHR Addr.: $" + _hoverTileInfo.AbsoluteTileAddress.ToString("X4") + Environment.NewLine
                                );

                            Bitmap preview = PpuViewerHelper.GetPreview(new Point(tileX * 16, tileY * 16), new Size(16, 16), 4, _chrBanks[chrBank == 0 ? 1 : 0]);
                            PpuViewerHelper.DrawOverlayTooltip(chrBankImage, tooltipText, preview, -1, chrBank == 0, g);
                        }
                    }
                }
            }

            PictureBox[] chrBanks = new PictureBox[] { this.picChrBank1, this.picChrBank2 };
            chrBanks[chrBank].Image = chrBankImage;
            chrBanks[chrBank].Refresh();
        }
Example #4
0
        private void UpdateColorInformation(int paletteIndex)
        {
            int tileX = paletteIndex % 4;
            int tileY = (paletteIndex / 4) % 4;

            _paletteIndex = paletteIndex;

            this.txtColor.Text          = _paletteRam[paletteIndex].ToString("X2");
            this.txtPaletteAddress.Text = (0x3F00 + paletteIndex).ToString("X4");

            this.txtColorCodeHex.Text = GetHexColorString();
            this.txtColorCodeRgb.Text = GetRgbColorString();

            this.picColor.Image = PpuViewerHelper.GetPreview(new Point(tileX * 32, tileY * 32), new Size(32, 32), 2, paletteIndex >= 16 ? picPaletteSprites.Image : picPaletteBg.Image);
        }
Example #5
0
        private void UpdateTileInformation(int xPos, int yPos, int baseAddress, int shift)
        {
            DebugState state = new DebugState();

            InteropEmu.DebugGetState(ref state);
            int bgAddr = state.PPU.ControlFlags.BackgroundPatternAddr;

            byte tileIndex     = _tileData[_nametableIndex][_tileY * 32 + _tileX];
            byte attributeData = _attributeData[_nametableIndex][_tileY * 32 + _tileX];

            _tileInfo = new TileInfo()
            {
                PpuAddress       = _currentPpuAddress,
                TileIndex        = tileIndex,
                AttributeData    = attributeData,
                AttributeAddress = baseAddress + 960 + ((_tileY & 0xFC) << 1) + (_tileX >> 2),
                PaletteAddress   = ((attributeData >> shift) & 0x03) << 2,
                    TileX        = _tileX,
                    TileY        = _tileY,
                    Nametable    = _nametableIndex,
                    TileAddress  = bgAddr + tileIndex * 16
            };

            this.ctrlTilePalette.SelectedPalette = (_tileInfo.PaletteAddress >> 2);

            this.txtPpuAddress.Text       = _tileInfo.PpuAddress.ToString("X4");
            this.txtNametable.Text        = _tileInfo.Nametable.ToString();
            this.txtLocation.Text         = _tileInfo.TileX.ToString() + ", " + _tileInfo.TileY.ToString();
            this.txtTileIndex.Text        = _tileInfo.TileIndex.ToString("X2");
            this.txtTileAddress.Text      = _tileInfo.TileAddress.ToString("X4");
            this.txtAttributeData.Text    = _tileInfo.AttributeData.ToString("X2");
            this.txtAttributeAddress.Text = _tileInfo.AttributeAddress.ToString("X4");
            this.txtPaletteAddress.Text   = (0x3F00 + _tileInfo.PaletteAddress).ToString("X4");

            picTile.Image = PpuViewerHelper.GetPreview(new Point(xPos / 8 * 8, yPos / 8 * 8), new Size(8, 8), 8, _nametableImage);
        }