Statistics
| Branch: | Revision:

root / hw / vga_template.h @ 546fa6ab

History | View | Annotate | Download (15.6 kB)

1 e89f66ec bellard
/*
2 e89f66ec bellard
 * QEMU VGA Emulator templates
3 e89f66ec bellard
 * 
4 e89f66ec bellard
 * Copyright (c) 2003 Fabrice Bellard
5 e89f66ec bellard
 * 
6 e89f66ec bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 e89f66ec bellard
 * of this software and associated documentation files (the "Software"), to deal
8 e89f66ec bellard
 * in the Software without restriction, including without limitation the rights
9 e89f66ec bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 e89f66ec bellard
 * copies of the Software, and to permit persons to whom the Software is
11 e89f66ec bellard
 * furnished to do so, subject to the following conditions:
12 e89f66ec bellard
 *
13 e89f66ec bellard
 * The above copyright notice and this permission notice shall be included in
14 e89f66ec bellard
 * all copies or substantial portions of the Software.
15 e89f66ec bellard
 *
16 e89f66ec bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 e89f66ec bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 e89f66ec bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 e89f66ec bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 e89f66ec bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 e89f66ec bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 e89f66ec bellard
 * THE SOFTWARE.
23 e89f66ec bellard
 */
24 e89f66ec bellard
25 e89f66ec bellard
#if DEPTH == 8
26 e89f66ec bellard
#define BPP 1
27 e89f66ec bellard
#define PIXEL_TYPE uint8_t 
28 e89f66ec bellard
#elif DEPTH == 15 || DEPTH == 16
29 e89f66ec bellard
#define BPP 2
30 e89f66ec bellard
#define PIXEL_TYPE uint16_t 
31 e89f66ec bellard
#elif DEPTH == 32
32 e89f66ec bellard
#define BPP 4
33 e89f66ec bellard
#define PIXEL_TYPE uint32_t 
34 e89f66ec bellard
#else
35 e89f66ec bellard
#error unsupport depth
36 e89f66ec bellard
#endif
37 e89f66ec bellard
38 e89f66ec bellard
#if DEPTH != 15
39 e89f66ec bellard
40 17b0018b bellard
static inline void glue(vga_draw_glyph_line_, DEPTH)(uint8_t *d, 
41 17b0018b bellard
                                                     uint32_t font_data,
42 17b0018b bellard
                                                     uint32_t xorcol, 
43 17b0018b bellard
                                                     uint32_t bgcol)
