Statistics
| Branch: | Revision:

root / hw / vga_template.h @ 16f62432

History | View | Annotate | Download (13.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 e89f66ec bellard
        ((uint32_t *)d)[3] = (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
        /* XXX: unaligned accesses are done */
110 e89f66ec bellard
#if BPP == 1
111 e89f66ec bellard
        ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;
112 e89f66ec bellard
        v = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
113 e89f66ec bellard
        ((uint32_t *)d)[3] = v;
114 e89f66ec bellard
        if (dup9)
115 39cf7803 bellard
            ((uint8_t *)d)[8] = v >> (24 * (1 - BIG));
116 e89f66ec bellard
        else
117 39cf7803 bellard
            ((uint8_t *)d)[8] = bgcol;
118 e89f66ec bellard
        
119 e89f66ec bellard
#elif BPP == 2
120 e89f66ec bellard
        ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;
121 e89f66ec bellard
        ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;
122 e89f66ec bellard
        ((uint32_t *)d)[2] = (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol;
123 e89f66ec bellard
        v = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol;
124 e89f66ec bellard
        ((uint32_t *)d)[3] = v;
125 e89f66ec bellard
        if (dup9)
126 39cf7803 bellard
            ((uint16_t *)d)[8] = v >> (16 * (1 - BIG));
127 e89f66ec bellard
        else
128 39cf7803 bellard
            ((uint16_t *)d)[8] = bgcol;
129 e89f66ec bellard
#else
130 e89f66ec bellard
        ((uint32_t *)d)[0] = ((-(font_data >> 7)) & xorcol) ^ bgcol;
131 e89f66ec bellard
        ((uint32_t *)d)[1] = ((-(font_data >> 6) & 1) & xorcol) ^ bgcol;
132 e89f66ec bellard
        ((uint32_t *)d)[2] = ((-(font_data >> 5) & 1) & xorcol) ^ bgcol;
133 e89f66ec bellard
        ((uint32_t *)d)[3] = ((-(font_data >> 4) & 1) & xorcol) ^ bgcol;
134 e89f66ec bellard
        ((uint32_t *)d)[4] = ((-(font_data >> 3) & 1) & xorcol) ^ bgcol;
135 e89f66ec bellard
        ((uint32_t *)d)[5] = ((-(font_data >> 2) & 1) & xorcol) ^ bgcol;
136 e89f66ec bellard
        ((uint32_t *)d)[6] = ((-(font_data >> 1) & 1) & xorcol) ^ bgcol;
137 e89f66ec bellard
        v = ((-(font_data >> 0) & 1) & xorcol) ^ bgcol;
138 e89f66ec bellard
        ((uint32_t *)d)[7] = v;
139 e89f66ec bellard
        if (dup9)
140 39cf7803 bellard
            ((uint32_t *)d)[8] = v;
141 e89f66ec bellard
        else
142 39cf7803 bellard
            ((uint32_t *)d)[8] = bgcol;
143 e89f66ec bellard
#endif
144 e89f66ec bellard
        font_ptr += 4;
145 e89f66ec bellard
        d += linesize;
146 e89f66ec bellard
    } while (--h);
147 e89f66ec bellard
}
148 e89f66ec bellard
149 e89f66ec bellard
/* 
150 e89f66ec bellard
 * 4 color mode
151 e89f66ec bellard
 */
152 e89f66ec bellard
static void glue(vga_draw_line2_, DEPTH)(VGAState *s1, uint8_t *d, 
153 e89f66ec bellard
                                         const uint8_t *s, int width)
154 e89f66ec bellard
{
155 e89f66ec bellard
    uint32_t plane_mask, *palette, data, v;
156 e89f66ec bellard
    int x;
157 e89f66ec bellard
158 e89f66ec bellard
    palette = s1->last_palette;
159 e89f66ec bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
160 e89f66ec bellard
    width >>= 3;
161 e89f66ec bellard
    for(x = 0; x < width; x++) {
162 e89f66ec bellard
        data = ((uint32_t *)s)[0];
163 e89f66ec bellard
        data &= plane_mask;
164 e89f66ec bellard
        v = expand2[GET_PLANE(data, 0)];
165 e89f66ec bellard
        v |= expand2[GET_PLANE(data, 2)] << 2;
166 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[v >> 12];
167 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[(v >> 8) & 0xf];
168 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[(v >> 4) & 0xf];
169 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[(v >> 0) & 0xf];
170 e89f66ec bellard
171 e89f66ec bellard
        v = expand2[GET_PLANE(data, 1)];
172 e89f66ec bellard
        v |= expand2[GET_PLANE(data, 3)] << 2;
173 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[v >> 12];
174 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[(v >> 8) & 0xf];
175 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[(v >> 4) & 0xf];
176 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[(v >> 0) & 0xf];
177 e89f66ec bellard
        d += BPP * 8;
178 e89f66ec bellard
        s += 4;
179 e89f66ec bellard
    }
180 e89f66ec bellard
}
181 e89f66ec bellard
182 17b0018b bellard
#if BPP == 1
183 17b0018b bellard
#define PUT_PIXEL2(d, n, v) ((uint16_t *)d)[(n)] = (v)
184 17b0018b bellard
#elif BPP == 2
185 17b0018b bellard
#define PUT_PIXEL2(d, n, v) ((uint32_t *)d)[(n)] = (v)
186 17b0018b bellard
#else
187 17b0018b bellard
#define PUT_PIXEL2(d, n, v) \
188 17b0018b bellard
((uint32_t *)d)[2*(n)] = ((uint32_t *)d)[2*(n)+1] = (v)
189 17b0018b bellard
#endif
190 17b0018b bellard
191 17b0018b bellard
/* 
192 17b0018b bellard
 * 4 color mode, dup2 horizontal
193 17b0018b bellard
 */
194 17b0018b bellard
static void glue(vga_draw_line2d2_, DEPTH)(VGAState *s1, uint8_t *d, 
195 17b0018b bellard
                                           const uint8_t *s, int width)
196 17b0018b bellard
{
197 17b0018b bellard
    uint32_t plane_mask, *palette, data, v;
198 17b0018b bellard
    int x;
199 17b0018b bellard
200 17b0018b bellard
    palette = s1->last_palette;
201 17b0018b bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
202 17b0018b bellard
    width >>= 3;
203 17b0018b bellard
    for(x = 0; x < width; x++) {
204 17b0018b bellard
        data = ((uint32_t *)s)[0];
205 17b0018b bellard
        data &= plane_mask;
206 17b0018b bellard
        v = expand2[GET_PLANE(data, 0)];
207 17b0018b bellard
        v |= expand2[GET_PLANE(data, 2)] << 2;
208 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[v >> 12]);
209 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[(v >> 8) & 0xf]);
210 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[(v >> 4) & 0xf]);
211 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[(v >> 0) & 0xf]);
212 17b0018b bellard
213 17b0018b bellard
        v = expand2[GET_PLANE(data, 1)];
