root / hw / milkymist-vgafb_template.h @ 7e0a9247
History | View | Annotate | Download (2.5 kB)
1 | d23948b1 | Michael Walle | /*
|
---|---|---|---|
2 | d23948b1 | Michael Walle | * QEMU model of the Milkymist VGA framebuffer.
|
3 | d23948b1 | Michael Walle | *
|
4 | d23948b1 | Michael Walle | * Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
5 | d23948b1 | Michael Walle | *
|
6 | d23948b1 | Michael Walle | * This library is free software; you can redistribute it and/or
|
7 | d23948b1 | Michael Walle | * modify it under the terms of the GNU Lesser General Public
|
8 | d23948b1 | Michael Walle | * License as published by the Free Software Foundation; either
|
9 | d23948b1 | Michael Walle | * version 2 of the License, or (at your option) any later version.
|
10 | d23948b1 | Michael Walle | *
|
11 | d23948b1 | Michael Walle | * This library is distributed in the hope that it will be useful,
|
12 | d23948b1 | Michael Walle | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | d23948b1 | Michael Walle | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | d23948b1 | Michael Walle | * Lesser General Public License for more details.
|
15 | d23948b1 | Michael Walle | *
|
16 | d23948b1 | Michael Walle | * You should have received a copy of the GNU Lesser General Public
|
17 | d23948b1 | Michael Walle | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | d23948b1 | Michael Walle | *
|
19 | d23948b1 | Michael Walle | */
|
20 | d23948b1 | Michael Walle | |
21 | d23948b1 | Michael Walle | #if BITS == 8 |
22 | d23948b1 | Michael Walle | #define COPY_PIXEL(to, r, g, b) \
|
23 | d23948b1 | Michael Walle | do { \
|
24 | d23948b1 | Michael Walle | *to = rgb_to_pixel8(r, g, b); \ |
25 | d23948b1 | Michael Walle | to += 1; \
|
26 | d23948b1 | Michael Walle | } while (0) |
27 | d23948b1 | Michael Walle | #elif BITS == 15 |
28 | d23948b1 | Michael Walle | #define COPY_PIXEL(to, r, g, b) \
|
29 | d23948b1 | Michael Walle | do { \
|
30 | d23948b1 | Michael Walle | *(uint16_t *)to = rgb_to_pixel15(r, g, b); \ |
31 | d23948b1 | Michael Walle | to += 2; \
|
32 | d23948b1 | Michael Walle | } while (0) |
33 | d23948b1 | Michael Walle | #elif BITS == 16 |
34 | d23948b1 | Michael Walle | #define COPY_PIXEL(to, r, g, b) \
|
35 | d23948b1 | Michael Walle | do { \
|
36 | d23948b1 | Michael Walle | *(uint16_t *)to = rgb_to_pixel16(r, g, b); \ |
37 | d23948b1 | Michael Walle | to += 2; \
|
38 | d23948b1 | Michael Walle | } while (0) |
39 | d23948b1 | Michael Walle | #elif BITS == 24 |
40 | d23948b1 | Michael Walle | #define COPY_PIXEL(to, r, g, b) \
|
41 | d23948b1 | Michael Walle | do { \
|
42 | 0f3c3cc9 | Andreas Färber | uint32_t tmp = rgb_to_pixel24(r, g, b); \ |
43 | d23948b1 | Michael Walle | *(to++) = tmp & 0xff; \
|
44 | d23948b1 | Michael Walle | *(to++) = (tmp >> 8) & 0xff; \ |
45 | d23948b1 | Michael Walle | *(to++) = (tmp >> 16) & 0xff; \ |
46 | d23948b1 | Michael Walle | } while (0) |
47 | d23948b1 | Michael Walle | #elif BITS == 32 |
48 | d23948b1 | Michael Walle | #define COPY_PIXEL(to, r, g, b) \
|
49 | d23948b1 | Michael Walle | do { \
|
50 | d23948b1 | Michael Walle | *(uint32_t *)to = rgb_to_pixel32(r, g, b); \ |
51 | d23948b1 | Michael Walle | to += 4; \
|
52 | d23948b1 | Michael Walle | } while (0) |
53 | d23948b1 | Michael Walle | #else
|
54 | d23948b1 | Michael Walle | #error unknown bit depth
|
55 | d23948b1 | Michael Walle | #endif
|
56 | d23948b1 | Michael Walle | |
57 | d23948b1 | Michael Walle | static void glue(draw_line_, BITS)(void *opaque, uint8_t *d, const uint8_t *s, |
58 | d23948b1 | Michael Walle | int width, int deststep) |
59 | d23948b1 | Michael Walle | { |
60 | d23948b1 | Michael Walle | uint16_t rgb565; |
61 | d23948b1 | Michael Walle | uint8_t r, g, b; |
62 | d23948b1 | Michael Walle | |
63 | d23948b1 | Michael Walle | while (width--) {
|
64 | d23948b1 | Michael Walle | rgb565 = lduw_raw(s); |
65 | d23948b1 | Michael Walle | r = ((rgb565 >> 11) & 0x1f) << 3; |
66 | d23948b1 | Michael Walle | g = ((rgb565 >> 5) & 0x3f) << 2; |
67 | d23948b1 | Michael Walle | b = ((rgb565 >> 0) & 0x1f) << 3; |
68 | d23948b1 | Michael Walle | COPY_PIXEL(d, r, g, b); |
69 | d23948b1 | Michael Walle | s += 2;
|
70 | d23948b1 | Michael Walle | } |
71 | d23948b1 | Michael Walle | } |
72 | d23948b1 | Michael Walle | |
73 | d23948b1 | Michael Walle | #undef BITS
|
74 | d23948b1 | Michael Walle | #undef COPY_PIXEL |