Statistics
| Branch: | Revision:

root / hw / cirrus_vga_rop2.h @ 43ad7e3e

History | View | Annotate | Download (7.9 kB)

1 a5082316 bellard
/*
2 a5082316 bellard
 * QEMU Cirrus CLGD 54xx VGA Emulator.
3 5fafdf24 ths
 *
4 a5082316 bellard
 * Copyright (c) 2004 Fabrice Bellard
5 5fafdf24 ths
 *
6 a5082316 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 a5082316 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 a5082316 bellard
 * in the Software without restriction, including without limitation the rights
9 a5082316 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 a5082316 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 a5082316 bellard
 * furnished to do so, subject to the following conditions:
12 a5082316 bellard
 *
13 a5082316 bellard
 * The above copyright notice and this permission notice shall be included in
14 a5082316 bellard
 * all copies or substantial portions of the Software.
15 a5082316 bellard
 *
16 a5082316 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 a5082316 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 a5082316 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 a5082316 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 a5082316 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 a5082316 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 a5082316 bellard
 * THE SOFTWARE.
23 a5082316 bellard
 */
24 a5082316 bellard
25 a5082316 bellard
#if DEPTH == 8
26 8c78881f Blue Swirl
#define PUTPIXEL()    ROP_OP(&d[0], col)
27 a5082316 bellard
#elif DEPTH == 16
28 8c78881f Blue Swirl
#define PUTPIXEL()    ROP_OP_16((uint16_t *)&d[0], col)
29 a5082316 bellard
#elif DEPTH == 24
30 8c78881f Blue Swirl
#define PUTPIXEL()    ROP_OP(&d[0], col);        \
31 8c78881f Blue Swirl
                      ROP_OP(&d[1], (col >> 8)); \
32 8c78881f Blue Swirl
                      ROP_OP(&d[2], (col >> 16))
33 a5082316 bellard
#elif DEPTH == 32
34 8c78881f Blue Swirl
#define PUTPIXEL()    ROP_OP_32(((uint32_t *)&d[0]), col)
35 a5082316 bellard
#else
36 a5082316 bellard
#error unsupported DEPTH
37 3b46e624 ths
#endif
38 a5082316 bellard
39 e69390ce bellard
static void
40 e69390ce bellard
glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
41 e69390ce bellard
     (CirrusVGAState * s, uint8_t * dst,
42 5fafdf24 ths
      const uint8_t * src,
43 5fafdf24 ths
      int dstpitch, int srcpitch,
44 e69390ce bellard
      int bltwidth, int bltheight)
45 e69390ce bellard
{
46 e69390ce bellard
    uint8_t *d;
47 e69390ce bellard
    int x, y, pattern_y, pattern_pitch, pattern_x;
48 e69390ce bellard
    unsigned int col;
49 e69390ce bellard
    const uint8_t *src1;
50 ad81218e bellard
#if DEPTH == 24
51 4e12cd94 Avi Kivity
    int skipleft = s->vga.gr[0x2f] & 0x1f;
52 ad81218e bellard
#else
53 4e12cd94 Avi Kivity
    int skipleft = (s->vga.gr[0x2f] & 0x07) * (DEPTH / 8);
54 ad81218e bellard
#endif
55 e69390ce bellard
56 e69390ce bellard
#if DEPTH == 8
57 e69390ce bellard
    pattern_pitch = 8;
58 e69390ce bellard
#elif DEPTH == 16
59 e69390ce bellard
    pattern_pitch = 16;
60 e69390ce bellard
#else
61 e69390ce bellard
    pattern_pitch = 32;
62 e69390ce bellard
#endif
63 e69390ce bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
64 e69390ce bellard
    for(y = 0; y < bltheight; y++) {
65 2f636b45 bellard
        pattern_x = skipleft;
66 e3a4e4b6 bellard
        d = dst + skipleft;
67 e69390ce bellard
        src1 = src + pattern_y * pattern_pitch;
68 e3a4e4b6 bellard
        for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
69 e69390ce bellard
#if DEPTH == 8
70 e69390ce bellard
            col = src1[pattern_x];
71 e69390ce bellard
            pattern_x = (pattern_x + 1) & 7;
72 e69390ce bellard
#elif DEPTH == 16
73 e69390ce bellard
            col = ((uint16_t *)(src1 + pattern_x))[0];
74 e69390ce bellard
            pattern_x = (pattern_x + 2) & 15;
75 b30d4608 bellard
#elif DEPTH == 24
76 b30d4608 bellard
            {
77 b30d4608 bellard
                const uint8_t *src2 = src1 + pattern_x * 3;
78 b30d4608 bellard
                col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
79 b30d4608 bellard
                pattern_x = (pattern_x + 1) & 7;
80 b30d4608 bellard
            }
81 e69390ce bellard
#else
82 e69390ce bellard
            col = ((uint32_t *)(src1 + pattern_x))[0];
83 e69390ce bellard
            pattern_x = (pattern_x + 4) & 31;
84 e69390ce bellard
#endif
85 e69390ce bellard
            PUTPIXEL();
86 e69390ce bellard
            d += (DEPTH / 8);
87 e69390ce bellard
        }
88 e69390ce bellard
        pattern_y = (pattern_y + 1) & 7;
89 e69390ce bellard
        dst += dstpitch;
90 e69390ce bellard
    }