214 17b0018b bellard
        v |= expand2[GET_PLANE(data, 3)] << 2;
215 17b0018b bellard
        PUT_PIXEL2(d, 4, palette[v >> 12]);
216 17b0018b bellard
        PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]);
217 17b0018b bellard
        PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
218 17b0018b bellard
        PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
219 17b0018b bellard
        d += BPP * 16;
220 17b0018b bellard
        s += 4;
221 17b0018b bellard
    }
222 17b0018b bellard
}
223 17b0018b bellard
224 e89f66ec bellard
/* 
225 e89f66ec bellard
 * 16 color mode
226 e89f66ec bellard
 */
227 e89f66ec bellard
static void glue(vga_draw_line4_, DEPTH)(VGAState *s1, uint8_t *d, 
228 e89f66ec bellard
                                         const uint8_t *s, int width)
229 e89f66ec bellard
{
230 e89f66ec bellard
    uint32_t plane_mask, data, v, *palette;
231 e89f66ec bellard
    int x;
232 e89f66ec bellard
233 e89f66ec bellard
    palette = s1->last_palette;
234 e89f66ec bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
235 e89f66ec bellard
    width >>= 3;
236 e89f66ec bellard
    for(x = 0; x < width; x++) {
237 e89f66ec bellard
        data = ((uint32_t *)s)[0];
238 e89f66ec bellard
        data &= plane_mask;
239 e89f66ec bellard
        v = expand4[GET_PLANE(data, 0)];
240 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 1)] << 1;
241 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 2)] << 2;
242 e89f66ec bellard
        v |= expand4[GET_PLANE(data, 3)] << 3;
