Basic OMAP310 support. Basic Palm Tungsten|E machine emulation.
[qemu] / hw / omap_lcd_template.h
1 /*
2  * QEMU OMAP LCD Emulator templates
3  *
4  * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #if DEPTH == 8
31 # define BPP 1
32 # define PIXEL_TYPE uint8_t 
33 #elif DEPTH == 15 || DEPTH == 16
34 # define BPP 2
35 # define PIXEL_TYPE uint16_t 
36 #elif DEPTH == 32
37 # define BPP 4
38 # define PIXEL_TYPE uint32_t 
39 #else
40 # error unsupport depth
41 #endif
42
43 /* 
44  * 2-bit colour
45  */
46 static void glue(draw_line2_, DEPTH)(
47                 uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
48 {
49     uint8_t v, r, g, b;
50
51     do {
52         v = ldub_raw((void *) s);
53         r = (pal[v & 3] >> 4) & 0xf0;
54         g = pal[v & 3] & 0xf0;
55         b = (pal[v & 3] << 4) & 0xf0;
56         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
57         d += BPP;
58         v >>= 2;
59         r = (pal[v & 3] >> 4) & 0xf0;
60         g = pal[v & 3] & 0xf0;
61         b = (pal[v & 3] << 4) & 0xf0;
62         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
63         d += BPP;
64         v >>= 2;
65         r = (pal[v & 3] >> 4) & 0xf0;
66         g = pal[v & 3] & 0xf0;
67         b = (pal[v & 3] << 4) & 0xf0;
68         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
69         d += BPP;
70         v >>= 2;
71         r = (pal[v & 3] >> 4) & 0xf0;
72         g = pal[v & 3] & 0xf0;
73         b = (pal[v & 3] << 4) & 0xf0;
74         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
75         d += BPP;
76         s ++;
77         width -= 4;
78     } while (width > 0);
79 }
80
81 /* 
82  * 4-bit colour
83  */
84 static void glue(draw_line4_, DEPTH)(
85                 uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
86 {
87     uint8_t v, r, g, b;
88
89     do {
90         v = ldub_raw((void *) s);
91         r = (pal[v & 0xf] >> 4) & 0xf0;
92         g = pal[v & 0xf] & 0xf0;
93         b = (pal[v & 0xf] << 4) & 0xf0;
94         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
95         d += BPP;
96         v >>= 4;
97         r = (pal[v & 0xf] >> 4) & 0xf0;
98         g = pal[v & 0xf] & 0xf0;
99         b = (pal[v & 0xf] << 4) & 0xf0;
100         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
101         d += BPP;
102         s ++;
103         width -= 2;
104     } while (width > 0);
105 }
106
107 /* 
108  * 8-bit colour
109  */
110 static void glue(draw_line8_, DEPTH)(
111                 uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
112 {
113     uint8_t v, r, g, b;
114
115     do {
116         v = ldub_raw((void *) s);
117         r = (pal[v] >> 4) & 0xf0;
118         g = pal[v] & 0xf0;
119         b = (pal[v] << 4) & 0xf0;
120         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
121         s ++;
122         d += BPP;
123     } while (-- width != 0);
124 }
125
126 /* 
127  * 12-bit colour
128  */
129 static void glue(draw_line12_, DEPTH)(
130                 uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
131 {
132     uint16_t v;
133     uint8_t r, g, b;
134
135     do {
136         v = lduw_raw((void *) s);
137         r = (v >> 4) & 0xf0;
138         g = v & 0xf0;
139         b = (v << 4) & 0xf0;
140         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
141         s += 2;
142         d += BPP;
143     } while (-- width != 0);
144 }
145
146 /* 
147  * 16-bit colour
148  */
149 static void glue(draw_line16_, DEPTH)(
150                 uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
151 {
152 #if DEPTH == 16 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
153     memcpy(d, s, width * 2);
154 #else
155     uint16_t v;
156     uint8_t r, g, b;
157
158     do {
159         v = lduw_raw((void *) s);
160         r = (v >> 8) & 0xf8;
161         g = (v >> 3) & 0xfc;
162         b = (v << 3) & 0xf8;
163         ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
164         s += 2;
165         d += BPP;
166     } while (-- width != 0);
167 #endif
168 }
169
170 #undef DEPTH
171 #undef BPP
172 #undef PIXEL_TYPE