44 e89f66ec bellard
{
45 e89f66ec bellard
#if BPP == 1
46 e89f66ec bellard
        ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;
47 188d8579 bellard
        ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
48 e89f66ec bellard
#elif BPP == 2
49 e89f66ec bellard
        ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;
50 e89f66ec bellard
        ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;
51 e89f66ec bellard
        ((uint32_t *)d)[2] = (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol;
52 e89f66ec bellard
        ((uint32_t *)d)[3] = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol;
53 e89f66ec bellard
#else
54 b1ba6574 bellard
        ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;
55 b1ba6574 bellard
        ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;
56 b1ba6574 bellard
        ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol;
57 b1ba6574 bellard
        ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol;
58 b1ba6574 bellard
        ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol;
59 b1ba6574 bellard
        ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol;
60 b1ba6574 bellard
        ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol;
61 b1ba6574 bellard
        ((uint32_t *)d)[7] = (-((font_data >> 0) & 1) & xorcol) ^ bgcol;
62 e89f66ec bellard
#endif
63 17b0018b bellard
}
64 17b0018b bellard
65 17b0018b bellard
static void glue(vga_draw_glyph8_, DEPTH)(uint8_t *d, int linesize,
66 17b0018b bellard
                                          const uint8_t *font_ptr, int h,
67 17b0018b bellard
                                          uint32_t fgcol, uint32_t bgcol)
68 17b0018b bellard
{
69 17b0018b bellard
    uint32_t font_data, xorcol;
70 17b0018b bellard
    
71 17b0018b bellard
    xorcol = bgcol ^ fgcol;
72 17b0018b bellard
    do {
73 17b0018b bellard
        font_data = font_ptr[0];
74 17b0018b bellard
        glue(vga_draw_glyph_line_, DEPTH)(d, font_data, xorcol, bgcol);
75 17b0018b bellard
        font_ptr += 4;
76 17b0018b bellard
        d += linesize;
77 17b0018b bellard
    } while (--h);
78 17b0018b bellard
}
79 17b0018b bellard
80 17b0018b bellard
static void glue(vga_draw_glyph16_, DEPTH)(uint8_t *d, int linesize,
81 17b0018b bellard
                                          const uint8_t *font_ptr, int h,
82 17b0018b bellard
                                          uint32_t fgcol, uint32_t bgcol)
83 17b0018b bellard
{
84 17b0018b bellard
    uint32_t font_data, xorcol;
85 17b0018b bellard
    
86 17b0018b bellard
    xorcol = bgcol ^ fgcol;
87 17b0018b bellard
    do {
88 17b0018b bellard
        font_data = font_ptr[0];
89 17b0018b bellard
        glue(vga_draw_glyph_line_, DEPTH)(d, 
90 17b0018b bellard
                                          expand4to8[font_data >> 4], 
91 17b0018b bellard
                                          xorcol, bgcol);
92 17b0018b bellard
        glue(vga_draw_glyph_line_, DEPTH)(d + 8 * BPP, 
93 17b0018b bellard
                                          expand4to8[font_data & 0x0f], 
94 17b0018b bellard
                                          xorcol, bgcol);
95 e89f66ec bellard
        font_ptr += 4;
96 e89f66ec bellard
        d += linesize;
97 e89f66ec bellard
    } while (--h);
98 e89f66ec bellard
}
99 e89f66ec bellard
100 e89f66ec bellard
static void glue(vga_draw_glyph9_, DEPTH)(uint8_t *d, int linesize,
101 e89f66ec bellard
                                          const uint8_t *font_ptr, int h, 
102 e89f66ec bellard
                                          uint32_t fgcol, uint32_t bgcol, int dup9)
103 e89f66ec bellard
{
104 e89f66ec bellard
    uint32_t font_data, xorcol, v;
105 e89f66ec bellard
    
106 e89f66ec bellard
    xorcol = bgcol ^ fgcol;
107 e89f66ec bellard
    do {
108 e89f66ec bellard
        font_data = font_ptr[0];
109 e89f66ec bellard
#if BPP == 1
110 188d8579 bellard
        cpu_to_32wu((uint32_t *)d, (dmask16[(font_data >> 4)] & xorcol) ^ bgcol);
111 e89f66ec bellard
        v = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
112 188d8579 bellard
        cpu_to_32wu(((uint32_t *)d)+1, v);
113 e89f66ec bellard
        if (dup9)
114 39cf7803 bellard
            ((uint8_t *)d)[8] = v >> (24 * (1 - BIG));
115 e89f66ec bellard
        else
116 39cf7803 bellard
            ((uint8_t *)d)[8] = bgcol;
117 e89f66ec bellard
        
118 e89f66ec bellard
#elif BPP == 2
119 188d8579 bellard
        cpu_to_32wu(((uint32_t *)d)+0, (dmask4[(font_data >> 6)] & xorcol) ^ bgcol);
120 188d8579 bellard
        cpu_to_32wu(((uint32_t *)d)+1, (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol);
121 188d8579 bellard
        cpu_to_32wu(((uint32_t *)d)+2, (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol);
122 e89f66ec bellard
        v = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol;
123 188d8579 bellard
        cpu_to_32wu(((uint32_t *)d)+3, v);
124 e89f66ec bellard
        if (dup9)
125 39cf7803 bellard
            ((uint16_t *)d)[8] = v >> (16 * (1 - BIG));
126 e89f66ec bellard
        else
127 39cf7803 bellard
            ((uint16_t *)d)[8] = bgcol;
128 e89f66ec bellard
#else
129 eccabc6e bellard
        ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;
130 eccabc6e bellard
        ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;
131 eccabc6e bellard
        ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol;
132 eccabc6e bellard
        ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol;
133 eccabc6e bellard
        ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol;
134 eccabc6e bellard
        ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol;
135 eccabc6e bellard
        ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol;
136 eccabc6e bellard
        v = (-((font_data >> 0) & 1) & xorcol) ^ bgcol;
137 e89f66ec bellard
        ((uint32_t *)d)[7] = v;
138 e89f66ec bellard
        if (dup9)
139 39cf7803 bellard
            ((uint32_t *)d)[8] = v;
140 e89f66ec bellard
        else
141 39cf7803 bellard
            ((uint32_t *)d)[8] = bgcol;
142 e89f66ec bellard
#endif
143 e89f66ec bellard
        font_ptr += 4;
144 e89f66ec bellard
        d += linesize;
145 e89f66ec bellard
    } while (--h);
146 e89f66ec bellard
}
147 e89f66ec bellard
148 e89f66ec bellard
/* 
149 e89f66ec bellard
 * 4 color mode
150 e89f66ec bellard
 */
151 e89f66ec bellard
static void glue(vga_draw_line2_, DEPTH)(VGAState *s1, uint8_t *d, 
152 e89f66ec bellard
                                         const uint8_t *s, int width)
153 e89f66ec bellard
{
154 e89f66ec bellard
    uint32_t plane_mask, *palette, data, v;
155 e89f66ec bellard
    int x;
156 e89f66ec bellard
157 e89f66ec bellard
    palette = s1->last_palette;
158 e89f66ec bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
159 e89f66ec bellard
    width >>= 3;
160 e89f66ec bellard
    for(x = 0; x < width; x++) {
161 e89f66ec bellard
        data = ((uint32_t *)s)[0];
162 e89f66ec bellard
        data &= plane_mask;
163 e89f66ec bellard
        v = expand2[GET_PLANE(data, 0)];
164 e89f66ec bellard
        v |= expand2[GET_PLANE(data, 2)] << 2;
165 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[v >> 12];
166 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[(v >> 8) & 0xf];
167 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[(v >> 4) & 0xf];
168 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[(v >> 0) & 0xf];
169 e89f66ec bellard
170 e89f66ec bellard
        v = expand2[GET_PLANE(data, 1)];
171 e89f66ec bellard
        v |= expand2[GET_PLANE(data, 3)] << 2;
172 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[v >> 12];
173 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[(v >> 8) & 0xf];
174 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[(v >> 4) & 0xf];
175 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[(v >> 0) & 0xf];
176 e89f66ec bellard
        d += BPP * 8;
177 e89f66ec bellard
        s += 4;
178 e89f66ec bellard
    }
179 e89f66ec bellard
}
180 e89f66ec bellard
181 17b0018b bellard
#if BPP == 1
182 17b0018b bellard
#define PUT_PIXEL2(d, n, v) ((uint16_t *)d)[(n)] = (v)
183 17b0018b bellard
#elif BPP == 2
184 17b0018b bellard
#define PUT_PIXEL2(d, n, v) ((uint32_t *)d)[(n)] = (v)
185 17b0018b bellard
#else
186 17b0018b bellard
#define PUT_PIXEL2(d, n, v) \
187 17b0018b bellard
((uint32_t *)d)[2*(n)] = ((uint32_t *)d)[2*(n)+1] = (v)
188 17b0018b bellard
#endif
189 17b0018b bellard
190 17b0018b bellard
/* 
191 17b0018b bellard
 * 4 color mode, dup2 horizontal
192 17b0018b bellard
 */
193 17b0018b bellard
static void glue(vga_draw_line2d2_, DEPTH)(VGAState *s1, uint8_t *d, 
194 17b0018b bellard
                                           const uint8_t *s, int width)
195 17b0018b bellard
{
196 17b0018b bellard
    uint32_t plane_mask, *palette, data, v;
197 17b0018b bellard
    int x;
198 17b0018b bellard
199 17b0018b bellard
    palette = s1->last_palette;
200 17b0018b bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
201 17b0018b bellard
    width >>= 3;
202 17b0018b bellard
    for(x = 0; x < width; x++) {
203 17b0018b bellard
        data = ((uint32_t *)s)[0];
204 17b0018b bellard
        data &= plane_mask;
205 17b0018b bellard
        v = expand2[GET_PLANE(data, 0)];
206 17b0018b bellard
        v |= expand2[GET_PLANE(data, 2)] << 2;
207 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[v >> 12]);
208 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[(v >> 8) & 0xf]);
209 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[(v >> 4) & 0xf]);
210 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[(v >> 0) & 0xf]);
211 17b0018b bellard
212 17b0018b bellard
        v = expand2[GET_PLANE(data, 1)];
213 17b0018b bellard
        v |= expand2[GET_PLANE(data, 3)] << 2;
214 17b0018b bellard
        PUT_PIXEL2(d, 4, palette[v >> 12]);
215 17b0018b bellard
        PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]);
