1 /*
2 * QEMU Cirrus CLGD 54xx VGA Emulator.
3 *
4 * Copyright (c) 2004 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
glue(rop_8_,ROP_NAME)25 STATIC_INLINE void glue(rop_8_,ROP_NAME)(uint8_t *dst, uint8_t src)
26 {
27 *dst = ROP_FN(*dst, src);
28 }
29
glue(rop_16_,ROP_NAME)30 STATIC_INLINE void glue(rop_16_,ROP_NAME)(uint16_t *dst, uint16_t src)
31 {
32 *dst = ROP_FN(*dst, src);
33 }
34
glue(rop_32_,ROP_NAME)35 STATIC_INLINE void glue(rop_32_,ROP_NAME)(uint32_t *dst, uint32_t src)
36 {
37 *dst = ROP_FN(*dst, src);
38 }
39
40 #define ROP_OP(d, s) glue(rop_8_,ROP_NAME)(d, s)
41 #define ROP_OP_16(d, s) glue(rop_16_,ROP_NAME)(d, s)
42 #define ROP_OP_32(d, s) glue(rop_32_,ROP_NAME)(d, s)
43 #undef ROP_FN
44
45 static void
glue(cirrus_bitblt_rop_fwd_,ROP_NAME)46 glue(cirrus_bitblt_rop_fwd_, ROP_NAME)(CirrusVGAState *s,
47 uint8_t *dst,const uint8_t *src,
48 int dstpitch,int srcpitch,
49 int bltwidth,int bltheight)
50 {
51 int x,y;
52 dstpitch -= bltwidth;
53 srcpitch -= bltwidth;
54
55 #if 0
56 /* Invalid test! TW */
57 if (dstpitch < 0 || srcpitch < 0) {
58 /* is 0 valid? srcpitch == 0 could be useful */
59 return;
60 }
61 #endif
62
63 for (y = 0; y < bltheight; y++) {
64 for (x = 0; x < (bltwidth & ~3); x += 4) {
65 ROP_OP_32((uint32_t*)dst, *((uint32_t*)src));
66 dst += 4;
67 src += 4;
68 }
69 for (; x < bltwidth; x++) {
70 ROP_OP(dst, *src);
71 dst++;
72 src++;
73 }
74 dst += dstpitch;
75 src += srcpitch;
76 }
77 }
78
79 static void
glue(cirrus_bitblt_rop_bkwd_,ROP_NAME)80 glue(cirrus_bitblt_rop_bkwd_, ROP_NAME)(CirrusVGAState *s,
81 uint8_t *dst,const uint8_t *src,
82 int dstpitch,int srcpitch,
83 int bltwidth,int bltheight)
84 {
85 int x,y;
86 dstpitch += bltwidth;
87 srcpitch += bltwidth;
88 for (y = 0; y < bltheight; y++) {
89 for (x = 0; x < (bltwidth & ~3); x += 4) {
90 dst -= 3;
91 src -= 3;
92 ROP_OP_32((uint32_t*)dst, *((uint32_t*)src));
93 dst -= 1;
94 src -= 1;
95 }
96 for (; x < bltwidth; x++) {
97 ROP_OP(dst, *src);
98 dst--;
99 src--;
100 }
101 dst += dstpitch;
102 src += srcpitch;
103 }
104 }
105
106 static void
glue(glue (cirrus_bitblt_rop_fwd_transp_,ROP_NAME),_8)107 glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
108 uint8_t *dst,const uint8_t *src,
109 int dstpitch,int srcpitch,
110 int bltwidth,int bltheight)
111 {
112 int x,y;
113 uint8_t p;
114 dstpitch -= bltwidth;
115 srcpitch -= bltwidth;
116 for (y = 0; y < bltheight; y++) {
117 for (x = 0; x < bltwidth; x++) {
118 p = *dst;
119 ROP_OP(&p, *src);
120 if (p != s->vga.gr[0x34]) *dst = p;
121 dst++;
122 src++;
123 }
124 dst += dstpitch;
125 src += srcpitch;
126 }
127 }
128
129 static void
glue(glue (cirrus_bitblt_rop_bkwd_transp_,ROP_NAME),_8)130 glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
131 uint8_t *dst,const uint8_t *src,
132 int dstpitch,int srcpitch,
133 int bltwidth,int bltheight)
134 {
135 int x,y;
136 uint8_t p;
137 dstpitch += bltwidth;
138 srcpitch += bltwidth;
139 for (y = 0; y < bltheight; y++) {
140 for (x = 0; x < bltwidth; x++) {
141 p = *dst;
142 ROP_OP(&p, *src);
143 if (p != s->vga.gr[0x34]) *dst = p;
144 dst--;
145 src--;
146 }
147 dst += dstpitch;
148 src += srcpitch;
149 }
150 }
151
152 static void
glue(glue (cirrus_bitblt_rop_fwd_transp_,ROP_NAME),_16)153 glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
154 uint8_t *dst,const uint8_t *src,
155 int dstpitch,int srcpitch,
156 int bltwidth,int bltheight)
157 {
158 int x,y;
159 uint8_t p1, p2;
160 dstpitch -= bltwidth;
161 srcpitch -= bltwidth;
162 for (y = 0; y < bltheight; y++) {
163 for (x = 0; x < bltwidth; x+=2) {
164 p1 = *dst;
165 p2 = *(dst+1);
166 ROP_OP(&p1, *src);
167 ROP_OP(&p2, *(src + 1));
168 if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
169 *dst = p1;
170 *(dst+1) = p2;
171 }
172 dst+=2;
173 src+=2;
174 }
175 dst += dstpitch;
176 src += srcpitch;
177 }
178 }
179
180 static void
glue(glue (cirrus_bitblt_rop_bkwd_transp_,ROP_NAME),_16)181 glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
182 uint8_t *dst,const uint8_t *src,
183 int dstpitch,int srcpitch,
184 int bltwidth,int bltheight)
185 {
186 int x,y;
187 uint8_t p1, p2;
188 dstpitch += bltwidth;
189 srcpitch += bltwidth;
190 for (y = 0; y < bltheight; y++) {
191 for (x = 0; x < bltwidth; x+=2) {
192 p1 = *(dst-1);
193 p2 = *dst;
194 ROP_OP(&p1, *(src - 1));
195 ROP_OP(&p2, *src);
196 if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
197 *(dst-1) = p1;
198 *dst = p2;
199 }
200 dst-=2;
201 src-=2;
202 }
203 dst += dstpitch;
204 src += srcpitch;
205 }
206 }
207
208 #define DEPTH 8
209 #include "cirrus_vga_rop2.h"
210
211 #define DEPTH 16
212 #include "cirrus_vga_rop2.h"
213
214 #define DEPTH 24
215 #include "cirrus_vga_rop2.h"
216
217 #define DEPTH 32
218 #include "cirrus_vga_rop2.h"
219
220 #undef ROP_NAME
221 #undef ROP_OP
222 #undef ROP_OP_16
223 #undef ROP_OP_32
224