cdrom: change pause timing again
[pcsx_rearmed.git] / plugins / gpu_senquack / gpu_raster_sprite.h
1 /***************************************************************************
2 *   Copyright (C) 2010 PCSX4ALL Team                                      *
3 *   Copyright (C) 2010 Unai                                               *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *                                                                         *
10 *   This program is distributed in the hope that it will be useful,       *
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13 *   GNU General Public License for more details.                          *
14 *                                                                         *
15 *   You should have received a copy of the GNU General Public License     *
16 *   along with this program; if not, write to the                         *
17 *   Free Software Foundation, Inc.,                                       *
18 *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
19 ***************************************************************************/
20
21 #ifndef __GPU_UNAI_GPU_RASTER_SPRITE_H__
22 #define __GPU_UNAI_GPU_RASTER_SPRITE_H__
23
24 ///////////////////////////////////////////////////////////////////////////////
25 //  GPU internal sprite drawing functions
26
27 void gpuDrawS(PtrUnion packet, const PS gpuSpriteSpanDriver)
28 {
29         s32 x0, x1, y0, y1;
30         u32 u0, v0;
31
32         //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y,
33         // or sprites in 1st level of SkullMonkeys disappear when walking right.
34         // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
35         x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]);
36         y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]);
37
38         u32 w = packet.U2[6] & 0x3ff; // Max width is 1023
39         u32 h = packet.U2[7] & 0x1ff; // Max height is 511
40         x1 = x0 + w;
41         y1 = y0 + h;
42
43         s32 xmin, xmax, ymin, ymax;
44         xmin = gpu_senquack.DrawingArea[0];     xmax = gpu_senquack.DrawingArea[2];
45         ymin = gpu_senquack.DrawingArea[1];     ymax = gpu_senquack.DrawingArea[3];
46
47         u0 = packet.U1[8];
48         v0 = packet.U1[9];
49
50         s32 temp;
51         temp = ymin - y0;
52         if (temp > 0) { y0 = ymin; v0 += temp; }
53         if (y1 > ymax) y1 = ymax;
54         if (y1 <= y0) return;
55
56         temp = xmin - x0;
57         if (temp > 0) { x0 = xmin; u0 += temp; }
58         if (x1 > xmax) x1 = xmax;
59         x1 -= x0;
60         if (x1 <= 0) return;
61
62         gpu_senquack.r5 = packet.U1[0] >> 3;
63         gpu_senquack.g5 = packet.U1[1] >> 3;
64         gpu_senquack.b5 = packet.U1[2] >> 3;
65
66         u16 *Pixel = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(x0, y0)];
67         const int li=gpu_senquack.ilace_mask;
68         const int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0);
69         const int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1);
70         unsigned int tmode = gpu_senquack.TEXT_MODE >> 5;
71         const u32 v0_mask = gpu_senquack.TextureWindow[3];
72         u8* pTxt_base = (u8*)gpu_senquack.TBA;
73
74         // Texture is accessed byte-wise, so adjust idx if 16bpp
75         if (tmode == 3) u0 <<= 1;
76
77         for (; y0<y1; ++y0) {
78                 u8* pTxt = pTxt_base + ((v0 & v0_mask) * 2048);
79                 if (!(y0&li) && (y0&pi)!=pif)
80                         gpuSpriteSpanDriver(Pixel, x1, pTxt, u0);
81                 Pixel += FRAME_WIDTH;
82                 v0++;
83         }
84 }
85
86 #ifdef __arm__
87 #include "gpu_arm.h"
88
89 /* Notaz 4bit sprites optimization */
90 void gpuDrawS16(PtrUnion packet)
91 {
92         s32 x0, y0;
93         s32 u0, v0;
94         s32 xmin, xmax;
95         s32 ymin, ymax;
96         u32 h = 16;
97
98         //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y,
99         // or sprites in 1st level of SkullMonkeys disappear when walking right.
100         // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
101         x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]);
102         y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]);
103
104         xmin = gpu_senquack.DrawingArea[0];     xmax = gpu_senquack.DrawingArea[2];
105         ymin = gpu_senquack.DrawingArea[1];     ymax = gpu_senquack.DrawingArea[3];
106         u0 = packet.U1[8];
107         v0 = packet.U1[9];
108
109         if (x0 > xmax - 16 || x0 < xmin ||
110             ((u0 | v0) & 15) || !(gpu_senquack.TextureWindow[2] & gpu_senquack.TextureWindow[3] & 8)) {
111                 // send corner cases to general handler
112                 packet.U4[3] = 0x00100010;
113                 gpuDrawS(packet, gpuSpriteSpanFn<0x20>);
114                 return;
115         }
116
117         if (y0 >= ymax || y0 <= ymin - 16)
118                 return;
119         if (y0 < ymin) {
120                 h -= ymin - y0;
121                 v0 += ymin - y0;
122                 y0 = ymin;
123         }
124         else if (ymax - y0 < 16)
125                 h = ymax - y0;
126
127         draw_spr16_full(&gpu_senquack.vram[FRAME_OFFSET(x0, y0)], &gpu_senquack.TBA[FRAME_OFFSET(u0/4, v0)], gpu_senquack.CBA, h);
128 }
129 #endif // __arm__
130
131 void gpuDrawT(PtrUnion packet, const PT gpuTileSpanDriver)
132 {
133         s32 x0, x1, y0, y1;
134
135         // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon:
136         x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]);
137         y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]);
138
139         u32 w = packet.U2[4] & 0x3ff; // Max width is 1023
140         u32 h = packet.U2[5] & 0x1ff; // Max height is 511
141         x1 = x0 + w;
142         y1 = y0 + h;
143
144         s32 xmin, xmax, ymin, ymax;
145         xmin = gpu_senquack.DrawingArea[0];     xmax = gpu_senquack.DrawingArea[2];
146         ymin = gpu_senquack.DrawingArea[1];     ymax = gpu_senquack.DrawingArea[3];
147
148         if (y0 < ymin) y0 = ymin;
149         if (y1 > ymax) y1 = ymax;
150         if (y1 <= y0) return;
151
152         if (x0 < xmin) x0 = xmin;
153         if (x1 > xmax) x1 = xmax;
154         x1 -= x0;
155         if (x1 <= 0) return;
156
157         const u16 Data = GPU_RGB16(packet.U4[0]);
158         u16 *Pixel = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(x0, y0)];
159         const int li=gpu_senquack.ilace_mask;
160         const int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0);
161         const int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1);
162
163         for (; y0<y1; ++y0) {
164                 if (!(y0&li) && (y0&pi)!=pif)
165                         gpuTileSpanDriver(Pixel,x1,Data);
166                 Pixel += FRAME_WIDTH;
167         }
168 }
169
170 #endif /* __GPU_UNAI_GPU_RASTER_SPRITE_H__ */