243 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[v >> 28];
244 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[(v >> 24) & 0xf];
245 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[(v >> 20) & 0xf];
246 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[(v >> 16) & 0xf];
247 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[(v >> 12) & 0xf];
248 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[(v >> 8) & 0xf];
249 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[(v >> 4) & 0xf];
250 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[(v >> 0) & 0xf];
251 e89f66ec bellard
        d += BPP * 8;
252 e89f66ec bellard
        s += 4;
253 e89f66ec bellard
    }
254 e89f66ec bellard
}
255 e89f66ec bellard
256 e89f66ec bellard
/* 
257 17b0018b bellard
 * 16 color mode, dup2 horizontal
258 17b0018b bellard
 */
259 17b0018b bellard
static void glue(vga_draw_line4d2_, DEPTH)(VGAState *s1, uint8_t *d, 
260 17b0018b bellard
                                           const uint8_t *s, int width)
261 17b0018b bellard
{
262 17b0018b bellard
    uint32_t plane_mask, data, v, *palette;
263 17b0018b bellard
    int x;
264 17b0018b bellard
265 17b0018b bellard
    palette = s1->last_palette;
266 17b0018b bellard
    plane_mask = mask16[s1->ar[0x12] & 0xf];
267 17b0018b bellard
    width >>= 3;
268 17b0018b bellard
    for(x = 0; x < width; x++) {
269 17b0018b bellard
        data = ((uint32_t *)s)[0];
270 17b0018b bellard
        data &= plane_mask;
271 17b0018b bellard
        v = expand4[GET_PLANE(data, 0)];
272 17b0018b bellard
        v |= expand4[GET_PLANE(data, 1)] << 1;
273 17b0018b bellard
        v |= expand4[GET_PLANE(data, 2)] << 2;
274 17b0018b bellard
        v |= expand4[GET_PLANE(data, 3)] << 3;
275 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[v >> 28]);
276 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[(v >> 24) & 0xf]);
277 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[(v >> 20) & 0xf]);
278 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[(v >> 16) & 0xf]);
279 17b0018b bellard
        PUT_PIXEL2(d, 4, palette[(v >> 12) & 0xf]);
280 17b0018b bellard
        PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]);
281 17b0018b bellard
        PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
282 17b0018b bellard
        PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
283 17b0018b bellard
        d += BPP * 16;
284 17b0018b bellard
        s += 4;
285 17b0018b bellard
    }
286 17b0018b bellard
}
287 17b0018b bellard
288 17b0018b bellard
/* 
289 17b0018b bellard
 * 256 color mode, double pixels
290 17b0018b bellard
 *
291 17b0018b bellard
 * XXX: add plane_mask support (never used in standard VGA modes)
292 17b0018b bellard
 */
293 17b0018b bellard
static void glue(vga_draw_line8d2_, DEPTH)(VGAState *s1, uint8_t *d, 
294 17b0018b bellard
                                           const uint8_t *s, int width)