216 17b0018b bellard
        PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
217 17b0018b bellard
        PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
218 17b0018b bellard
        d += BPP * 16;
219 17b0018b bellard
        s += 4;
220 17b0018b bellard
    }
221 17b0018b bellard
}
222 17b0018b bellard
223 e89f66ec bellard
/* 
224 e89f66ec bellard
 * 16 color mode
225 e89f66ec bellard
 */
226 e89f66ec bellard
static void glue(vga_draw_line4_, DEPTH)(VGAState *s1, uint8_t *d, 
227 e89f66ec bellard
                                         const uint8_t *s, int width)
228 e89f66ec bellard
{
229 e89f66ec bellard
    uint32_t plane_mask, data, v, *palette;
230 e89f66ec bellard
    int x;
231 e89f66ec bellard
232 e89f66ec bellard
    palette = s1->last_palette;
233 e89f66ec bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
234 e89f66ec bellard
    width >>= 3;
235 e89f66ec bellard
    for(x = 0; x < width; x++) {
236 e89f66ec bellard
        data = ((uint32_t *)s)[0];
237 e89f66ec bellard
        data &= plane_mask;
238 e89f66ec bellard
        v = expand4[GET_PLANE(data, 0)];
239 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 1)] << 1;
240 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 2)] << 2;
241 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 3)] << 3;
242 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[v >> 28];
243 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[(v >> 24) & 0xf];
244 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[(v >> 20) & 0xf];
245 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[(v >> 16) & 0xf];
246 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[(v >> 12) & 0xf];
247 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[(v >> 8) & 0xf];
248 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[(v >> 4) & 0xf];
249 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[(v >> 0) & 0xf];
250 e89f66ec bellard
        d += BPP * 8;