91 e69390ce bellard
}
92 e69390ce bellard
93 4c8732d7 bellard
/* NOTE: srcpitch is ignored */
94 a5082316 bellard
static void
95 a5082316 bellard
glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
96 a5082316 bellard
     (CirrusVGAState * s, uint8_t * dst,
97 5fafdf24 ths
      const uint8_t * src,
98 5fafdf24 ths
      int dstpitch, int srcpitch,
99 a5082316 bellard
      int bltwidth, int bltheight)
100 a5082316 bellard
{
101 a5082316 bellard
    uint8_t *d;
102 a5082316 bellard
    int x, y;
103 b30d4608 bellard
    unsigned bits, bits_xor;
104 a5082316 bellard
    unsigned int col;
105 a5082316 bellard
    unsigned bitmask;
106 a5082316 bellard
    unsigned index;
107 ad81218e bellard
#if DEPTH == 24
108 4e12cd94 Avi Kivity
    int dstskipleft = s->vga.gr[0x2f] & 0x1f;
109 ad81218e bellard
    int srcskipleft = dstskipleft / 3;
110 ad81218e bellard
#else
111 4e12cd94 Avi Kivity
    int srcskipleft = s->vga.gr[0x2f] & 0x07;
112 e3a4e4b6 bellard
    int dstskipleft = srcskipleft * (DEPTH / 8);
113 ad81218e bellard
#endif
114 a5082316 bellard
115 b30d4608 bellard
    if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
116 b30d4608 bellard
        bits_xor = 0xff;
117 b30d4608 bellard
        col = s->cirrus_blt_bgcol;
118 b30d4608 bellard
    } else {
119 b30d4608 bellard
        bits_xor = 0x00;
120 b30d4608 bellard
        col = s->cirrus_blt_fgcol;
121 b30d4608 bellard
    }
122 b30d4608 bellard
123 a5082316 bellard
    for(y = 0; y < bltheight; y++) {
124 a5082316 bellard
        bitmask = 0x80 >> srcskipleft;
125 b30d4608 bellard
        bits = *src++ ^ bits_xor;
126 e3a4e4b6 bellard
        d = dst + dstskipleft;
127 e3a4e4b6 bellard
        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
128 a5082316 bellard
            if ((bitmask & 0xff) == 0) {
129 a5082316 bellard
                bitmask = 0x80;
130 b30d4608 bellard
                bits = *src++ ^ bits_xor;
131 a5082316 bellard
            }
132 a5082316 bellard
            index = (bits & bitmask);
133 a5082316 bellard
            if (index) {
134 a5082316 bellard
                PUTPIXEL();
135 a5082316 bellard
            }
136 a5082316 bellard
            d += (DEPTH / 8);
137 a5082316 bellard
            bitmask >>= 1;
138 a5082316 bellard
        }
139 4c8732d7 bellard
        dst += dstpitch;
