ref: b70aae808d4ac2c7296b02e75cc52fc78809b886
parent: d7f9df0ebd752fb3ff90293585bfba71c9bb87fb
author: Snesrev <snesrev@protonmail.com>
date: Fri Sep 23 07:20:15 EDT 2022
Fix Sky bg layer corruption in 16:9 mode on inventory screen (Fixes #115)
--- a/snes/ppu.c
+++ b/snes/ppu.c
@@ -224,9 +224,9 @@
uint8 bits;
} PpuWindows;
-static void PpuWindows_Clear(PpuWindows *win, Ppu *ppu) {
- win->edges[0] = -ppu->extraLeftCur;
- win->edges[1] = 256 + ppu->extraRightCur;
+static void PpuWindows_Clear(PpuWindows *win, Ppu *ppu, uint layer) {
+ win->edges[0] = -(layer != 2 ? ppu->extraLeftCur : 0);
+ win->edges[1] = 256 + (layer != 2 ? ppu->extraRightCur : 0);
win->nr = 1;
win->bits = 0;
}
@@ -237,8 +237,8 @@
// There are at most 5 windows.
// Algorithm from Snes9x
uint nr = 1;
- int window_right = 256 + ppu->extraRightCur;
- win->edges[0] = - ppu->extraLeftCur;
+ int window_right = 256 + (layer != 2 ? ppu->extraRightCur : 0);
+ win->edges[0] = - (layer != 2 ? ppu->extraLeftCur : 0);
win->edges[1] = window_right;
uint8 window_bits = 0;
uint i, j;
@@ -307,7 +307,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu, layer);
BgLayer *bglayer = &ppu->bgLayer[layer];
y += bglayer->vScroll;
int sc_offs = bglayer->tilemapAdr + (((y >> 3) & 0x1f) << 5);
@@ -406,7 +406,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu, layer);
BgLayer *bglayer = &ppu->bgLayer[layer];
y += bglayer->vScroll;
int sc_offs = bglayer->tilemapAdr + (((y >> 3) & 0x1f) << 5);
@@ -504,7 +504,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu, layer);
BgLayer *bglayer = &ppu->bgLayer[layer];
y = ppu->mosaicModulo[y] + bglayer->vScroll;
int sc_offs = bglayer->tilemapAdr + (((y >> 3) & 0x1f) << 5);
@@ -564,7 +564,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu, layer);
BgLayer *bglayer = &ppu->bgLayer[layer];
y = ppu->mosaicModulo[y] + bglayer->vScroll;
int sc_offs = bglayer->tilemapAdr + (((y >> 3) & 0x1f) << 5);
@@ -624,7 +624,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, 4) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, 4) : PpuWindows_Clear(&win, ppu, 4);
for (size_t windex = 0; windex < win.nr; windex++) {
if (win.bits & (1 << windex))
continue; // layer is disabled for this window part
@@ -651,7 +651,7 @@
if (!layerp->screenEnabled[sub])
return; // layer is completely hidden
PpuWindows win;
- layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu);
+ layerp->screenWindowed[sub] ? PpuWindows_Calc(&win, ppu, layer) : PpuWindows_Clear(&win, ppu, layer);
// expand 13-bit values to signed values
int hScroll = ((int16_t)(ppu->m7matrix[6] << 3)) >> 3;