cirrus: stop passing around dst pointers in the blitter
[qemu.git] / hw / display / cirrus_vga_rop2.h
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
25 #if DEPTH == 8
26 #define PUTPIXEL(s, a, c) ROP_OP(s, a, c)
27 #elif DEPTH == 16
28 #define PUTPIXEL(s, a, c) ROP_OP_16(s, a, c)
29 #elif DEPTH == 24
30 #define PUTPIXEL(s, a, c) do { \
31 ROP_OP(s, a, c); \
32 ROP_OP(s, a + 1, (col >> 8)); \
33 ROP_OP(s, a + 2, (col >> 16)); \
34 } while (0)
35 #elif DEPTH == 32
36 #define PUTPIXEL(s, a, c) ROP_OP_32(s, a, c)
37 #else
38 #error unsupported DEPTH
39 #endif
40
41 static void
42 glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
43 (CirrusVGAState *s, uint32_t dstaddr,
44 const uint8_t *src,
45 int dstpitch, int srcpitch,
46 int bltwidth, int bltheight)
47 {
48 uint32_t addr;
49 int x, y, pattern_y, pattern_pitch, pattern_x;
50 unsigned int col;
51 const uint8_t *src1;
52 #if DEPTH == 24
53 int skipleft = s->vga.gr[0x2f] & 0x1f;
54 #else
55 int skipleft = (s->vga.gr[0x2f] & 0x07) * (DEPTH / 8);
56 #endif
57
58 #if DEPTH == 8
59 pattern_pitch = 8;
60 #elif DEPTH == 16
61 pattern_pitch = 16;
62 #else
63 pattern_pitch = 32;
64 #endif
65 pattern_y = s->cirrus_blt_srcaddr & 7;
66 for(y = 0; y < bltheight; y++) {
67 pattern_x = skipleft;
68 addr = dstaddr + skipleft;
69 src1 = src + pattern_y * pattern_pitch;
70 for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
71 #if DEPTH == 8
72 col = src1[pattern_x];
73 pattern_x = (pattern_x + 1) & 7;
74 #elif DEPTH == 16
75 col = ((uint16_t *)(src1 + pattern_x))[0];
76 pattern_x = (pattern_x + 2) & 15;
77 #elif DEPTH == 24
78 {
79 const uint8_t *src2 = src1 + pattern_x * 3;
80 col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
81 pattern_x = (pattern_x + 1) & 7;
82 }
83 #else
84 col = ((uint32_t *)(src1 + pattern_x))[0];
85 pattern_x = (pattern_x + 4) & 31;
86 #endif
87 PUTPIXEL(s, addr, col);
88 addr += (DEPTH / 8);
89 }
90 pattern_y = (pattern_y + 1) & 7;
91 dstaddr += dstpitch;
92 }
93 }
94
95 /* NOTE: srcpitch is ignored */
96 static void
97 glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
98 (CirrusVGAState *s, uint32_t dstaddr,
99 const uint8_t *src,
100 int dstpitch, int srcpitch,
101 int bltwidth, int bltheight)
102 {
103 uint32_t addr;
104 int x, y;
105 unsigned bits, bits_xor;
106 unsigned int col;
107 unsigned bitmask;
108 unsigned index;
109 #if DEPTH == 24
110 int dstskipleft = s->vga.gr[0x2f] & 0x1f;
111 int srcskipleft = dstskipleft / 3;
112 #else
113 int srcskipleft = s->vga.gr[0x2f] & 0x07;
114 int dstskipleft = srcskipleft * (DEPTH / 8);
115 #endif
116
117 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
118 bits_xor = 0xff;
119 col = s->cirrus_blt_bgcol;
120 } else {
121 bits_xor = 0x00;
122 col = s->cirrus_blt_fgcol;
123 }
124
125 for(y = 0; y < bltheight; y++) {
126 bitmask = 0x80 >> srcskipleft;
127 bits = *src++ ^ bits_xor;
128 addr = dstaddr + dstskipleft;
129 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
130 if ((bitmask & 0xff) == 0) {
131 bitmask = 0x80;
132 bits = *src++ ^ bits_xor;
133 }
134 index = (bits & bitmask);
135 if (index) {
136 PUTPIXEL(s, addr, col);
137 }
138 addr += (DEPTH / 8);
139 bitmask >>= 1;
140 }
141 dstaddr += dstpitch;
142 }
143 }
144
145 static void
146 glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
147 (CirrusVGAState *s, uint32_t dstaddr,
148 const uint8_t *src,
149 int dstpitch, int srcpitch,
150 int bltwidth, int bltheight)
151 {
152 uint32_t colors[2];
153 uint32_t addr;
154 int x, y;
155 unsigned bits;
156 unsigned int col;
157 unsigned bitmask;
158 int srcskipleft = s->vga.gr[0x2f] & 0x07;
159 int dstskipleft = srcskipleft * (DEPTH / 8);
160
161 colors[0] = s->cirrus_blt_bgcol;
162 colors[1] = s->cirrus_blt_fgcol;
163 for(y = 0; y < bltheight; y++) {
164 bitmask = 0x80 >> srcskipleft;
165 bits = *src++;
166 addr = dstaddr + dstskipleft;
167 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
168 if ((bitmask & 0xff) == 0) {
169 bitmask = 0x80;
170 bits = *src++;
171 }
172 col = colors[!!(bits & bitmask)];
173 PUTPIXEL(s, addr, col);
174 addr += (DEPTH / 8);
175 bitmask >>= 1;
176 }
177 dstaddr += dstpitch;
178 }
179 }
180
181 static void
182 glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
183 (CirrusVGAState *s, uint32_t dstaddr,
184 const uint8_t *src,
185 int dstpitch, int srcpitch,
186 int bltwidth, int bltheight)
187 {
188 uint32_t addr;
189 int x, y, bitpos, pattern_y;
190 unsigned int bits, bits_xor;
191 unsigned int col;
192 #if DEPTH == 24
193 int dstskipleft = s->vga.gr[0x2f] & 0x1f;
194 int srcskipleft = dstskipleft / 3;
195 #else
196 int srcskipleft = s->vga.gr[0x2f] & 0x07;
197 int dstskipleft = srcskipleft * (DEPTH / 8);
198 #endif
199
200 if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
201 bits_xor = 0xff;
202 col = s->cirrus_blt_bgcol;
203 } else {
204 bits_xor = 0x00;
205 col = s->cirrus_blt_fgcol;
206 }
207 pattern_y = s->cirrus_blt_srcaddr & 7;
208
209 for(y = 0; y < bltheight; y++) {
210 bits = src[pattern_y] ^ bits_xor;
211 bitpos = 7 - srcskipleft;
212 addr = dstaddr + dstskipleft;
213 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
214 if ((bits >> bitpos) & 1) {
215 PUTPIXEL(s, addr, col);
216 }
217 addr += (DEPTH / 8);
218 bitpos = (bitpos - 1) & 7;
219 }
220 pattern_y = (pattern_y + 1) & 7;
221 dstaddr += dstpitch;
222 }
223 }
224
225 static void
226 glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
227 (CirrusVGAState *s, uint32_t dstaddr,
228 const uint8_t *src,
229 int dstpitch, int srcpitch,
230 int bltwidth, int bltheight)
231 {
232 uint32_t colors[2];
233 uint32_t addr;
234 int x, y, bitpos, pattern_y;
235 unsigned int bits;
236 unsigned int col;
237 int srcskipleft = s->vga.gr[0x2f] & 0x07;
238 int dstskipleft = srcskipleft * (DEPTH / 8);
239
240 colors[0] = s->cirrus_blt_bgcol;
241 colors[1] = s->cirrus_blt_fgcol;
242 pattern_y = s->cirrus_blt_srcaddr & 7;
243
244 for(y = 0; y < bltheight; y++) {
245 bits = src[pattern_y];
246 bitpos = 7 - srcskipleft;
247 addr = dstaddr + dstskipleft;
248 for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
249 col = colors[(bits >> bitpos) & 1];
250 PUTPIXEL(s, addr, col);
251 addr += (DEPTH / 8);
252 bitpos = (bitpos - 1) & 7;
253 }
254 pattern_y = (pattern_y + 1) & 7;
255 dstaddr += dstpitch;
256 }
257 }
258
259 static void
260 glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
261 (CirrusVGAState *s,
262 uint32_t dstaddr, int dst_pitch,
263 int width, int height)
264 {
265 uint32_t addr;
266 uint32_t col;
267 int x, y;
268
269 col = s->cirrus_blt_fgcol;
270
271 for(y = 0; y < height; y++) {
272 addr = dstaddr;
273 for(x = 0; x < width; x += (DEPTH / 8)) {
274 PUTPIXEL(s, addr, col);
275 addr += (DEPTH / 8);
276 }
277 dstaddr += dst_pitch;
278 }
279 }
280
281 #undef DEPTH
282 #undef PUTPIXEL