psx_gpu: fix line mask test
[pcsx_rearmed.git] / plugins / gpu_unai / gpu_inner_blend.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 _OP_BLEND_H_
22 #define _OP_BLEND_H_
23
24 //  GPU Blending operations functions
25
26 #ifdef __arm__
27 #define gpuBlending00(uSrc,uDst) \
28 { \
29         asm ("and  %[src], %[src], %[msk]\n" \
30              "and  %[dst], %[dst], %[msk]\n" \
31              "add  %[src], %[dst], %[src]\n" \
32              "mov  %[src], %[src], lsr #1\n" \
33          : [src] "=&r" (uSrc), [dst] "=&r" (uDst) : "0" (uSrc), "1" (uDst), [msk] "r" (uMsk)); \
34 }
35 #else
36 #define gpuBlending00(uSrc,uDst) \
37 { \
38         uSrc = (((uDst & uMsk) + (uSrc & uMsk)) >> 1); \
39 }
40 #endif
41
42 //      1.0 x Back + 1.0 x Forward
43 #ifdef __arm__
44 #define gpuBlending01(uSrc,uDst) \
45 { \
46         u32 st,dt,out; \
47         asm ("and    %[dt],  %[dst],   #0x7C00\n" \
48              "and    %[st],  %[src],   #0x7C00\n" \
49              "add    %[out], %[dt],    %[st]  \n" \
50              "cmp    %[out], #0x7C00          \n" \
51              "movhi  %[out], #0x7C00          \n" \
52              "and    %[dt],  %[dst],   #0x03E0\n" \
53              "and    %[st],  %[src],   #0x03E0\n" \
54              "add    %[dt],  %[dt],    %[st]  \n" \
55              "cmp    %[dt],  #0x03E0          \n" \
56              "movhi  %[dt],  #0x03E0          \n" \
57              "orr    %[out], %[out],   %[dt]  \n" \
58              "and    %[dt],  %[dst],   #0x001F\n" \
59              "and    %[st],  %[src],   #0x001F\n" \
60              "add    %[dt],  %[dt],    %[st]  \n" \
61              "cmp    %[dt],  #0x001F          \n" \
62              "movhi  %[dt],  #0x001F          \n" \
63              "orr    %[src], %[out],  %[dt]  \n" \
64          : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
65          : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
66 }
67 #else
68 #define gpuBlending01(uSrc,uDst) \
69 { \
70         u16 rr, gg, bb; \
71         bb = (uDst & 0x7C00) + (uSrc & 0x7C00);   if (bb > 0x7C00)  bb = 0x7C00; \
72         gg = (uDst & 0x03E0) + (uSrc & 0x03E0);   if (gg > 0x03E0)  gg = 0x03E0;  bb |= gg; \
73         rr = (uDst & 0x001F) + (uSrc & 0x001F);   if (rr > 0x001F)  rr = 0x001F;  bb |= rr; \
74         uSrc = bb; \
75 }
76 #endif
77
78 //      1.0 x Back - 1.0 x Forward      */
79 #ifdef __arm__
80 #define gpuBlending02(uSrc,uDst) \
81 { \
82         u32 st,dt,out; \
83         asm ("and    %[dt],  %[dst],   #0x7C00\n" \
84              "and    %[st],  %[src],   #0x7C00\n" \
85              "subs   %[out], %[dt],    %[st]  \n" \
86              "movmi  %[out], #0x0000          \n" \
87              "and    %[dt],  %[dst],   #0x03E0\n" \
88              "and    %[st],  %[src],   #0x03E0\n" \
89              "subs   %[dt],  %[dt],    %[st]  \n" \
90              "orrpl  %[out], %[out],   %[dt]  \n" \
91              "and    %[dt],  %[dst],   #0x001F\n" \
92              "and    %[st],  %[src],   #0x001F\n" \
93              "subs   %[dt],  %[dt],    %[st]  \n" \
94              "orrpl  %[out], %[out],   %[dt]  \n" \
95              "mov    %[src], %[out]           \n" \
96          : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
97          : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
98 }
99
100 int btest(int s, int d)
101 {
102         gpuBlending02(s, d);
103         return s;
104 }
105 #else
106 #define gpuBlending02(uSrc,uDst) \
107 { \
108         s32 rr, gg, bb; \
109         bb = (uDst & 0x7C00) - (uSrc & 0x7C00);   if (bb < 0)  bb  =  0; \
110         gg = (uDst & 0x03E0) - (uSrc & 0x03E0);   if (gg > 0)  bb |= gg; \
111         rr = (uDst & 0x001F) - (uSrc & 0x001F);   if (rr > 0)  bb |= rr; \
112         uSrc = bb; \
113 }
114 #endif
115
116 //      1.0 x Back + 0.25 x Forward     */
117 #ifdef __arm__
118 #define gpuBlending03(uSrc,uDst) \
119 { \
120         u32 st,dt,out; \
121         asm ("mov    %[src], %[src],   lsr #2 \n" \
122              "and    %[dt],  %[dst],   #0x7C00\n" \
123              "and    %[st],  %[src],   #0x1C00\n" \
124              "add    %[out], %[dt],    %[st]  \n" \
125              "cmp    %[out], #0x7C00          \n" \
126              "movhi  %[out], #0x7C00          \n" \
127              "and    %[dt],  %[dst],   #0x03E0\n" \
128              "and    %[st],  %[src],   #0x00E0\n" \
129              "add    %[dt],  %[dt],    %[st]  \n" \
130              "cmp    %[dt],  #0x03E0          \n" \
131              "movhi  %[dt],  #0x03E0          \n" \
132              "orr    %[out], %[out],   %[dt]  \n" \
133              "and    %[dt],  %[dst],   #0x001F\n" \
134              "and    %[st],  %[src],   #0x0007\n" \
135              "add    %[dt],  %[dt],    %[st]  \n" \
136              "cmp    %[dt],  #0x001F          \n" \
137              "movhi  %[dt],  #0x001F          \n" \
138              "orr    %[src], %[out],   %[dt]  \n" \
139          : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
140          : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
141 }
142 #else
143 #define gpuBlending03(uSrc,uDst) \
144 { \
145         u16 rr, gg, bb; \
146         uSrc >>= 2; \
147         bb = (uDst & 0x7C00) + (uSrc & 0x1C00);   if (bb > 0x7C00)  bb = 0x7C00; \
148         gg = (uDst & 0x03E0) + (uSrc & 0x00E0);   if (gg > 0x03E0)  gg = 0x03E0;  bb |= gg; \
149         rr = (uDst & 0x001F) + (uSrc & 0x0007);   if (rr > 0x001F)  rr = 0x001F;  bb |= rr; \
150         uSrc = bb; \
151 }
152 #endif
153
154 #endif  //_OP_BLEND_H_