aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpu_unai/gpu_raster_sprite.h
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/gpu_unai/gpu_raster_sprite.h')
-rw-r--r--plugins/gpu_unai/gpu_raster_sprite.h219
1 files changed, 105 insertions, 114 deletions
diff --git a/plugins/gpu_unai/gpu_raster_sprite.h b/plugins/gpu_unai/gpu_raster_sprite.h
index a700db3..0afdbf5 100644
--- a/plugins/gpu_unai/gpu_raster_sprite.h
+++ b/plugins/gpu_unai/gpu_raster_sprite.h
@@ -21,73 +21,70 @@
///////////////////////////////////////////////////////////////////////////////
// GPU internal sprite drawing functions
-///////////////////////////////////////////////////////////////////////////////
-void gpuDrawS(const PS gpuSpriteSpanDriver)
+void gpuDrawS(PtrUnion packet, const PS gpuSpriteSpanDriver)
{
- s32 x0, x1;
- s32 y0, y1;
- s32 u0;
- s32 v0;
-
- x1 = x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
- y1 = y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
- x1+= PacketBuffer.S2[6];
- y1+= PacketBuffer.S2[7];
-
- {
- s32 xmin, xmax;
- s32 ymin, ymax;
- xmin = DrawingArea[0]; xmax = DrawingArea[2];
- ymin = DrawingArea[1]; ymax = DrawingArea[3];
-
- {
- int rx0 = Max2(xmin,Min2(x0,x1));
- int ry0 = Max2(ymin,Min2(y0,y1));
- int rx1 = Min2(xmax,Max2(x0,x1));
- int ry1 = Min2(ymax,Max2(y0,y1));
- if( rx0>=rx1 || ry0>=ry1) return;
- }
-
- u0 = PacketBuffer.U1[8];
- v0 = PacketBuffer.U1[9];
-
- r4 = s32(PacketBuffer.U1[0]);
- g4 = s32(PacketBuffer.U1[1]);
- b4 = s32(PacketBuffer.U1[2]);
-
- {
- s32 temp;
- temp = ymin - y0;
- if (temp > 0) { y0 = ymin; v0 += temp; }
- if (y1 > ymax) y1 = ymax;
- if (y1 <= y0) return;
-
- temp = xmin - x0;
- if (temp > 0) { x0 = xmin; u0 += temp; }
- if (x1 > xmax) x1 = xmax;
- x1 -= x0;
- if (x1 <= 0) return;
- }
- }
-
- {
- u16 *Pixel = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0, y0)];
- const int li=linesInterlace;
- const u32 masku=TextureWindow[2];
- const u32 maskv=TextureWindow[3];
-
- for (;y0<y1;++y0) {
- if( 0 == (y0&li) ) gpuSpriteSpanDriver(Pixel,x1,FRAME_OFFSET(u0,v0),masku);
- Pixel += FRAME_WIDTH;
- v0 = (v0+1)&maskv;
- }
+ s32 x0, x1, y0, y1;
+ u32 u0, v0;
+
+ //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y,
+ // or sprites in 1st level of SkullMonkeys disappear when walking right.
+ // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
+ x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_unai.DrawingOffset[0]);
+ y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_unai.DrawingOffset[1]);
+
+ u32 w = packet.U2[6] & 0x3ff; // Max width is 1023
+ u32 h = packet.U2[7] & 0x1ff; // Max height is 511
+ x1 = x0 + w;
+ y1 = y0 + h;
+
+ s32 xmin, xmax, ymin, ymax;
+ xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
+ ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
+
+ u0 = packet.U1[8];
+ v0 = packet.U1[9];
+
+ s32 temp;
+ temp = ymin - y0;
+ if (temp > 0) { y0 = ymin; v0 += temp; }
+ if (y1 > ymax) y1 = ymax;
+ if (y1 <= y0) return;
+
+ temp = xmin - x0;
+ if (temp > 0) { x0 = xmin; u0 += temp; }
+ if (x1 > xmax) x1 = xmax;
+ x1 -= x0;
+ if (x1 <= 0) return;
+
+ gpu_unai.r5 = packet.U1[0] >> 3;
+ gpu_unai.g5 = packet.U1[1] >> 3;
+ gpu_unai.b5 = packet.U1[2] >> 3;
+
+ u16 *Pixel = &((u16*)gpu_unai.vram)[FRAME_OFFSET(x0, y0)];
+ const int li=gpu_unai.ilace_mask;
+ const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
+ const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
+ unsigned int tmode = gpu_unai.TEXT_MODE >> 5;
+ const u32 v0_mask = gpu_unai.TextureWindow[3];
+ u8* pTxt_base = (u8*)gpu_unai.TBA;
+
+ // Texture is accessed byte-wise, so adjust idx if 16bpp
+ if (tmode == 3) u0 <<= 1;
+
+ for (; y0<y1; ++y0) {
+ u8* pTxt = pTxt_base + ((v0 & v0_mask) * 2048);
+ if (!(y0&li) && (y0&pi)!=pif)
+ gpuSpriteSpanDriver(Pixel, x1, pTxt, u0);
+ Pixel += FRAME_WIDTH;
+ v0++;
}
}
#ifdef __arm__
#include "gpu_arm.h"
-void gpuDrawS16(void)
+/* Notaz 4bit sprites optimization */
+void gpuDrawS16(PtrUnion packet)
{
s32 x0, y0;
s32 u0, v0;
@@ -95,19 +92,22 @@ void gpuDrawS16(void)
s32 ymin, ymax;
u32 h = 16;
- x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
- y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
+ //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y,
+ // or sprites in 1st level of SkullMonkeys disappear when walking right.
+ // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
+ x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_unai.DrawingOffset[0]);
+ y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_unai.DrawingOffset[1]);
- xmin = DrawingArea[0]; xmax = DrawingArea[2];
- ymin = DrawingArea[1]; ymax = DrawingArea[3];
- u0 = PacketBuffer.U1[8];
- v0 = PacketBuffer.U1[9];
+ xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
+ ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
+ u0 = packet.U1[8];
+ v0 = packet.U1[9];
if (x0 > xmax - 16 || x0 < xmin ||
- ((u0 | v0) & 15) || !(TextureWindow[2] & TextureWindow[3] & 8)) {
+ ((u0 | v0) & 15) || !(gpu_unai.TextureWindow[2] & gpu_unai.TextureWindow[3] & 8)) {
// send corner cases to general handler
- PacketBuffer.U4[3] = 0x00100010;
- gpuDrawS(gpuSpriteSpanFn<0x20>);
+ packet.U4[3] = 0x00100010;
+ gpuDrawS(packet, gpuSpriteSpanFn<0x20>);
return;
}
@@ -121,54 +121,45 @@ void gpuDrawS16(void)
else if (ymax - y0 < 16)
h = ymax - y0;
- draw_spr16_full(&GPU_FrameBuffer[FRAME_OFFSET(x0, y0)], &TBA[FRAME_OFFSET(u0/4, v0)], CBA, h);
+ draw_spr16_full(&gpu_unai.vram[FRAME_OFFSET(x0, y0)], &gpu_unai.TBA[FRAME_OFFSET(u0/4, v0)], gpu_unai.CBA, h);
}
#endif // __arm__
-///////////////////////////////////////////////////////////////////////////////
-void gpuDrawT(const PT gpuTileSpanDriver)
+void gpuDrawT(PtrUnion packet, const PT gpuTileSpanDriver)
{
- s32 x0, y0;
- s32 x1, y1;
-
- x1 = x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
- y1 = y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
- x1+= PacketBuffer.S2[4];
- y1+= PacketBuffer.S2[5];
-
- {
- s32 xmin, xmax;
- s32 ymin, ymax;
- xmin = DrawingArea[0]; xmax = DrawingArea[2];
- ymin = DrawingArea[1]; ymax = DrawingArea[3];
-
- {
- int rx0 = Max2(xmin,Min2(x0,x1));
- int ry0 = Max2(ymin,Min2(y0,y1));
- int rx1 = Min2(xmax,Max2(x0,x1));
- int ry1 = Min2(ymax,Max2(y0,y1));
- if(rx0>=rx1 || ry0>=ry1) return;
- }
-
- if (y0 < ymin) y0 = ymin;
- if (y1 > ymax) y1 = ymax;
- if (y1 <= y0) return;
-
- if (x0 < xmin) x0 = xmin;
- if (x1 > xmax) x1 = xmax;
- x1 -= x0;
- if (x1 <= 0) return;
- }
-
- {
- u16 *Pixel = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0, y0)];
- const u16 Data = GPU_RGB16(PacketBuffer.U4[0]);
- const int li=linesInterlace;
-
- for (; y0<y1; ++y0)
- {
- if( 0 == (y0&li) ) gpuTileSpanDriver(Pixel,x1,Data);
- Pixel += FRAME_WIDTH;
- }
+ s32 x0, x1, y0, y1;
+
+ // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
+ x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_unai.DrawingOffset[0]);
+ y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_unai.DrawingOffset[1]);
+
+ u32 w = packet.U2[4] & 0x3ff; // Max width is 1023
+ u32 h = packet.U2[5] & 0x1ff; // Max height is 511
+ x1 = x0 + w;
+ y1 = y0 + h;
+
+ s32 xmin, xmax, ymin, ymax;
+ xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
+ ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
+
+ if (y0 < ymin) y0 = ymin;
+ if (y1 > ymax) y1 = ymax;
+ if (y1 <= y0) return;
+
+ if (x0 < xmin) x0 = xmin;
+ if (x1 > xmax) x1 = xmax;
+ x1 -= x0;
+ if (x1 <= 0) return;
+
+ const u16 Data = GPU_RGB16(packet.U4[0]);
+ u16 *Pixel = &((u16*)gpu_unai.vram)[FRAME_OFFSET(x0, y0)];
+ const int li=gpu_unai.ilace_mask;
+ const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
+ const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
+
+ for (; y0<y1; ++y0) {
+ if (!(y0&li) && (y0&pi)!=pif)
+ gpuTileSpanDriver(Pixel,x1,Data);
+ Pixel += FRAME_WIDTH;
}
}