251 e89f66ec bellard
        s += 4;
252 e89f66ec bellard
    }
253 e89f66ec bellard
}
254 e89f66ec bellard
255 e89f66ec bellard
/* 
256 17b0018b bellard
 * 16 color mode, dup2 horizontal
257 17b0018b bellard
 */
258 17b0018b bellard
static void glue(vga_draw_line4d2_, DEPTH)(VGAState *s1, uint8_t *d, 
259 17b0018b bellard
                                           const uint8_t *s, int width)
260 17b0018b bellard
{
261 17b0018b bellard
    uint32_t plane_mask, data, v, *palette;
262 17b0018b bellard
    int x;
263 17b0018b bellard
264 17b0018b bellard
    palette = s1->last_palette;
265 17b0018b bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
266 17b0018b bellard
    width >>= 3;
267 17b0018b bellard
    for(x = 0; x < width; x++) {
268 17b0018b bellard
        data = ((uint32_t *)s)[0];
269 17b0018b bellard
        data &= plane_mask;
270 17b0018b bellard
        v = expand4[GET_PLANE(data, 0)];
271 17b0018b bellard
        v |= expand4[GET_PLANE(data, 1)] << 1;
272 17b0018b bellard
        v |= expand4[GET_PLANE(data, 2)] << 2;
273 17b0018b bellard
        v |= expand4[GET_PLANE(data, 3)] << 3;
274 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[v >> 28]);
275 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[(v >> 24) & 0xf]);
276 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[(v >> 20) & 0xf]);
277 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[(v >> 16) & 0xf]);
278 17b0018b bellard
        PUT_PIXEL2(d, 4, palette[(v >> 12) & 0xf]);
279 17b0018b bellard
        PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]);
280 17b0018b bellard
        PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