295 17b0018b bellard
{
296 17b0018b bellard
    uint32_t *palette;
297 17b0018b bellard
    int x;
298 17b0018b bellard
299 17b0018b bellard
    palette = s1->last_palette;
300 17b0018b bellard
    width >>= 3;
301 17b0018b bellard
    for(x = 0; x < width; x++) {
302 17b0018b bellard
        PUT_PIXEL2(d, 0, palette[s[0]]);
303 17b0018b bellard
        PUT_PIXEL2(d, 1, palette[s[1]]);
304 17b0018b bellard
        PUT_PIXEL2(d, 2, palette[s[2]]);
305 17b0018b bellard
        PUT_PIXEL2(d, 3, palette[s[3]]);
306 17b0018b bellard
        d += BPP * 8;
307 17b0018b bellard
        s += 4;
308 17b0018b bellard
    }
309 17b0018b bellard
}
310 17b0018b bellard
311 17b0018b bellard
/* 
312 17b0018b bellard
 * standard 256 color mode
313 e89f66ec bellard
 *
314 e89f66ec bellard
 * XXX: add plane_mask support (never used in standard VGA modes)
315 e89f66ec bellard
 */
316 e89f66ec bellard
static void glue(vga_draw_line8_, DEPTH)(VGAState *s1, uint8_t *d, 
317 e89f66ec bellard
                                         const uint8_t *s, int width)
318 e89f66ec bellard
{
319 e89f66ec bellard
    uint32_t *palette;
320 e89f66ec bellard
    int x;
321 e89f66ec bellard
322 e89f66ec bellard
    palette = s1->last_palette;
323 e89f66ec bellard
    width >>= 3;
324 e89f66ec bellard
    for(x = 0; x < width; x++) {
325 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = palette[s[0]];
326 e89f66ec bellard
        ((PIXEL_TYPE *)d)[1] = palette[s[1]];
327 e89f66ec bellard
        ((PIXEL_TYPE *)d)[2] = palette[s[2]];
328 e89f66ec bellard
        ((PIXEL_TYPE *)d)[3] = palette[s[3]];
329 e89f66ec bellard
        ((PIXEL_TYPE *)d)[4] = palette[s[4]];
330 e89f66ec bellard
        ((PIXEL_TYPE *)d)[5] = palette[s[5]];
331 e89f66ec bellard
        ((PIXEL_TYPE *)d)[6] = palette[s[6]];
332 e89f66ec bellard
        ((PIXEL_TYPE *)d)[7] = palette[s[7]];
333 e89f66ec bellard
        d += BPP * 8;
334 e89f66ec bellard
        s += 8;
335 e89f66ec bellard
    }
336 e89f66ec bellard
}
337 e89f66ec bellard
338 e89f66ec bellard
#endif /* DEPTH != 15 */
339 e89f66ec bellard
340 e89f66ec bellard
341 e89f66ec bellard
/* XXX: optimize */
342 e89f66ec bellard
343 e89f66ec bellard
/* 
344 e89f66ec bellard
 * 15 bit color
345 e89f66ec bellard
 */
346 e89f66ec bellard
static void glue(vga_draw_line15_, DEPTH)(VGAState *s1, uint8_t *d, 
347 e89f66ec bellard
                                          const uint8_t *s, int width)
348 e89f66ec bellard
{
349 e89f66ec bellard
#if DEPTH == 15 && !defined(WORDS_BIGENDIAN)
350 e89f66ec bellard
    memcpy(d, s, width * 2);
351 e89f66ec bellard
#else
352 e89f66ec bellard
    int w;
353 e89f66ec bellard
    uint32_t v, r, g, b;
354 e89f66ec bellard
355 e89f66ec bellard
    w = width;
356 e89f66ec bellard
    do {
357 61382a50 bellard
        v = lduw_raw((void *)s);
358 e89f66ec bellard
        r = (v >> 7) & 0xf8;
359 e89f66ec bellard
        g = (v >> 2) & 0xf8;
360 e89f66ec bellard
        b = (v << 3) & 0xf8;
361 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
362 e89f66ec bellard
        s += 2;
363 e89f66ec bellard
        d += BPP;
364 e89f66ec bellard
    } while (--w != 0);
365 e89f66ec bellard
#endif    
366 e89f66ec bellard
}
367 e89f66ec bellard
368 e89f66ec bellard
/* 
369 e89f66ec bellard
 * 16 bit color
370 e89f66ec bellard
 */
