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