281 17b0018b bellard
        PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
282 17b0018b bellard
        d += BPP * 16;
283 17b0018b bellard
        s += 4;
284 17b0018b bellard
    }
285 17b0018b bellard
}
286 17b0018b bellard
287 17b0018b bellard
/* 
288 17b0018b bellard
 * 256 color mode, double pixels
289 17b0018b bellard
 *
290 17b0018b bellard
 * XXX: add plane_mask support (never used in standard VGA modes)
291 17b0018b bellard
 */
292 17b0018b bellard
static void glue(vga_draw_line8d2_, DEPTH)(VGAState *s1, uint8_t *d, 
293 17b0018b bellard
                                           const uint8_t *s, int width)
294 17b0018b bellard
{
295 17b0018b bellard
    uint32_t *palette;
296 17b0018b bellard
    int x;
297 17b0018b bellard
298 17b0018b bellard
    palette = s1->last_palette;
299 17b0018b bellard
    width >>= 3;
300 17b0018b bellard
    for(x = 0; x < width; x++) {
301 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[s[0]]);
302 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[s[1]]);
303 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[s[2]]);
304 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[s[3]]);
305 17b0018b bellard
        d += BPP * 8;
306 17b0018b bellard
        s += 4;
307 17b0018b bellard
    }
308 17b0018b bellard
}
309 17b0018b bellard
310 17b0018b bellard
/* 
311 17b0018b bellard
 * standard 256 color mode
312 e89f66ec bellard
 *
313 e89f66ec bellard
 * XXX: add plane_mask support (never used in standard VGA modes)
314 e89f66ec bellard
 */
315 e89f66ec bellard
static void glue(vga_draw_line8_, DEPTH)(VGAState *s1, uint8_t *d, 
316 e89f66ec bellard
                                         const uint8_t *s, int width)
317 e89f66ec bellard
{
318 e89f66ec bellard
    uint32_t *palette;
319 e89f66ec bellard
    int x;
320 e89f66ec bellard
321 e89f66ec bellard
    palette = s1->last_palette;
322 e89f66ec bellard
    width >>= 3;
323 e89f66ec bellard
    for(x = 0; x < width; x++) {
324 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[s[0]];
325 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[s[1]];
326 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[s[2]];
327 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[s[3]];
328 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[s[4]];
329 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[s[5]];
330 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[s[6]];
331 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[s[7]];
332 e89f66ec bellard
        d += BPP * 8;
333 e89f66ec bellard
        s += 8;
334 e89f66ec bellard
    }
335 e89f66ec bellard
}
336 e89f66ec bellard
337 e89f66ec bellard
#endif /* DEPTH != 15 */
338 e89f66ec bellard
339 e89f66ec bellard
340 e89f66ec bellard
/* XXX: optimize */
341 e89f66ec bellard
342 e89f66ec bellard
/* 
343 e89f66ec bellard
 * 15 bit color
344 e89f66ec bellard
 */
345 e89f66ec bellard
static void glue(vga_draw_line15_, DEPTH)(VGAState *s1, uint8_t *d, 
346 e89f66ec bellard
                                          const uint8_t *s, int width)
347 e89f66ec bellard
{
348 53c862a8 bellard
#if DEPTH == 15 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
349 e89f66ec bellard
    memcpy(d, s, width * 2);
350 e89f66ec bellard
#else
351 e89f66ec bellard
    int w;
352 e89f66ec bellard
    uint32_t v, r, g, b;
353 e89f66ec bellard
354 e89f66ec bellard
    w = width;
355 e89f66ec bellard
    do {
356 61382a50 bellard
        v = lduw_raw((void *)s);
357 e89f66ec bellard
        r = (v >> 7) & 0xf8;
358 e89f66ec bellard
        g = (v >> 2) & 0xf8;
359 e89f66ec bellard
        b = (v << 3) & 0xf8;
360 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
361 e89f66ec bellard
        s += 2;
362 e89f66ec bellard
        d += BPP;
363 e89f66ec bellard
    } while (--w != 0);
364 e89f66ec bellard
#endif    
365 e89f66ec bellard
}
366 e89f66ec bellard
367 e89f66ec bellard
/* 
368 e89f66ec bellard
 * 16 bit color
369 e89f66ec bellard
 */
