Commit | Line | Data |
---|---|---|
86aad47b | 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 | ||
908e426c | 21 | #ifndef __GPU_UNAI_GPU_RASTER_SPRITE_H__ |
22 | #define __GPU_UNAI_GPU_RASTER_SPRITE_H__ | |
23 | ||
86aad47b | 24 | /////////////////////////////////////////////////////////////////////////////// |
25 | // GPU internal sprite drawing functions | |
26 | ||
c296224f | 27 | void gpuDrawS(PtrUnion packet, const PS gpuSpriteSpanDriver, s32 *w_out, s32 *h_out) |
86aad47b | 28 | { |
030d1121 | 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: | |
4949d4ff PC |
35 | x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); |
36 | y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); | |
030d1121 | 37 | |
4949d4ff PC |
38 | u32 w = le16_to_u16(packet.U2[6]) & 0x3ff; // Max width is 1023 |
39 | u32 h = le16_to_u16(packet.U2[7]) & 0x1ff; // Max height is 511 | |
030d1121 | 40 | x1 = x0 + w; |
41 | y1 = y0 + h; | |
42 | ||
43 | s32 xmin, xmax, ymin, ymax; | |
44 | xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; | |
45 | ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.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; | |
c296224f | 61 | *w_out = x1; |
62 | *h_out = y1 - y0; | |
030d1121 | 63 | |
64 | gpu_unai.r5 = packet.U1[0] >> 3; | |
65 | gpu_unai.g5 = packet.U1[1] >> 3; | |
66 | gpu_unai.b5 = packet.U1[2] >> 3; | |
67 | ||
4949d4ff | 68 | le16_t *Pixel = &gpu_unai.vram[FRAME_OFFSET(x0, y0)]; |
030d1121 | 69 | const int li=gpu_unai.ilace_mask; |
70 | const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); | |
71 | const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); | |
72 | unsigned int tmode = gpu_unai.TEXT_MODE >> 5; | |
73 | const u32 v0_mask = gpu_unai.TextureWindow[3]; | |
74 | u8* pTxt_base = (u8*)gpu_unai.TBA; | |
75 | ||
76 | // Texture is accessed byte-wise, so adjust idx if 16bpp | |
77 | if (tmode == 3) u0 <<= 1; | |
78 | ||
79 | for (; y0<y1; ++y0) { | |
80 | u8* pTxt = pTxt_base + ((v0 & v0_mask) * 2048); | |
81 | if (!(y0&li) && (y0&pi)!=pif) | |
82 | gpuSpriteSpanDriver(Pixel, x1, pTxt, u0); | |
83 | Pixel += FRAME_WIDTH; | |
84 | v0++; | |
86aad47b | 85 | } |
86 | } | |
87 | ||
b3db9409 | 88 | #ifdef __arm__ |
89 | #include "gpu_arm.h" | |
90 | ||
030d1121 | 91 | /* Notaz 4bit sprites optimization */ |
c296224f | 92 | void gpuDrawS16(PtrUnion packet, s32 *w_out, s32 *h_out) |
b3db9409 | 93 | { |
94 | s32 x0, y0; | |
95 | s32 u0, v0; | |
96 | s32 xmin, xmax; | |
97 | s32 ymin, ymax; | |
98 | u32 h = 16; | |
99 | ||
030d1121 | 100 | //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y, |
101 | // or sprites in 1st level of SkullMonkeys disappear when walking right. | |
102 | // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon: | |
4949d4ff PC |
103 | x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); |
104 | y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); | |
b3db9409 | 105 | |
030d1121 | 106 | xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; |
107 | ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; | |
108 | u0 = packet.U1[8]; | |
109 | v0 = packet.U1[9]; | |
b3db9409 | 110 | |
111 | if (x0 > xmax - 16 || x0 < xmin || | |
030d1121 | 112 | ((u0 | v0) & 15) || !(gpu_unai.TextureWindow[2] & gpu_unai.TextureWindow[3] & 8)) { |
b3db9409 | 113 | // send corner cases to general handler |
4949d4ff | 114 | packet.U4[3] = u32_to_le32(0x00100010); |
c296224f | 115 | gpuDrawS(packet, gpuSpriteSpanFn<0x20>, w_out, h_out); |
b3db9409 | 116 | return; |
117 | } | |
118 | ||
119 | if (y0 >= ymax || y0 <= ymin - 16) | |
120 | return; | |
121 | if (y0 < ymin) { | |
122 | h -= ymin - y0; | |
123 | v0 += ymin - y0; | |
124 | y0 = ymin; | |
125 | } | |
126 | else if (ymax - y0 < 16) | |
127 | h = ymax - y0; | |
c296224f | 128 | *w_out = 16; |
129 | *h_out = h; | |
b3db9409 | 130 | |
030d1121 | 131 | draw_spr16_full(&gpu_unai.vram[FRAME_OFFSET(x0, y0)], &gpu_unai.TBA[FRAME_OFFSET(u0/4, v0)], gpu_unai.CBA, h); |
b3db9409 | 132 | } |
133 | #endif // __arm__ | |
134 | ||
c296224f | 135 | void gpuDrawT(PtrUnion packet, const PT gpuTileSpanDriver, s32 *w_out, s32 *h_out) |
86aad47b | 136 | { |
030d1121 | 137 | s32 x0, x1, y0, y1; |
138 | ||
139 | // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon: | |
4949d4ff PC |
140 | x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); |
141 | y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); | |
030d1121 | 142 | |
4949d4ff PC |
143 | u32 w = le16_to_u16(packet.U2[4]) & 0x3ff; // Max width is 1023 |
144 | u32 h = le16_to_u16(packet.U2[5]) & 0x1ff; // Max height is 511 | |
030d1121 | 145 | x1 = x0 + w; |
146 | y1 = y0 + h; | |
147 | ||
148 | s32 xmin, xmax, ymin, ymax; | |
149 | xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; | |
150 | ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; | |
151 | ||
152 | if (y0 < ymin) y0 = ymin; | |
153 | if (y1 > ymax) y1 = ymax; | |
154 | if (y1 <= y0) return; | |
155 | ||
156 | if (x0 < xmin) x0 = xmin; | |
157 | if (x1 > xmax) x1 = xmax; | |
158 | x1 -= x0; | |
159 | if (x1 <= 0) return; | |
c296224f | 160 | *w_out = x1; |
161 | *h_out = y1 - y0; | |
030d1121 | 162 | |
4949d4ff PC |
163 | const u16 Data = GPU_RGB16(le32_to_u32(packet.U4[0])); |
164 | le16_t *Pixel = &gpu_unai.vram[FRAME_OFFSET(x0, y0)]; | |
030d1121 | 165 | const int li=gpu_unai.ilace_mask; |
166 | const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); | |
167 | const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); | |
168 | ||
169 | for (; y0<y1; ++y0) { | |
170 | if (!(y0&li) && (y0&pi)!=pif) | |
171 | gpuTileSpanDriver(Pixel,x1,Data); | |
172 | Pixel += FRAME_WIDTH; | |
86aad47b | 173 | } |
174 | } | |
908e426c | 175 | |
176 | #endif /* __GPU_UNAI_GPU_RASTER_SPRITE_H__ */ |