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