psx_gpu: partial interlace mode support
[pcsx_rearmed.git] / plugins / gpu_unai / gpu_blit.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 _INNER_BLIT_H_
22 #define _INNER_BLIT_H_
23
24 #ifndef USE_BGR15
25 #define RGB24(R,G,B)    (((((R)&0xF8)<<8)|(((G)&0xFC)<<3)|(((B)&0xF8)>>3)))
26 #define RGB16X2(C)      (((C)&(0x1f001f<<10))>>10) | (((C)&(0x1f001f<<5))<<1) | (((C)&(0x1f001f<<0))<<11)
27 #define RGB16(C)                (((C)&(0x1f<<10))>>10) | (((C)&(0x1f<<5))<<1) | (((C)&(0x1f<<0))<<11)
28 #else
29 #define RGB24(R,G,B)    ((((R)&0xF8)>>3)|(((G)&0xF8)<<2)|(((B)&0xF8)<<7))
30 #endif
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //  GPU Blitting code with rescale and interlace support.
34
35 INLINE void GPU_BlitWW(const void* src, u16* dst16, u32 isRGB24)
36 {
37         u32 uCount;
38         if(isRGB24 == 0)
39         {
40                 #ifndef USE_BGR15
41                         uCount = 20;
42                         const u32* src32 = (const u32*) src; 
43                         u32* dst32 = (u32*)(void*) dst16;
44                         do{
45                                 dst32[0] = RGB16X2(src32[0]);
46                                 dst32[1] = RGB16X2(src32[1]);
47                                 dst32[2] = RGB16X2(src32[2]);
48                                 dst32[3] = RGB16X2(src32[3]);
49                                 dst32[4] = RGB16X2(src32[4]);
50                                 dst32[5] = RGB16X2(src32[5]);
51                                 dst32[6] = RGB16X2(src32[6]);
52                                 dst32[7] = RGB16X2(src32[7]);
53                                 dst32 += 8;
54                                 src32 += 8;
55                         }while(--uCount);
56                 #else
57                         memcpy(dst16,src,640);
58                 #endif
59         }
60         else
61         {
62                 uCount = 20;
63                 const u8* src8 = (const u8*)src;
64                 do{
65                         dst16[ 0] = RGB24(src8[ 0], src8[ 1], src8[ 2] );
66                         dst16[ 1] = RGB24(src8[ 3], src8[ 4], src8[ 5] );
67                         dst16[ 2] = RGB24(src8[ 6], src8[ 7], src8[ 8] );
68                         dst16[ 3] = RGB24(src8[ 9], src8[10], src8[11] );
69                         dst16[ 4] = RGB24(src8[12], src8[13], src8[14] );
70                         dst16[ 5] = RGB24(src8[15], src8[16], src8[17] );
71                         dst16[ 6] = RGB24(src8[18], src8[19], src8[20] );
72                         dst16[ 7] = RGB24(src8[21], src8[22], src8[23] );
73
74                         dst16[ 8] = RGB24(src8[24], src8[25], src8[26] );
75                         dst16[ 9] = RGB24(src8[27], src8[28], src8[29] );
76                         dst16[10] = RGB24(src8[30], src8[31], src8[32] );
77                         dst16[11] = RGB24(src8[33], src8[34], src8[35] );
78                         dst16[12] = RGB24(src8[36], src8[37], src8[38] );
79                         dst16[13] = RGB24(src8[39], src8[40], src8[41] );
80                         dst16[14] = RGB24(src8[42], src8[43], src8[44] );
81                         dst16[15] = RGB24(src8[45], src8[46], src8[47] );
82                         dst16 += 16;
83                         src8  += 48;
84                 }while(--uCount);
85         }
86 }
87
88 INLINE void GPU_BlitWWSWWSWS(const void* src, u16* dst16, u32 isRGB24)
89 {
90         u32 uCount;
91         if(isRGB24 == 0)
92         {
93                 #ifndef USE_BGR15
94                         uCount = 32;
95                         const u16* src16 = (const u16*) src; 
96                         do{
97                                 dst16[ 0] = RGB16(src16[0]);
98                                 dst16[ 1] = RGB16(src16[1]);
99                                 dst16[ 2] = RGB16(src16[3]);
100                                 dst16[ 3] = RGB16(src16[4]);
101                                 dst16[ 4] = RGB16(src16[6]);
102                                 dst16[ 5] = RGB16(src16[8]);
103                                 dst16[ 6] = RGB16(src16[9]);
104                                 dst16[ 7] = RGB16(src16[11]);
105                                 dst16[ 8] = RGB16(src16[12]);
106                                 dst16[ 9] = RGB16(src16[14]);
107                                 dst16 += 10;
108                                 src16 += 16;
109                         }while(--uCount);
110                 #else
111                         uCount = 64;
112                         const u16* src16 = (const u16*) src; 
113                         do{
114                                 *dst16++ = *src16++;
115                                 *dst16++ = *src16;
116                                 src16+=2;
117                                 *dst16++ = *src16++;
118                                 *dst16++ = *src16;
119                                 src16+=2;
120                                 *dst16++ = *src16;
121                                 src16+=2;
122                         }while(--uCount);
123                 #endif
124         }
125         else
126         {
127                 uCount = 32;
128                 const u8* src8 = (const u8*)src;
129                 do{
130                         dst16[ 0] = RGB24(src8[ 0], src8[ 1], src8[ 2] );
131                         dst16[ 1] = RGB24(src8[ 3], src8[ 4], src8[ 5] );
132                         dst16[ 2] = RGB24(src8[ 9], src8[10], src8[11] );
133                         dst16[ 3] = RGB24(src8[12], src8[13], src8[14] );
134                         dst16[ 4] = RGB24(src8[18], src8[19], src8[20] );
135
136                         dst16[ 5] = RGB24(src8[24], src8[25], src8[26] );
137                         dst16[ 6] = RGB24(src8[27], src8[28], src8[29] );
138                         dst16[ 7] = RGB24(src8[33], src8[34], src8[35] );
139                         dst16[ 8] = RGB24(src8[36], src8[37], src8[38] );
140                         dst16[ 9] = RGB24(src8[42], src8[43], src8[44] );
141
142                         dst16 += 10;
143                         src8  += 48;
144                 }while(--uCount);
145         }
146 }
147
148 INLINE void GPU_BlitWWWWWS(const void* src, u16* dst16, u32 isRGB24)
149 {
150         u32 uCount;
151         if(isRGB24 == 0)
152         {
153                 #ifndef USE_BGR15
154                         uCount = 32;
155                         const u16* src16 = (const u16*) src; 
156                         do{
157                                 dst16[ 0] = RGB16(src16[0]);
158                                 dst16[ 1] = RGB16(src16[1]);
159                                 dst16[ 2] = RGB16(src16[2]);
160                                 dst16[ 3] = RGB16(src16[3]);
161                                 dst16[ 4] = RGB16(src16[4]);
162                                 dst16[ 5] = RGB16(src16[6]);
163                                 dst16[ 6] = RGB16(src16[7]);
164                                 dst16[ 7] = RGB16(src16[8]);
165                                 dst16[ 8] = RGB16(src16[9]);
166                                 dst16[ 9] = RGB16(src16[10]);
167                                 dst16 += 10;
168                                 src16 += 12;
169                         }while(--uCount);
170                 #else
171                         uCount = 64;
172                         const u16* src16 = (const u16*) src; 
173                         do{
174                                 *dst16++ = *src16++;
175                                 *dst16++ = *src16++;
176                                 *dst16++ = *src16++;
177                                 *dst16++ = *src16++;
178                                 *dst16++ = *src16;
179                                 src16+=2;
180                         }while(--uCount);
181                 #endif
182         }
183         else
184         {
185                 uCount = 32;
186                 const u8* src8 = (const u8*)src;
187                 do{
188                         dst16[0] = RGB24(src8[ 0], src8[ 1], src8[ 2] );
189                         dst16[1] = RGB24(src8[ 3], src8[ 4], src8[ 5] );
190                         dst16[2] = RGB24(src8[ 6], src8[ 7], src8[ 8] );
191                         dst16[3] = RGB24(src8[ 9], src8[10], src8[11] );
192                         dst16[4] = RGB24(src8[12], src8[13], src8[14] );
193                         dst16[5] = RGB24(src8[18], src8[19], src8[20] );
194                         dst16[6] = RGB24(src8[21], src8[22], src8[23] );
195                         dst16[7] = RGB24(src8[24], src8[25], src8[26] );
196                         dst16[8] = RGB24(src8[27], src8[28], src8[29] );
197                         dst16[9] = RGB24(src8[30], src8[31], src8[32] );
198                         dst16 += 10;
199                         src8  += 36;
200                 }while(--uCount);
201         }
202 }
203
204 INLINE void GPU_BlitWWWWWWWWS(const void* src, u16* dst16, u32 isRGB24, u32 uClip_src)
205 {
206         u32 uCount;
207         if(isRGB24 == 0)
208         {
209                 #ifndef USE_BGR15
210                         uCount = 20;
211                         const u16* src16 = ((const u16*) src) + uClip_src; 
212                         do{
213                                 dst16[ 0] = RGB16(src16[0]);
214                                 dst16[ 1] = RGB16(src16[1]);
215                                 dst16[ 2] = RGB16(src16[2]);
216                                 dst16[ 3] = RGB16(src16[3]);
217                                 dst16[ 4] = RGB16(src16[4]);
218                                 dst16[ 5] = RGB16(src16[5]);
219                                 dst16[ 6] = RGB16(src16[6]);
220                                 dst16[ 7] = RGB16(src16[7]);
221
222                                 dst16[ 8] = RGB16(src16[9]);
223                                 dst16[ 9] = RGB16(src16[10]);
224                                 dst16[10] = RGB16(src16[11]);
225                                 dst16[11] = RGB16(src16[12]);
226                                 dst16[12] = RGB16(src16[13]);
227                                 dst16[13] = RGB16(src16[14]);
228                                 dst16[14] = RGB16(src16[15]);
229                                 dst16[15] = RGB16(src16[16]);
230                                 dst16 += 16;
231                                 src16 += 18;
232                         }while(--uCount);
233                 #else
234                         uCount = 40;
235                         const u16* src16 = ((const u16*) src) + uClip_src; 
236                         do{
237                                 *dst16++ = *src16++;
238                                 *dst16++ = *src16++;
239                                 *dst16++ = *src16++;
240                                 *dst16++ = *src16++;
241                                 *dst16++ = *src16++;
242                                 *dst16++ = *src16++;
243                                 *dst16++ = *src16++;
244                                 *dst16++ = *src16;
245                                 src16+=2;
246                         }while(--uCount);
247                 #endif
248         }
249         else
250         {
251                 uCount = 20;
252                 const u8* src8 = (const u8*)src + (uClip_src<<1) + uClip_src;
253                 do{
254                         dst16[ 0] = RGB24(src8[ 0], src8[ 1], src8[ 2] );
255                         dst16[ 1] = RGB24(src8[ 3], src8[ 4], src8[ 5] );
256                         dst16[ 2] = RGB24(src8[ 6], src8[ 7], src8[ 8] );
257                         dst16[ 3] = RGB24(src8[ 9], src8[10], src8[11] );
258                         dst16[ 4] = RGB24(src8[12], src8[13], src8[14] );
259                         dst16[ 5] = RGB24(src8[15], src8[16], src8[17] );
260                         dst16[ 6] = RGB24(src8[18], src8[19], src8[20] );
261                         dst16[ 7] = RGB24(src8[21], src8[22], src8[23] );
262
263                         dst16[ 8] = RGB24(src8[27], src8[28], src8[29] );
264                         dst16[ 9] = RGB24(src8[30], src8[31], src8[32] );
265                         dst16[10] = RGB24(src8[33], src8[34], src8[35] );
266                         dst16[11] = RGB24(src8[36], src8[37], src8[38] );
267                         dst16[12] = RGB24(src8[39], src8[40], src8[41] );
268                         dst16[13] = RGB24(src8[42], src8[43], src8[44] );
269                         dst16[14] = RGB24(src8[45], src8[46], src8[47] );
270                         dst16[15] = RGB24(src8[48], src8[49], src8[50] );
271                         dst16 += 16;
272                         src8  += 54;
273                 }while(--uCount);
274         }
275 }
276
277 INLINE void GPU_BlitWWDWW(const void* src, u16* dst16, u32 isRGB24)
278 {
279         u32 uCount;
280         if(isRGB24 == 0)
281         {
282                 #ifndef USE_BGR15
283                         uCount = 32;
284                         const u16* src16 = (const u16*) src; 
285                         do{
286                                 dst16[ 0] = RGB16(src16[0]);
287                                 dst16[ 1] = RGB16(src16[1]);
288                                 dst16[ 2] = dst16[1];
289                                 dst16[ 3] = RGB16(src16[2]);
290                                 dst16[ 4] = RGB16(src16[3]);
291                                 dst16[ 5] = RGB16(src16[4]);
292                                 dst16[ 6] = RGB16(src16[5]);
293                                 dst16[ 7] = dst16[6];
294                                 dst16[ 8] = RGB16(src16[6]);
295                                 dst16[ 9] = RGB16(src16[7]);
296                                 dst16 += 10;
297                                 src16 +=  8;
298                         }while(--uCount);
299                 #else
300                         uCount = 64;
301                         const u16* src16 = (const u16*) src; 
302                         do{
303                                 *dst16++ = *src16++;
304                                 *dst16++ = *src16;
305                                 *dst16++ = *src16++;
306                                 *dst16++ = *src16++;
307                                 *dst16++ = *src16++;
308                         }while(--uCount);
309                 #endif
310         }
311         else
312         {
313                 uCount = 32;
314                 const u8* src8 = (const u8*)src;
315                 do{
316                         dst16[ 0] = RGB24(src8[0], src8[ 1], src8[ 2] );
317                         dst16[ 1] = RGB24(src8[3], src8[ 4], src8[ 5] );
318                         dst16[ 2] = dst16[1];
319                         dst16[ 3] = RGB24(src8[6], src8[ 7], src8[ 8] );
320                         dst16[ 4] = RGB24(src8[9], src8[10], src8[11] );
321
322                         dst16[ 5] = RGB24(src8[12], src8[13], src8[14] );
323                         dst16[ 6] = RGB24(src8[15], src8[16], src8[17] );
324                         dst16[ 7] = dst16[6];
325                         dst16[ 8] = RGB24(src8[18], src8[19], src8[20] );
326                         dst16[ 9] = RGB24(src8[21], src8[22], src8[23] );
327                         dst16 += 10;
328                         src8  += 24;
329                 }while(--uCount);
330         }
331 }
332
333
334 INLINE void GPU_BlitWS(const void* src, u16* dst16, u32 isRGB24)
335 {
336         u32 uCount;
337         if(isRGB24 == 0)
338         {
339                 #ifndef USE_BGR15
340                         uCount = 20;
341                         const u16* src16 = (const u16*) src; 
342                         do{
343                                 dst16[ 0] = RGB16(src16[0]);
344                                 dst16[ 1] = RGB16(src16[2]);
345                                 dst16[ 2] = RGB16(src16[4]);
346                                 dst16[ 3] = RGB16(src16[6]);
347
348                                 dst16[ 4] = RGB16(src16[8]);
349                                 dst16[ 5] = RGB16(src16[10]);
350                                 dst16[ 6] = RGB16(src16[12]);
351                                 dst16[ 7] = RGB16(src16[14]);
352
353                                 dst16[ 8] = RGB16(src16[16]);
354                                 dst16[ 9] = RGB16(src16[18]);
355                                 dst16[10] = RGB16(src16[20]);
356                                 dst16[11] = RGB16(src16[22]);
357
358                                 dst16[12] = RGB16(src16[24]);
359                                 dst16[13] = RGB16(src16[26]);
360                                 dst16[14] = RGB16(src16[28]);
361                                 dst16[15] = RGB16(src16[30]);
362
363                                 dst16 += 16;
364                                 src16 += 32;
365                         }while(--uCount);
366                 #else
367                         uCount = 320;
368                         const u16* src16 = (const u16*) src; 
369                         do{
370                                 *dst16++ = *src16; src16+=2;
371                         }while(--uCount);
372                 #endif
373         }
374         else
375         {
376                 uCount = 20;
377                 const u8* src8 = (const u8*) src; 
378                 do{
379                         dst16[ 0] = RGB24(src8[ 0], src8[ 1], src8[ 2] );
380                         dst16[ 1] = RGB24(src8[ 6], src8[ 7], src8[ 8] );
381                         dst16[ 2] = RGB24(src8[12], src8[13], src8[14] );
382                         dst16[ 3] = RGB24(src8[18], src8[19], src8[20] );
383
384                         dst16[ 4] = RGB24(src8[24], src8[25], src8[26] );
385                         dst16[ 5] = RGB24(src8[30], src8[31], src8[32] );
386                         dst16[ 6] = RGB24(src8[36], src8[37], src8[38] );
387                         dst16[ 7] = RGB24(src8[42], src8[43], src8[44] );
388
389                         dst16[ 8] = RGB24(src8[48], src8[49], src8[50] );
390                         dst16[ 9] = RGB24(src8[54], src8[55], src8[56] );
391                         dst16[10] = RGB24(src8[60], src8[61], src8[62] );
392                         dst16[11] = RGB24(src8[66], src8[67], src8[68] );
393
394                         dst16[12] = RGB24(src8[72], src8[73], src8[74] );
395                         dst16[13] = RGB24(src8[78], src8[79], src8[80] );
396                         dst16[14] = RGB24(src8[84], src8[85], src8[86] );
397                         dst16[15] = RGB24(src8[90], src8[91], src8[92] );
398
399                         dst16 += 16;
400                         src8  += 96;
401                 }while(--uCount);
402         }
403 }
404
405 #endif //_INNER_BLIT_H_