shithub: zelda3

Download patch

ref: 634086734f11bb2f220bf1d8353c810fe473c3a9
parent: 7471a86e3d40f217ff61fad94de5fcd023204ab1
author: Snesrev <[email protected]>
date: Wed Sep 28 12:06:47 EDT 2022

Add config option to disable the per-scanline sprite limits

- Visible when beamos shoots horizontally

--- a/config.c
+++ b/config.c
@@ -224,6 +224,9 @@
     } else if (StringEqualsNoCase(key, "WindowScale")) {
       g_config.window_scale = (uint8)strtol(value, (char**)NULL, 10);
       return true;
+    } else if (StringEqualsNoCase(key, "NoSpriteLimits")) {
+      g_config.no_sprite_limits = (bool)strtol(value, (char **)NULL, 10);
+      return true;
     }
   } else if (section == 2) {
     if (StringEqualsNoCase(key, "EnableAudio")) {
--- a/config.h
+++ b/config.h
@@ -46,6 +46,7 @@
   bool autosave;
   uint8 extended_aspect_ratio;
   bool extend_y, extended_aspect_ratio_nospr;
+  bool no_sprite_limits;
   bool display_perf_title;
   bool enable_msu;
   bool item_switch_lr;
--- a/main.c
+++ b/main.c
@@ -203,7 +203,8 @@
 
   g_ppu_render_flags = g_config.new_renderer * kPpuRenderFlags_NewRenderer |
                        g_config.enhanced_mode7 * kPpuRenderFlags_4x4Mode7 |
-                       g_config.extend_y * kPpuRenderFlags_Height240;
+                       g_config.extend_y * kPpuRenderFlags_Height240 |
+                       g_config.no_sprite_limits * kPpuRenderFlags_NoSpriteLimits;
   msu_enabled = g_config.enable_msu;
 
   if (g_config.fullscreen == 1)
--- a/snes/ppu.c
+++ b/snes/ppu.c
@@ -1305,9 +1305,13 @@
   //   then iterate those in-range sprites in reverse for tile-fetching
   // TODO: rectangular sprites, wierdness with sprites at -256
   int index = ppu->objPriority ? (ppu->oamAdr & 0xfe) : 0, index_end = index;
-  int spritesFound = 0, tilesFound = 0;
+  int spritesLeft = 32 + 1, tilesLeft = 34 + 1;
   uint8 spriteSizes[2] = { kSpriteSizes[ppu->objSize][0], kSpriteSizes[ppu->objSize][1] };
   int extra_left_right = ppu->extraLeftRight;
+  if (ppu->renderFlags & kPpuRenderFlags_NoSpriteLimits)
+    spritesLeft = tilesLeft = 1024;
+  int tilesLeftOrg = tilesLeft;
+
   do {
     int yy = ppu->oam[index] >> 8;
     if (yy == 0xf0)
@@ -1325,7 +1329,7 @@
     if (x <= -(spriteSize + extra_left_right))
       continue;
     // break if we found 32 sprites already
-    if (++spritesFound > 32) {
+    if (--spritesLeft == 0) {
       ppu->rangeOver = true;
       break;
     }
@@ -1341,7 +1345,7 @@
     for (int col = 0; col < spriteSize; col += 8) {
       if (col + x > -8 - extra_left_right && col + x < 256 + extra_left_right) {
         // break if we found 34 8*1 slivers already
-        if (++tilesFound > 34) {
+        if (--tilesLeft == 0) {
           ppu->timeOver = true;
           return true;
         }
@@ -1366,7 +1370,7 @@
       }
     }
   } while ((index = (index + 2) & 0xff) != index_end);
-  return (tilesFound != 0);
+  return (tilesLeft != tilesLeftOrg);
 }
 
 static uint16_t ppu_getVramRemap(Ppu* ppu) {
--- a/snes/ppu.h
+++ b/snes/ppu.h
@@ -52,6 +52,8 @@
   kPpuRenderFlags_4x4Mode7 = 2,
   // Use 240 height instead of 224
   kPpuRenderFlags_Height240 = 4,
+  // Disable sprite render limits
+  kPpuRenderFlags_NoSpriteLimits = 8,
 };
 
 
--- a/zelda3.ini
+++ b/zelda3.ini
@@ -19,6 +19,8 @@
 EnhancedMode7 = 1
 IgnoreAspectRatio = 0
 
+# Enable this option to remove the sprite limits per scan line
+NoSpriteLimits = 1
 
 [Sound]
 EnableAudio = 1