From 195197fb709753e5606b8dc630c75aabf4515919 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 15 Oct 2015 23:12:20 -0500 Subject: [PATCH] snes gfx debugger: fix crashes and malfunction in 16x16 tilemaps --- .../tools/SNES/SNESGraphicsDebugger.Designer.cs | 5 ++--- .../tools/SNES/SNESGraphicsDebugger.cs | 13 ++++++++----- .../Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs | 11 ++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.Designer.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.Designer.cs index 89b43e8d87..8824a7d647 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.Designer.cs @@ -2143,10 +2143,9 @@ // pnDetailsPaletteColor // this.pnDetailsPaletteColor.BackColor = System.Drawing.Color.Red; - this.pnDetailsPaletteColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.pnDetailsPaletteColor.Location = new System.Drawing.Point(3, 4); + this.pnDetailsPaletteColor.Location = new System.Drawing.Point(6, 6); this.pnDetailsPaletteColor.Name = "pnDetailsPaletteColor"; - this.pnDetailsPaletteColor.Size = new System.Drawing.Size(69, 68); + this.pnDetailsPaletteColor.Size = new System.Drawing.Size(64, 64); this.pnDetailsPaletteColor.TabIndex = 3; this.pnDetailsPaletteColor.DoubleClick += new System.EventHandler(this.pnDetailsPaletteColor_DoubleClick); // diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 469b2859dc..8c4a6e4ff6 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -978,10 +978,13 @@ namespace BizHawk.Client.EmuHawk { //view a BG tile int paletteStart = 0; - var bmp = new Bitmap(8, 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - var bmpdata = bmp.LockBits(new Rectangle(0, 0, 8, 8), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var bgs = currMapEntryState; var oneTileEntry = new SNESGraphicsDecoder.TileEntry[] { bgs.entry }; + int tileSize = si.BG[bgs.bgnum].TileSize; + int pixels = tileSize * tileSize; + + var bmp = new Bitmap(tileSize, tileSize, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + var bmpdata = bmp.LockBits(new Rectangle(0, 0, tileSize, tileSize), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); if (viewBgMode == SNESGraphicsDecoder.BGMode.Mode7) gd.RenderMode7TilesToScreen((int*)bmpdata.Scan0, bmpdata.Stride / 4, false, false, 1, currMapEntryState.entry.tilenum, 1); @@ -991,9 +994,9 @@ namespace BizHawk.Client.EmuHawk gd.RenderMode7TilesToScreen((int*)bmpdata.Scan0, bmpdata.Stride / 4, false, true, 1, currMapEntryState.entry.tilenum, 1); else { - gd.DecodeBG((int*)bmpdata.Scan0, bmpdata.Stride / 4, oneTileEntry, si.BG[bgs.bgnum].TiledataAddr, SNESGraphicsDecoder.ScreenSize.Hacky_1x1, si.BG[bgs.bgnum].Bpp, 8, paletteStart); - gd.Paletteize((int*)bmpdata.Scan0, 0, 0, 64); - gd.Colorize((int*)bmpdata.Scan0, 0, 64); + gd.DecodeBG((int*)bmpdata.Scan0, bmpdata.Stride / 4, oneTileEntry, si.BG[bgs.bgnum].TiledataAddr, SNESGraphicsDecoder.ScreenSize.Hacky_1x1, si.BG[bgs.bgnum].Bpp, tileSize, paletteStart); + gd.Paletteize((int*)bmpdata.Scan0, 0, 0, pixels); + gd.Colorize((int*)bmpdata.Scan0, 0, pixels); } bmp.UnlockBits(bmpdata); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs index 840bd28f83..537bfed059 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs @@ -663,7 +663,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES { int mapIndex = mty * dims.Width + mtx; var te = map[mapIndex]; - int tileNum = te.tilenum + tx + ty * 16 + baseTileNum; + + //apply metatile flipping + int tnx = tx, tny = ty; + if (tilesize == 16) + { + if ((te.flags & TileEntryFlags.Horz) != 0) tnx = 1 - tnx; + if ((te.flags & TileEntryFlags.Vert) != 0) tny = 1 - tny; + } + + int tileNum = te.tilenum + tnx + tny * 16 + baseTileNum; int srcOfs = tileNum * 64; for (int i = 0, y = 0; y < 8; y++) {