Statistics
| Branch: | Revision:

root / hw / cirrus_vga_rop2.h @ 546fa6ab

History | View | Annotate | Download (7.1 kB)

1 a5082316 bellard
/*
2 a5082316 bellard
 * QEMU Cirrus CLGD 54xx VGA Emulator.
3 a5082316 bellard
 * 
4 a5082316 bellard
 * Copyright (c) 2004 Fabrice Bellard
5 a5082316 bellard
 * 
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 a5082316 bellard
#define PUTPIXEL()    ROP_OP(d[0], col)
27 a5082316 bellard
#elif DEPTH == 16
28 a5082316 bellard
#define PUTPIXEL()    ROP_OP(((uint16_t *)d)[0], col);
29 a5082316 bellard
#elif DEPTH == 24
30 a5082316 bellard
#define PUTPIXEL()    ROP_OP(d[0], col); \
31 a5082316 bellard
                      ROP_OP(d[1], (col >> 8)); \
32 a5082316 bellard
                      ROP_OP(d[2], (col >> 16))
33 a5082316 bellard
#elif DEPTH == 32
34 a5082316 bellard
#define PUTPIXEL()    ROP_OP(((uint32_t *)d)[0], col)
35 a5082316 bellard
#else
36 a5082316 bellard
#error unsupported DEPTH
37 a5082316 bellard
#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 e69390ce bellard
      const uint8_t * src, 
43 e69390ce bellard
      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 e69390ce bellard
51 e69390ce bellard
#if DEPTH == 8
52 e69390ce bellard
    pattern_pitch = 8;
53 e69390ce bellard
#elif DEPTH == 16
54 e69390ce bellard
    pattern_pitch = 16;
55 e69390ce bellard
#else
56 e69390ce bellard
    pattern_pitch = 32;
57 e69390ce bellard
#endif
58 e69390ce bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
59 e69390ce bellard
    pattern_x = 0;
60 e69390ce bellard
    for(y = 0; y < bltheight; y++) {
61 e69390ce bellard
        d = dst;
62 e69390ce bellard
        src1 = src + pattern_y * pattern_pitch;
63 e69390ce bellard
        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
64 e69390ce bellard
#if DEPTH == 8
65 e69390ce bellard
            col = src1[pattern_x];
66 e69390ce bellard
            pattern_x = (pattern_x + 1) & 7;
67 e69390ce bellard
#elif DEPTH == 16
68 e69390ce bellard
            col = ((uint16_t *)(src1 + pattern_x))[0];
69 e69390ce bellard
            pattern_x = (pattern_x + 2) & 15;
70 b30d4608 bellard
#elif DEPTH == 24
71 b30d4608 bellard
            {
72 b30d4608 bellard
                const uint8_t *src2 = src1 + pattern_x * 3;
73 b30d4608 bellard
                col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
74 b30d4608 bellard
                pattern_x = (pattern_x + 1) & 7;
75 b30d4608 bellard
            }
76 e69390ce bellard
#else
77 e69390ce bellard
            col = ((uint32_t *)(src1 + pattern_x))[0];
78 e69390ce bellard
            pattern_x = (pattern_x + 4) & 31;
79 e69390ce bellard
#endif
80 e69390ce bellard
            PUTPIXEL();
81 e69390ce bellard
            d += (DEPTH / 8);
82 e69390ce bellard
        }
83 e69390ce bellard
        pattern_y = (pattern_y + 1) & 7;
84 e69390ce bellard
        dst += dstpitch;
85 e69390ce bellard
    }
86 e69390ce bellard
}
87 e69390ce bellard
88 4c8732d7 bellard
/* NOTE: srcpitch is ignored */
89 a5082316 bellard
static void
90 a5082316 bellard
glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
91 a5082316 bellard
     (CirrusVGAState * s, uint8_t * dst,
92 4c8732d7 bellard
      const uint8_t * src, 
93 a5082316 bellard
      int dstpitch, int srcpitch, 
94 a5082316 bellard
      int bltwidth, int bltheight)