370 e89f66ec bellard
static void glue(vga_draw_line16_, DEPTH)(VGAState *s1, uint8_t *d, 
371 e89f66ec bellard
                                          const uint8_t *s, int width)
372 e89f66ec bellard
{
373 53c862a8 bellard
#if DEPTH == 16 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
374 e89f66ec bellard
    memcpy(d, s, width * 2);
375 e89f66ec bellard
#else
376 e89f66ec bellard
    int w;
377 e89f66ec bellard
    uint32_t v, r, g, b;
378 e89f66ec bellard
379 e89f66ec bellard
    w = width;
380 e89f66ec bellard
    do {
381 61382a50 bellard
        v = lduw_raw((void *)s);
382 e89f66ec bellard
        r = (v >> 8) & 0xf8;
383 e89f66ec bellard
        g = (v >> 3) & 0xfc;
384 e89f66ec bellard
        b = (v << 3) & 0xf8;
385 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
386 e89f66ec bellard
        s += 2;
387 e89f66ec bellard
        d += BPP;
388 e89f66ec bellard
    } while (--w != 0);
389 e89f66ec bellard
#endif    
390 e89f66ec bellard
}
391 e89f66ec bellard
392 e89f66ec bellard
/* 
393 4fa0f5d2 bellard
 * 24 bit color
394 4fa0f5d2 bellard
 */
395 4fa0f5d2 bellard
static void glue(vga_draw_line24_, DEPTH)(VGAState *s1, uint8_t *d, 
396 4fa0f5d2 bellard
                                          const uint8_t *s, int width)
397 4fa0f5d2 bellard
{
398 4fa0f5d2 bellard
    int w;
399 4fa0f5d2 bellard
    uint32_t r, g, b;
400 4fa0f5d2 bellard
401 4fa0f5d2 bellard
    w = width;
402 4fa0f5d2 bellard
    do {
403 53c862a8 bellard
#if defined(TARGET_WORDS_BIGENDIAN)
404 53c862a8 bellard
        r = s[0];
405 53c862a8 bellard
        g = s[1];
406 53c862a8 bellard
        b = s[2];
407 53c862a8 bellard
#else
408 4fa0f5d2 bellard
        b = s[0];
409 4fa0f5d2 bellard
        g = s[1];
410 4fa0f5d2 bellard
        r = s[2];
411 53c862a8 bellard
#endif
412 4fa0f5d2 bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
413 4fa0f5d2 bellard
        s += 3;
414 4fa0f5d2 bellard
        d += BPP;
415 4fa0f5d2 bellard
    } while (--w != 0);
416 4fa0f5d2 bellard
}
417 4fa0f5d2 bellard
418 4fa0f5d2 bellard
/* 
419 e89f66ec bellard
 * 32 bit color
420 e89f66ec bellard
 */
421 e89f66ec bellard
static void glue(vga_draw_line32_, DEPTH)(VGAState *s1, uint8_t *d, 
422 e89f66ec bellard
                                          const uint8_t *s, int width)
423 e89f66ec bellard
{
424 53c862a8 bellard
#if DEPTH == 32 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
425 e89f66ec bellard
    memcpy(d, s, width * 4);
426 e89f66ec bellard
#else
427 e89f66ec bellard
    int w;
428 e89f66ec bellard
    uint32_t r, g, b;
429 e89f66ec bellard
430 e89f66ec bellard
    w = width;
431 e89f66ec bellard
    do {
432 53c862a8 bellard
#if defined(TARGET_WORDS_BIGENDIAN)
433 53c862a8 bellard
        r = s[1];
434 53c862a8 bellard
        g = s[2];
435 53c862a8 bellard
        b = s[3];
436 53c862a8 bellard
#else
437 e89f66ec bellard
        b = s[0];
438 e89f66ec bellard
        g = s[1];
439 e89f66ec bellard
        r = s[2];
440 53c862a8 bellard
#endif
441 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
442 e89f66ec bellard
        s += 4;
443 e89f66ec bellard
        d += BPP;
444 e89f66ec bellard
    } while (--w != 0);
445 e89f66ec bellard
#endif
446 e89f66ec bellard
}
447 e89f66ec bellard
448 a8aa669b bellard
#if DEPTH != 15
449 a8aa669b bellard
void glue(vga_draw_cursor_line_, DEPTH)(uint8_t *d1, 
450 a8aa669b bellard
                                        const uint8_t *src1, 
451 a8aa669b bellard
                                        int poffset, int w,
452 a8aa669b bellard
                                        unsigned int color0, 
453 a8aa669b bellard
                                        unsigned int color1,
454 a8aa669b bellard
                                        unsigned int color_xor)
