debuggers.hg

view tools/ioemu/hw/cirrus_vga_rop2.h @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
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 */
25 #if DEPTH == 8
26 #define PUTPIXEL() ROP_OP((dst_base + m(d))[0], col)
27 #elif DEPTH == 16
28 #define PUTPIXEL() ROP_OP(((uint16_t *)(dst_base + m(d)))[0], col);
29 #elif DEPTH == 24
30 #define PUTPIXEL() ROP_OP((dst_base + m(d))[0], col); \
31 ROP_OP((dst_base + m(d))[1], (col >> 8)); \
32 ROP_OP((dst_base + m(d))[2], (col >> 16))
33 #elif DEPTH == 32
34 #define PUTPIXEL() ROP_OP(((uint32_t *)(dst_base + m(d)))[0], col)
35 #else
36 #error unsupported DEPTH
37 #endif
39 static void
40 glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
41 (CirrusVGAState * s, uint8_t * dst_,
42 const uint8_t * src_,
43 int dstpitch, int srcpitch,
44 int bltwidth, int bltheight)
45 {
46 uint8_t *dst_base, *src_base;
47 uint32_t src, dst;
48 uint32_t d;
49 int x, y, pattern_y, pattern_pitch, pattern_x;
50 unsigned int col;
51 uint32_t src1;
52 #if DEPTH == 24
53 int skipleft = s->gr[0x2f] & 0x1f;
54 #else
55 int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
56 #endif
58 get_base(dst_, s, dst_base);
59 get_base(src_, s, src_base);
60 dst = dst_ - dst_base;
61 src = src_ - src_base;
62 #if DEPTH == 8
63 pattern_pitch = 8;
64 #elif DEPTH == 16
65 pattern_pitch = 16;
66 #else
67 pattern_pitch = 32;
68 #endif
69 pattern_y = s->cirrus_blt_srcaddr & 7;
70 for(y = 0; y < bltheight; y++) {
71 pattern_x = skipleft;
72 d = dst + skipleft;
73 src1 = src + pattern_y * pattern_pitch;
74 for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
75 #if DEPTH == 8
76 col = *(src_base + m(src1 + pattern_x));
77 pattern_x = (pattern_x + 1) & 7;
78 #elif DEPTH == 16
79 col = *(uint16_t *)(src_base + m(src1 + pattern_x));
80 pattern_x = (pattern_x + 2) & 15;
81 #elif DEPTH == 24
82 {
83 const uint8_t *src2 = src_base + m(src1 + pattern_x * 3);
84 col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
85 pattern_x = (pattern_x + 1) & 7;
86 }
87 #else
88 col = *(uint32_t *)(src_base + m(src1 + pattern_x));
89 pattern_x = (pattern_x + 4) & 31;
90 #endif
91 PUTPIXEL();
92 d += (DEPTH / 8);
93 }
94 pattern_y = (pattern_y + 1) & 7;
95 dst += dstpitch;
96 }
97 }
99 /* NOTE: srcpitch is ignored */
100 static void
101 glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
102 (CirrusVGAState * s, uint8_t * dst_,
103 const uint8_t * src_,
104 int dstpitch, int srcpitch,
105 int bltwidth, int bltheight)
106 {
107 uint8_t *dst_base, *src_base;
108 uint32_t src, dst;
109 uint32_t d;
110 int x, y;
111 unsigned bits, bits_xor;
112 unsigned int col;
113 unsigned bitmask;
114 unsigned index;
115 #if DEPTH == 24
116 int dstskipleft = s->gr[0x2f] & 0x1f;
117 int srcskipleft = dstskipleft / 3;
118 #else
119 int srcskipleft = s->gr[0x2f] & 0x07;
120 int dstskipleft = srcskipleft * (DEPTH / 8);
121 #endif
123 get_base(dst_, s, dst_base);
124 get_base(src_, s, src_base);
125 dst = dst_ - dst_base;
126 src = src_ - src_base;
127 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
128 bits_xor = 0xff;
129 col = s->cirrus_blt_bgcol;
130 } else {
131 bits_xor = 0x00;
132 col = s->cirrus_blt_fgcol;
133 }
135 for(y = 0; y < bltheight; y++) {
136 bitmask = 0x80 >> srcskipleft;
137 bits = *(src_base + m(src++)) ^ bits_xor;
138 d = dst + dstskipleft;
139 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
140 if ((bitmask & 0xff) == 0) {
141 bitmask = 0x80;
142 bits = *(src_base + m(src++)) ^ bits_xor;
143 }
144 index = (bits & bitmask);
145 if (index) {
146 PUTPIXEL();
147 }
148 d += (DEPTH / 8);
149 bitmask >>= 1;
150 }
151 dst += dstpitch;
152 }
153 }
155 static void
156 glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
157 (CirrusVGAState * s, uint8_t * dst_,
158 const uint8_t * src_,
159 int dstpitch, int srcpitch,
160 int bltwidth, int bltheight)
161 {
162 uint8_t *dst_base, *src_base;
163 uint32_t src, dst;
164 uint32_t colors[2];
165 uint32_t d;
166 int x, y;
167 unsigned bits;
168 unsigned int col;
169 unsigned bitmask;
170 int srcskipleft = s->gr[0x2f] & 0x07;
171 int dstskipleft = srcskipleft * (DEPTH / 8);
173 get_base(dst_, s, dst_base);
174 get_base(src_, s, src_base);
175 dst = dst_ - dst_base;
176 src = src_ - src_base;
177 colors[0] = s->cirrus_blt_bgcol;
178 colors[1] = s->cirrus_blt_fgcol;
179 for(y = 0; y < bltheight; y++) {
180 bitmask = 0x80 >> srcskipleft;
181 bits = *(src_base + m(src++));
182 d = dst + dstskipleft;
183 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
184 if ((bitmask & 0xff) == 0) {
185 bitmask = 0x80;
186 bits = *(src_base + m(src++));
187 }
188 col = colors[!!(bits & bitmask)];
189 PUTPIXEL();
190 d += (DEPTH / 8);
191 bitmask >>= 1;
192 }
193 dst += dstpitch;
194 }
195 }
197 static void
198 glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
199 (CirrusVGAState * s, uint8_t * dst_,
200 const uint8_t * src_,
201 int dstpitch, int srcpitch,
202 int bltwidth, int bltheight)
203 {
204 uint8_t *dst_base, *src_base;
205 uint32_t src, dst;
206 uint32_t d;
207 int x, y, bitpos, pattern_y;
208 unsigned int bits, bits_xor;
209 unsigned int col;
210 #if DEPTH == 24
211 int dstskipleft = s->gr[0x2f] & 0x1f;
212 int srcskipleft = dstskipleft / 3;
213 #else
214 int srcskipleft = s->gr[0x2f] & 0x07;
215 int dstskipleft = srcskipleft * (DEPTH / 8);
216 #endif
218 get_base(dst_, s, dst_base);
219 get_base(src_, s, src_base);
220 dst = dst_ - dst_base;
221 src = src_ - src_base;
222 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
223 bits_xor = 0xff;
224 col = s->cirrus_blt_bgcol;
225 } else {
226 bits_xor = 0x00;
227 col = s->cirrus_blt_fgcol;
228 }
229 pattern_y = s->cirrus_blt_srcaddr & 7;
231 for(y = 0; y < bltheight; y++) {
232 bits = *(src_base + m(src + pattern_y)) ^ bits_xor;
233 bitpos = 7 - srcskipleft;
234 d = dst + dstskipleft;
235 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
236 if ((bits >> bitpos) & 1) {
237 PUTPIXEL();
238 }
239 d += (DEPTH / 8);
240 bitpos = (bitpos - 1) & 7;
241 }
242 pattern_y = (pattern_y + 1) & 7;
243 dst += dstpitch;
244 }
245 }
247 static void
248 glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
249 (CirrusVGAState * s, uint8_t * dst_,
250 const uint8_t * src_,
251 int dstpitch, int srcpitch,
252 int bltwidth, int bltheight)
253 {
254 uint8_t *dst_base, *src_base;
255 uint32_t src, dst;
256 uint32_t colors[2];
257 uint32_t d;
258 int x, y, bitpos, pattern_y;
259 unsigned int bits;
260 unsigned int col;
261 int srcskipleft = s->gr[0x2f] & 0x07;
262 int dstskipleft = srcskipleft * (DEPTH / 8);
264 get_base(dst_, s, dst_base);
265 get_base(src_, s, src_base);
266 dst = dst_ - dst_base;
267 src = src_ - src_base;
268 colors[0] = s->cirrus_blt_bgcol;
269 colors[1] = s->cirrus_blt_fgcol;
270 pattern_y = s->cirrus_blt_srcaddr & 7;
272 for(y = 0; y < bltheight; y++) {
273 bits = *(src_base + m(src + pattern_y));
274 bitpos = 7 - srcskipleft;
275 d = dst + dstskipleft;
276 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
277 col = colors[(bits >> bitpos) & 1];
278 PUTPIXEL();
279 d += (DEPTH / 8);
280 bitpos = (bitpos - 1) & 7;
281 }
282 pattern_y = (pattern_y + 1) & 7;
283 dst += dstpitch;
284 }
285 }
287 static void
288 glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
289 (CirrusVGAState *s,
290 uint8_t *dst_, int dst_pitch,
291 int width, int height)
292 {
293 uint8_t *dst_base;
294 uint32_t dst;
295 uint32_t d, d1;
296 uint32_t col;
297 int x, y;
299 get_base(dst_, s, dst_base);
300 dst = dst_ - dst_base;
301 col = s->cirrus_blt_fgcol;
303 d1 = dst;
304 for(y = 0; y < height; y++) {
305 d = d1;
306 for(x = 0; x < width; x += (DEPTH / 8)) {
307 PUTPIXEL();
308 d += (DEPTH / 8);
309 }
310 d1 += dst_pitch;
311 }
312 }
314 #undef DEPTH
315 #undef PUTPIXEL