95 a5082316 bellard
{
96 a5082316 bellard
    uint8_t *d;
97 a5082316 bellard
    int x, y;
98 b30d4608 bellard
    unsigned bits, bits_xor;
99 a5082316 bellard
    unsigned int col;
100 a5082316 bellard
    unsigned bitmask;
101 a5082316 bellard
    unsigned index;
102 a5082316 bellard
    int srcskipleft = 0;
103 a5082316 bellard
104 b30d4608 bellard
    if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
105 b30d4608 bellard
        bits_xor = 0xff;
106 b30d4608 bellard
        col = s->cirrus_blt_bgcol;
107 b30d4608 bellard
    } else {
108 b30d4608 bellard
        bits_xor = 0x00;
109 b30d4608 bellard
        col = s->cirrus_blt_fgcol;
110 b30d4608 bellard
    }
111 b30d4608 bellard
112 a5082316 bellard
    for(y = 0; y < bltheight; y++) {
113 a5082316 bellard
        bitmask = 0x80 >> srcskipleft;
114 b30d4608 bellard
        bits = *src++ ^ bits_xor;
115 a5082316 bellard
        d = dst;
116 a5082316 bellard
        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
117 a5082316 bellard
            if ((bitmask & 0xff) == 0) {
118 a5082316 bellard
                bitmask = 0x80;
119 b30d4608 bellard
                bits = *src++ ^ bits_xor;
120 a5082316 bellard
            }
121 a5082316 bellard
            index = (bits & bitmask);
122 a5082316 bellard
            if (index) {
123 a5082316 bellard
                PUTPIXEL();
124 a5082316 bellard
            }
125 a5082316 bellard
            d += (DEPTH / 8);
126 a5082316 bellard
            bitmask >>= 1;
127 a5082316 bellard
        }
128 4c8732d7 bellard
        dst += dstpitch;
129 4c8732d7 bellard
    }
130 4c8732d7 bellard
}
131 4c8732d7 bellard
132 4c8732d7 bellard
static void
133 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
134 4c8732d7 bellard
     (CirrusVGAState * s, uint8_t * dst,
135 4c8732d7 bellard
      const uint8_t * src, 
136 4c8732d7 bellard
      int dstpitch, int srcpitch, 
137 4c8732d7 bellard
      int bltwidth, int bltheight)
138 4c8732d7 bellard
{
139 b30d4608 bellard
    uint32_t colors[2];
140 4c8732d7 bellard
    uint8_t *d;
141 4c8732d7 bellard
    int x, y;
142 4c8732d7 bellard
    unsigned bits;
143 4c8732d7 bellard
    unsigned int col;
144 4c8732d7 bellard
    unsigned bitmask;
145 4c8732d7 bellard
    int srcskipleft = 0;
146 4c8732d7 bellard
147 b30d4608 bellard
    colors[0] = s->cirrus_blt_bgcol;
148 b30d4608 bellard
    colors[1] = s->cirrus_blt_fgcol;
149 4c8732d7 bellard
    for(y = 0; y < bltheight; y++) {
150 4c8732d7 bellard
        bitmask = 0x80 >> srcskipleft;
151 4c8732d7 bellard
        bits = *src++;
152 4c8732d7 bellard
        d = dst;
153 4c8732d7 bellard
        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
154 4c8732d7 bellard
            if ((bitmask & 0xff) == 0) {
155 4c8732d7 bellard
                bitmask = 0x80;
156 4c8732d7 bellard
                bits = *src++;
157 4c8732d7 bellard
            }
158 b30d4608 bellard
            col = colors[!!(bits & bitmask)];
159 b30d4608 bellard
            PUTPIXEL();
160 b30d4608 bellard
            d += (DEPTH / 8);
161 b30d4608 bellard
            bitmask >>= 1;
162 b30d4608 bellard
        }
163 b30d4608 bellard
        dst += dstpitch;
164 b30d4608 bellard
    }
165 b30d4608 bellard
}
166 b30d4608 bellard
167 b30d4608 bellard
static void
168 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
169 b30d4608 bellard
     (CirrusVGAState * s, uint8_t * dst,
170 b30d4608 bellard
      const uint8_t * src, 
171 b30d4608 bellard
      int dstpitch, int srcpitch, 
172 b30d4608 bellard
      int bltwidth, int bltheight)
173 b30d4608 bellard
{
174 b30d4608 bellard
    uint8_t *d;
175 b30d4608 bellard
    int x, y, bitpos, pattern_y;
176 b30d4608 bellard
    unsigned int bits, bits_xor;
177 b30d4608 bellard
    unsigned int col;
178 b30d4608 bellard
179 b30d4608 bellard
    if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
180 b30d4608 bellard
        bits_xor = 0xff;
181 b30d4608 bellard
        col = s->cirrus_blt_bgcol;
182 b30d4608 bellard
    } else {
183 b30d4608 bellard
        bits_xor = 0x00;
184 b30d4608 bellard
        col = s->cirrus_blt_fgcol;
185 b30d4608 bellard
    }