140 4c8732d7 bellard
    }
141 4c8732d7 bellard
}
142 4c8732d7 bellard
143 4c8732d7 bellard
static void
144 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
145 4c8732d7 bellard
     (CirrusVGAState * s, uint8_t * dst,
146 5fafdf24 ths
      const uint8_t * src,
147 5fafdf24 ths
      int dstpitch, int srcpitch,
148 4c8732d7 bellard
      int bltwidth, int bltheight)
149 4c8732d7 bellard
{
150 b30d4608 bellard
    uint32_t colors[2];
151 4c8732d7 bellard
    uint8_t *d;
152 4c8732d7 bellard
    int x, y;
153 4c8732d7 bellard
    unsigned bits;
154 4c8732d7 bellard
    unsigned int col;
155 4c8732d7 bellard
    unsigned bitmask;
156 4e12cd94 Avi Kivity
    int srcskipleft = s->vga.gr[0x2f] & 0x07;
157 e3a4e4b6 bellard
    int dstskipleft = srcskipleft * (DEPTH / 8);
158 4c8732d7 bellard
159 b30d4608 bellard
    colors[0] = s->cirrus_blt_bgcol;
160 b30d4608 bellard
    colors[1] = s->cirrus_blt_fgcol;
161 4c8732d7 bellard
    for(y = 0; y < bltheight; y++) {
162 4c8732d7 bellard
        bitmask = 0x80 >> srcskipleft;
163 4c8732d7 bellard
        bits = *src++;
164 e3a4e4b6 bellard
        d = dst + dstskipleft;
165 e3a4e4b6 bellard
        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
166 4c8732d7 bellard
            if ((bitmask & 0xff) == 0) {
167 4c8732d7 bellard
                bitmask = 0x80;
168 4c8732d7 bellard
                bits = *src++;
169 4c8732d7 bellard
            }
170 b30d4608 bellard
            col = colors[!!(bits & bitmask)];
171 b30d4608 bellard
            PUTPIXEL();
172 b30d4608 bellard
            d += (DEPTH / 8);
173 b30d4608 bellard
            bitmask >>= 1;
174 b30d4608 bellard
        }
175 b30d4608 bellard
        dst += dstpitch;
176 b30d4608 bellard
    }
177 b30d4608 bellard
}
178 b30d4608 bellard
179 b30d4608 bellard
static void
180 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
181 b30d4608 bellard
     (CirrusVGAState * s, uint8_t * dst,
182 5fafdf24 ths
      const uint8_t * src,
183 5fafdf24 ths
      int dstpitch, int srcpitch,
184 b30d4608 bellard
      int bltwidth, int bltheight)
185 b30d4608 bellard
{
186 b30d4608 bellard
    uint8_t *d;
187 b30d4608 bellard
    int x, y, bitpos, pattern_y;
188 b30d4608 bellard
    unsigned int bits, bits_xor;
189 b30d4608 bellard
    unsigned int col;
190 ad81218e bellard
#if DEPTH == 24
191 4e12cd94 Avi Kivity
    int dstskipleft = s->vga.gr[0x2f] & 0x1f;
192 ad81218e bellard
    int srcskipleft = dstskipleft / 3;
193 ad81218e bellard
#else
194 4e12cd94 Avi Kivity
    int srcskipleft = s->vga.gr[0x2f] & 0x07;
195 e3a4e4b6 bellard
    int dstskipleft = srcskipleft * (DEPTH / 8);
196 ad81218e bellard
#endif
197 b30d4608 bellard
198 b30d4608 bellard
    if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
199 b30d4608 bellard
        bits_xor = 0xff;
200 b30d4608 bellard
        col = s->cirrus_blt_bgcol;
201 b30d4608 bellard
    } else {
202 b30d4608 bellard
        bits_xor = 0x00;
203 b30d4608 bellard
        col = s->cirrus_blt_fgcol;
204 b30d4608 bellard
    }