371 e89f66ec bellard
static void glue(vga_draw_line16_, DEPTH)(VGAState *s1, uint8_t *d, 
372 e89f66ec bellard
                                          const uint8_t *s, int width)
373 e89f66ec bellard
{
374 e89f66ec bellard
#if DEPTH == 16 && !defined(WORDS_BIGENDIAN)
375 e89f66ec bellard
    memcpy(d, s, width * 2);
376 e89f66ec bellard
#else
377 e89f66ec bellard
    int w;
378 e89f66ec bellard
    uint32_t v, r, g, b;
379 e89f66ec bellard
380 e89f66ec bellard
    w = width;
381 e89f66ec bellard
    do {
382 61382a50 bellard
        v = lduw_raw((void *)s);
383 e89f66ec bellard
        r = (v >> 8) & 0xf8;
384 e89f66ec bellard
        g = (v >> 3) & 0xfc;
385 e89f66ec bellard
        b = (v << 3) & 0xf8;
386 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
387 e89f66ec bellard
        s += 2;
388 e89f66ec bellard
        d += BPP;
389 e89f66ec bellard
    } while (--w != 0);
390 e89f66ec bellard
#endif    
391 e89f66ec bellard
}
392 e89f66ec bellard
393 e89f66ec bellard
/* 
394 4fa0f5d2 bellard
 * 24 bit color
395 4fa0f5d2 bellard
 */
396 4fa0f5d2 bellard
static void glue(vga_draw_line24_, DEPTH)(VGAState *s1, uint8_t *d, 
397 4fa0f5d2 bellard
                                          const uint8_t *s, int width)
398 4fa0f5d2 bellard
{
399 4fa0f5d2 bellard
    int w;
400 4fa0f5d2 bellard
    uint32_t r, g, b;
401 4fa0f5d2 bellard
402 4fa0f5d2 bellard
    w = width;
403 4fa0f5d2 bellard
    do {
404 4fa0f5d2 bellard
        b = s[0];
405 4fa0f5d2 bellard
        g = s[1];
406 4fa0f5d2 bellard
        r = s[2];
407 4fa0f5d2 bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
408 4fa0f5d2 bellard
        s += 3;
409 4fa0f5d2 bellard
        d += BPP;
410 4fa0f5d2 bellard
    } while (--w != 0);
411 4fa0f5d2 bellard
}
412 4fa0f5d2 bellard
413 4fa0f5d2 bellard
/* 
414 e89f66ec bellard
 * 32 bit color
415 e89f66ec bellard
 */
416 e89f66ec bellard
static void glue(vga_draw_line32_, DEPTH)(VGAState *s1, uint8_t *d, 
417 e89f66ec bellard
                                          const uint8_t *s, int width)
418 e89f66ec bellard
{
419 e89f66ec bellard
#if DEPTH == 32 && !defined(WORDS_BIGENDIAN)
420 e89f66ec bellard
    memcpy(d, s, width * 4);
421 e89f66ec bellard
#else
422 e89f66ec bellard
    int w;
423 e89f66ec bellard
    uint32_t r, g, b;
424 e89f66ec bellard
425 e89f66ec bellard
    w = width;
426 e89f66ec bellard
    do {
427 e89f66ec bellard
        b = s[0];
428 e89f66ec bellard
        g = s[1];
429 e89f66ec bellard
        r = s[2];
430 e89f66ec bellard
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
431 e89f66ec bellard
        s += 4;
432 e89f66ec bellard
        d += BPP;
433 e89f66ec bellard
    } while (--w != 0);
434 e89f66ec bellard
#endif
435 e89f66ec bellard
}
436 e89f66ec bellard
437 17b0018b bellard
#undef PUT_PIXEL2
438 e89f66ec bellard
#undef DEPTH
439 e89f66ec bellard
#undef BPP
440 e89f66ec bellard
#undef PIXEL_TYPE