From e1191584a2c82d671ce587254b95a866336208e9 Mon Sep 17 00:00:00 2001
From: kub <derkub@gmail.com>
Date: Mon, 17 Feb 2025 23:04:59 +0100
Subject: [PATCH] core vdp, fix s/h handling for layer window

---
 pico/draw.c     | 19 +++++++++----------
 pico/draw_arm.S |  2 +-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/pico/draw.c b/pico/draw.c
index b62333c5..f1d92f4b 100644
--- a/pico/draw.c
+++ b/pico/draw.c
@@ -629,8 +629,9 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
   tend<<=1;
 
   // Draw tiles across screen:
-  if (!sh)
+  if (!sh || !prio)
   {
+    sh = (sh ? 0x80 : 0x00); // sh and low prio -> shadow
     for (; tilex < tend; tilex++)
     {
       int dx, pal;
@@ -640,15 +641,15 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
         est->rendstatus |= PDRAW_WND_DIFF_PRIO;
         continue;
       }
-      if (code==blank) continue;
 
+      if (code==blank) continue;
       dx = 8 + (tilex << 3);
       DrawTile(~0,yshift,ymask,code,0);
     }
   }
   else
   {
-    sh <<= 6;
+    sh = lflags; // sh and high prio -> no shadow (lflags to suppress warning)
     for (; tilex < tend; tilex++)
     {
       int dx, pal;
@@ -659,14 +660,12 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
         continue;
       }
 
-      if (prio) {
-        int *zb = (int *)(est->HighCol+8+(tilex<<3));
-        *zb++ &= 0x7f7f7f7f;
-        *zb   &= 0x7f7f7f7f;
-      }
-      if(code==blank) continue;
+      // sh and high prio -> clear shadow
+      int *zb = (int *)(est->HighCol+8+(tilex<<3));
+      *zb++ &= 0x7f7f7f7f;
+      *zb   &= 0x7f7f7f7f;
 
-      sh = (sh & ~0x80) | (prio << 7);
+      if(code==blank) continue;
       dx = 8 + (tilex << 3);
       DrawTile(~0,yshift,ymask,code,0);
     }
diff --git a/pico/draw_arm.S b/pico/draw_arm.S
index 40d5c443..05a2ecec 100644
--- a/pico/draw_arm.S
+++ b/pico/draw_arm.S
@@ -1520,7 +1520,7 @@ DrawWindow:
     orr     r4, r4, r4, lsl #16
     mov     r5, r4
     stmia   r1!, {r4,r5}
-    b       .dwloop_nor1       @ we incremeted r1 ourselves
+    b       .dwloop_nor1       @ we incremented r1 ourselves
 
 .dw_shadow:
     tst     r6, #1             @ hi pri?
-- 
2.39.5