205 b30d4608 bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
206 b30d4608 bellard
207 b30d4608 bellard
    for(y = 0; y < bltheight; y++) {
208 b30d4608 bellard
        bits = src[pattern_y] ^ bits_xor;
209 e3a4e4b6 bellard
        bitpos = 7 - srcskipleft;
210 e3a4e4b6 bellard
        d = dst + dstskipleft;
211 e3a4e4b6 bellard
        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
212 b30d4608 bellard
            if ((bits >> bitpos) & 1) {
213 4c8732d7 bellard
                PUTPIXEL();
214 4c8732d7 bellard
            }
215 4c8732d7 bellard
            d += (DEPTH / 8);
216 b30d4608 bellard
            bitpos = (bitpos - 1) & 7;
217 4c8732d7 bellard
        }
218 b30d4608 bellard
        pattern_y = (pattern_y + 1) & 7;
219 a5082316 bellard
        dst += dstpitch;
220 a5082316 bellard
    }
221 a5082316 bellard
}
222 a5082316 bellard
223 a5082316 bellard
static void
224 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
225 a5082316 bellard
     (CirrusVGAState * s, uint8_t * dst,
226 5fafdf24 ths
      const uint8_t * src,
227 5fafdf24 ths
      int dstpitch, int srcpitch,
228 a5082316 bellard
      int bltwidth, int bltheight)
229 a5082316 bellard
{
230 a5082316 bellard
    uint32_t colors[2];
231 a5082316 bellard
    uint8_t *d;
232 b30d4608 bellard
    int x, y, bitpos, pattern_y;
233 b30d4608 bellard
    unsigned int bits;
234 a5082316 bellard
    unsigned int col;
235 4e12cd94 Avi Kivity
    int srcskipleft = s->vga.gr[0x2f] & 0x07;
236 e3a4e4b6 bellard
    int dstskipleft = srcskipleft * (DEPTH / 8);
237 a5082316 bellard
238 a5082316 bellard
    colors[0] = s->cirrus_blt_bgcol;
239 a5082316 bellard
    colors[1] = s->cirrus_blt_fgcol;
240 b30d4608 bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
241 b30d4608 bellard
242 a5082316 bellard
    for(y = 0; y < bltheight; y++) {
243 b30d4608 bellard
        bits = src[pattern_y];
244 e3a4e4b6 bellard
        bitpos = 7 - srcskipleft;
245 e3a4e4b6 bellard
        d = dst + dstskipleft;
246 e3a4e4b6 bellard
        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
247 b30d4608 bellard
            col = colors[(bits >> bitpos) & 1];
248 a5082316 bellard
            PUTPIXEL();
249 a5082316 bellard
            d += (DEPTH / 8);
250 b30d4608 bellard
            bitpos = (bitpos - 1) & 7;
251 a5082316 bellard
        }
252 b30d4608 bellard
        pattern_y = (pattern_y + 1) & 7;
253 a5082316 bellard
        dst += dstpitch;
254 a5082316 bellard
    }
255 a5082316 bellard
}
256 a5082316 bellard
257 5fafdf24 ths
static void
258 a5082316 bellard
glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
259 a5082316 bellard
     (CirrusVGAState *s,
260 5fafdf24 ths
      uint8_t *dst, int dst_pitch,
261 a5082316 bellard
      int width, int height)
262 a5082316 bellard
{
263 a5082316 bellard
    uint8_t *d, *d1;
264 a5082316 bellard
    uint32_t col;
265 a5082316 bellard
    int x, y;
266 a5082316 bellard
267 a5082316 bellard
    col = s->cirrus_blt_fgcol;
268 a5082316 bellard
269 a5082316 bellard
    d1 = dst;
270 a5082316 bellard
    for(y = 0; y < height; y++) {
271 a5082316 bellard
        d = d1;
272 a5082316 bellard
        for(x = 0; x < width; x += (DEPTH / 8)) {
273 a5082316 bellard
            PUTPIXEL();
274 a5082316 bellard
            d += (DEPTH / 8);
275 a5082316 bellard
        }
276 a5082316 bellard
        d1 += dst_pitch;
277 a5082316 bellard
    }
278 a5082316 bellard
}
279 a5082316 bellard
280 a5082316 bellard
#undef DEPTH
281 a5082316 bellard
#undef PUTPIXEL