2 * QEMU Cirrus CLGD 54xx VGA Emulator.
4 * Copyright (c) 2004 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
26 #define PUTPIXEL() ROP_OP(d[0], col)
28 #define PUTPIXEL() ROP_OP(((uint16_t *)d)[0], col);
30 #define PUTPIXEL() ROP_OP(d[0], col); \
31 ROP_OP(d[1], (col >> 8)); \
32 ROP_OP(d[2], (col >> 16))
34 #define PUTPIXEL() ROP_OP(((uint32_t *)d)[0], col)
36 #error unsupported DEPTH
40 glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
41 (CirrusVGAState * s, uint8_t * dst,
43 int dstpitch, int srcpitch,
44 int bltwidth, int bltheight)
47 int x, y, pattern_y, pattern_pitch, pattern_x;
50 int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
59 pattern_y = s->cirrus_blt_srcaddr & 7;
61 for(y = 0; y < bltheight; y++) {
63 src1 = src + pattern_y * pattern_pitch;
64 for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
66 col = src1[pattern_x];
67 pattern_x = (pattern_x + 1) & 7;
69 col = ((uint16_t *)(src1 + pattern_x))[0];
70 pattern_x = (pattern_x + 2) & 15;
73 const uint8_t *src2 = src1 + pattern_x * 3;
74 col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
75 pattern_x = (pattern_x + 1) & 7;
78 col = ((uint32_t *)(src1 + pattern_x))[0];
79 pattern_x = (pattern_x + 4) & 31;
84 pattern_y = (pattern_y + 1) & 7;
89 /* NOTE: srcpitch is ignored */
91 glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
92 (CirrusVGAState * s, uint8_t * dst,
94 int dstpitch, int srcpitch,
95 int bltwidth, int bltheight)
99 unsigned bits, bits_xor;
103 int srcskipleft = s->gr[0x2f] & 0x07;
104 int dstskipleft = srcskipleft * (DEPTH / 8);
106 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
108 col = s->cirrus_blt_bgcol;
111 col = s->cirrus_blt_fgcol;
114 for(y = 0; y < bltheight; y++) {
115 bitmask = 0x80 >> srcskipleft;
116 bits = *src++ ^ bits_xor;
117 d = dst + dstskipleft;
118 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
119 if ((bitmask & 0xff) == 0) {
121 bits = *src++ ^ bits_xor;
123 index = (bits & bitmask);
135 glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
136 (CirrusVGAState * s, uint8_t * dst,
138 int dstpitch, int srcpitch,
139 int bltwidth, int bltheight)
147 int srcskipleft = s->gr[0x2f] & 0x07;
148 int dstskipleft = srcskipleft * (DEPTH / 8);
150 colors[0] = s->cirrus_blt_bgcol;
151 colors[1] = s->cirrus_blt_fgcol;
152 for(y = 0; y < bltheight; y++) {
153 bitmask = 0x80 >> srcskipleft;
155 d = dst + dstskipleft;
156 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
157 if ((bitmask & 0xff) == 0) {
161 col = colors[!!(bits & bitmask)];
171 glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
172 (CirrusVGAState * s, uint8_t * dst,
174 int dstpitch, int srcpitch,
175 int bltwidth, int bltheight)
178 int x, y, bitpos, pattern_y;
179 unsigned int bits, bits_xor;
181 int srcskipleft = s->gr[0x2f] & 0x07;
182 int dstskipleft = srcskipleft * (DEPTH / 8);
184 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
186 col = s->cirrus_blt_bgcol;
189 col = s->cirrus_blt_fgcol;
191 pattern_y = s->cirrus_blt_srcaddr & 7;
193 for(y = 0; y < bltheight; y++) {
194 bits = src[pattern_y] ^ bits_xor;
195 bitpos = 7 - srcskipleft;
196 d = dst + dstskipleft;
197 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
198 if ((bits >> bitpos) & 1) {
202 bitpos = (bitpos - 1) & 7;
204 pattern_y = (pattern_y + 1) & 7;
210 glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
211 (CirrusVGAState * s, uint8_t * dst,
213 int dstpitch, int srcpitch,
214 int bltwidth, int bltheight)
218 int x, y, bitpos, pattern_y;
221 int srcskipleft = s->gr[0x2f] & 0x07;
222 int dstskipleft = srcskipleft * (DEPTH / 8);
224 colors[0] = s->cirrus_blt_bgcol;
225 colors[1] = s->cirrus_blt_fgcol;
226 pattern_y = s->cirrus_blt_srcaddr & 7;
228 for(y = 0; y < bltheight; y++) {
229 bits = src[pattern_y];
230 bitpos = 7 - srcskipleft;
231 d = dst + dstskipleft;
232 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
233 col = colors[(bits >> bitpos) & 1];
236 bitpos = (bitpos - 1) & 7;
238 pattern_y = (pattern_y + 1) & 7;
244 glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
246 uint8_t *dst, int dst_pitch,
247 int width, int height)
253 col = s->cirrus_blt_fgcol;
256 for(y = 0; y < height; y++) {
258 for(x = 0; x < width; x += (DEPTH / 8)) {