From df4b38990f5d586b57366b6caad70c9cf51d00de Mon Sep 17 00:00:00 2001 From: nattthebear Date: Fri, 9 Dec 2016 22:09:58 -0500 Subject: [PATCH] GBAGPUView: Don't draw a sprite if its size + tile index combined make it go past the end of vram --- .../tools/GBA/GBAGPUView.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs index 7fade6caf0..4d5ed41121 100644 --- a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs @@ -349,14 +349,25 @@ namespace BizHawk.Client.EmuHawk ushort* palette = (ushort*)palram + 256; if (!eightbit) palette += attr2 >> 12 << 4; - if (!eightbit) - tiles += 32 * (attr2 & 1023); - else - tiles += 32 * (attr2 & 1022); - int tilestride = 0; - if (twodee) - tilestride = 1024 - tw * (eightbit ? 64 : 32); + int tileindex = eightbit ? attr2 & 1022 : attr2 & 1023; + int tilestride = twodee ? 1024 - tw * (eightbit ? 64 : 32) : 0; + + // see if the sprite would read past the end of vram, and skip it if it would + { + int tileend; + + if (!twodee) + tileend = tileindex + tw * th * (eightbit ? 2 : 1); + else + tileend = tileindex + tw * (eightbit ? 2 : 1) + (th - 1) * 32; + + if (tileend > 1024) + return; + } + + tiles += 32 * tileindex; + if (vflip) dest += pitch * 8 * (th - 1); if (hflip)