186 b30d4608 bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
187 b30d4608 bellard
188 b30d4608 bellard
    for(y = 0; y < bltheight; y++) {
189 b30d4608 bellard
        bits = src[pattern_y] ^ bits_xor;
190 b30d4608 bellard
        bitpos = 7;
191 b30d4608 bellard
        d = dst;
192 b30d4608 bellard
        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
193 b30d4608 bellard
            if ((bits >> bitpos) & 1) {
194 4c8732d7 bellard
                PUTPIXEL();
195 4c8732d7 bellard
            }
196 4c8732d7 bellard
            d += (DEPTH / 8);
197 b30d4608 bellard
            bitpos = (bitpos - 1) & 7;
198 4c8732d7 bellard
        }
199 b30d4608 bellard
        pattern_y = (pattern_y + 1) & 7;
200 a5082316 bellard
        dst += dstpitch;
201 a5082316 bellard
    }
202 a5082316 bellard
}
203 a5082316 bellard
204 a5082316 bellard
static void
205 b30d4608 bellard
glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
206 a5082316 bellard
     (CirrusVGAState * s, uint8_t * dst,
207 4c8732d7 bellard
      const uint8_t * src, 
208 a5082316 bellard
      int dstpitch, int srcpitch, 
209 a5082316 bellard
      int bltwidth, int bltheight)
210 a5082316 bellard
{
211 a5082316 bellard
    uint32_t colors[2];
212 a5082316 bellard
    uint8_t *d;
213 b30d4608 bellard
    int x, y, bitpos, pattern_y;
214 b30d4608 bellard
    unsigned int bits;
215 a5082316 bellard
    unsigned int col;
216 a5082316 bellard
217 a5082316 bellard
    colors[0] = s->cirrus_blt_bgcol;
218 a5082316 bellard
    colors[1] = s->cirrus_blt_fgcol;
219 b30d4608 bellard
    pattern_y = s->cirrus_blt_srcaddr & 7;
220 b30d4608 bellard
221 a5082316 bellard
    for(y = 0; y < bltheight; y++) {
222 b30d4608 bellard
        bits = src[pattern_y];
223 b30d4608 bellard
        bitpos = 7;
224 a5082316 bellard
        d = dst;
225 a5082316 bellard
        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
226 b30d4608 bellard
            col = colors[(bits >> bitpos) & 1];
227 a5082316 bellard
            PUTPIXEL();
228 a5082316 bellard
            d += (DEPTH / 8);
229 b30d4608 bellard
            bitpos = (bitpos - 1) & 7;
230 a5082316 bellard
        }
231 b30d4608 bellard
        pattern_y = (pattern_y + 1) & 7;
232 a5082316 bellard
        dst += dstpitch;
233 a5082316 bellard
    }
234 a5082316 bellard
}
235 a5082316 bellard
236 a5082316 bellard
static void 
237 a5082316 bellard
glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
238 a5082316 bellard
     (CirrusVGAState *s,
239 a5082316 bellard
      uint8_t *dst, int dst_pitch, 
240 a5082316 bellard
      int width, int height)
241 a5082316 bellard
{
242 a5082316 bellard
    uint8_t *d, *d1;
243 a5082316 bellard
    uint32_t col;
244 a5082316 bellard
    int x, y;
245 a5082316 bellard
246 a5082316 bellard
    col = s->cirrus_blt_fgcol;
247 a5082316 bellard
248 a5082316 bellard
    d1 = dst;
249 a5082316 bellard
    for(y = 0; y < height; y++) {
250 a5082316 bellard
        d = d1;
251 a5082316 bellard
        for(x = 0; x < width; x += (DEPTH / 8)) {
252 a5082316 bellard
            PUTPIXEL();
253 a5082316 bellard
            d += (DEPTH / 8);
254 a5082316 bellard
        }
255 a5082316 bellard
        d1 += dst_pitch;
256 a5082316 bellard
    }
257 a5082316 bellard
}
258 a5082316 bellard
259 a5082316 bellard
#undef DEPTH
260 a5082316 bellard
#undef PUTPIXEL