455 a8aa669b bellard
{
456 a8aa669b bellard
    const uint8_t *plane0, *plane1;
457 a8aa669b bellard
    int x, b0, b1;
458 a8aa669b bellard
    uint8_t *d;
459 a8aa669b bellard
460 a8aa669b bellard
    d = d1;
461 a8aa669b bellard
    plane0 = src1;
462 a8aa669b bellard
    plane1 = src1 + poffset;
463 a8aa669b bellard
    for(x = 0; x < w; x++) {
464 a8aa669b bellard
        b0 = (plane0[x >> 3] >> (7 - (x & 7))) & 1;
465 a8aa669b bellard
        b1 = (plane1[x >> 3] >> (7 - (x & 7))) & 1;
466 a8aa669b bellard
#if DEPTH == 8
467 a8aa669b bellard
        switch(b0 | (b1 << 1)) {
468 a8aa669b bellard
        case 0:
469 a8aa669b bellard
            break;
470 a8aa669b bellard
        case 1:
471 a8aa669b bellard
            d[0] ^= color_xor;
472 a8aa669b bellard
            break;
473 a8aa669b bellard
        case 2:
474 a8aa669b bellard
            d[0] = color0;
475 a8aa669b bellard
            break;
476 a8aa669b bellard
        case 3:
477 a8aa669b bellard
            d[0] = color1;
478 a8aa669b bellard
            break;
479 a8aa669b bellard
        }
480 a8aa669b bellard
#elif DEPTH == 16
481 a8aa669b bellard
        switch(b0 | (b1 << 1)) {
482 a8aa669b bellard
        case 0:
483 a8aa669b bellard
            break;
484 a8aa669b bellard
        case 1:
485 a8aa669b bellard
            ((uint16_t *)d)[0] ^= color_xor;
486 a8aa669b bellard
            break;
487 a8aa669b bellard
        case 2:
488 a8aa669b bellard
            ((uint16_t *)d)[0] = color0;
489 a8aa669b bellard
            break;
490 a8aa669b bellard
        case 3:
491 a8aa669b bellard
            ((uint16_t *)d)[0] = color1;
492 a8aa669b bellard
            break;
493 a8aa669b bellard
        }
494 a8aa669b bellard
#elif DEPTH == 32
495 a8aa669b bellard
        switch(b0 | (b1 << 1)) {
496 a8aa669b bellard
        case 0:
497 a8aa669b bellard
            break;
498 a8aa669b bellard
        case 1:
499 a8aa669b bellard
            ((uint32_t *)d)[0] ^= color_xor;
500 a8aa669b bellard
            break;
501 a8aa669b bellard
        case 2:
502 a8aa669b bellard
            ((uint32_t *)d)[0] = color0;
503 a8aa669b bellard
            break;
504 a8aa669b bellard
        case 3:
505 a8aa669b bellard
            ((uint32_t *)d)[0] = color1;
506 a8aa669b bellard
            break;
507 a8aa669b bellard
        }
508 a8aa669b bellard
#else
509 a8aa669b bellard
#error unsupported depth
510 a8aa669b bellard
#endif
511 1cc98a5f bellard
        d += BPP;
512 a8aa669b bellard
    }
513 a8aa669b bellard
}
514 a8aa669b bellard
#endif
515 a8aa669b bellard
516 17b0018b bellard
#undef PUT_PIXEL2
517 e89f66ec bellard
#undef DEPTH
518 e89f66ec bellard
#undef BPP
519 e89f66ec bellard
#undef PIXEL_TYPE