Eliminate some uses of T2
[qemu/malc.git] / hw / pl110_template.h
blob33483c0278a4b475a8c13b087c889e06b0af9269
1 /*
2 * Arm PrimeCell PL110 Color LCD Controller
4 * Copyright (c) 2005 CodeSourcery, LLC.
5 * Written by Paul Brook
7 * This code is licenced under the GNU LGPL
9 * Framebuffer format conversion routines.
12 #ifndef ORDER
14 #if BITS == 8
15 #define COPY_PIXEL(to, from) *(to++) = from
16 #elif BITS == 15 || BITS == 16
17 #define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2;
18 #elif BITS == 24
19 #define COPY_PIXEL(to, from) \
20 *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16
21 #elif BITS == 32
22 #define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4;
23 #else
24 #error unknown bit depth
25 #endif
27 #undef RGB
28 #define BORDER bgr
29 #define ORDER 0
30 #include "pl110_template.h"
31 #define ORDER 1
32 #include "pl110_template.h"
33 #define ORDER 2
34 #include "pl110_template.h"
35 #undef BORDER
36 #define RGB
37 #define BORDER rgb
38 #define ORDER 0
39 #include "pl110_template.h"
40 #define ORDER 1
41 #include "pl110_template.h"
42 #define ORDER 2
43 #include "pl110_template.h"
44 #undef BORDER
46 static drawfn glue(pl110_draw_fn_,BITS)[36] =
48 glue(pl110_draw_line1_lblp_bgr,BITS),
49 glue(pl110_draw_line2_lblp_bgr,BITS),
50 glue(pl110_draw_line4_lblp_bgr,BITS),
51 glue(pl110_draw_line8_lblp_bgr,BITS),
52 glue(pl110_draw_line16_lblp_bgr,BITS),
53 glue(pl110_draw_line32_lblp_bgr,BITS),
55 glue(pl110_draw_line1_bbbp_bgr,BITS),
56 glue(pl110_draw_line2_bbbp_bgr,BITS),
57 glue(pl110_draw_line4_bbbp_bgr,BITS),
58 glue(pl110_draw_line8_bbbp_bgr,BITS),
59 glue(pl110_draw_line16_bbbp_bgr,BITS),
60 glue(pl110_draw_line32_bbbp_bgr,BITS),
62 glue(pl110_draw_line1_lbbp_bgr,BITS),
63 glue(pl110_draw_line2_lbbp_bgr,BITS),
64 glue(pl110_draw_line4_lbbp_bgr,BITS),
65 glue(pl110_draw_line8_lbbp_bgr,BITS),
66 glue(pl110_draw_line16_lbbp_bgr,BITS),
67 glue(pl110_draw_line32_lbbp_bgr,BITS),
69 glue(pl110_draw_line1_lblp_rgb,BITS),
70 glue(pl110_draw_line2_lblp_rgb,BITS),
71 glue(pl110_draw_line4_lblp_rgb,BITS),
72 glue(pl110_draw_line8_lblp_rgb,BITS),
73 glue(pl110_draw_line16_lblp_rgb,BITS),
74 glue(pl110_draw_line32_lblp_rgb,BITS),
76 glue(pl110_draw_line1_bbbp_rgb,BITS),
77 glue(pl110_draw_line2_bbbp_rgb,BITS),
78 glue(pl110_draw_line4_bbbp_rgb,BITS),
79 glue(pl110_draw_line8_bbbp_rgb,BITS),
80 glue(pl110_draw_line16_bbbp_rgb,BITS),
81 glue(pl110_draw_line32_bbbp_rgb,BITS),
83 glue(pl110_draw_line1_lbbp_rgb,BITS),
84 glue(pl110_draw_line2_lbbp_rgb,BITS),
85 glue(pl110_draw_line4_lbbp_rgb,BITS),
86 glue(pl110_draw_line8_lbbp_rgb,BITS),
87 glue(pl110_draw_line16_lbbp_rgb,BITS),
88 glue(pl110_draw_line32_lbbp_rgb,BITS),
91 #undef BITS
92 #undef COPY_PIXEL
94 #else
96 #if ORDER == 0
97 #define NAME glue(glue(lblp_, BORDER), BITS)
98 #ifdef WORDS_BIGENDIAN
99 #define SWAP_WORDS 1
100 #endif
101 #elif ORDER == 1
102 #define NAME glue(glue(bbbp_, BORDER), BITS)
103 #ifndef WORDS_BIGENDIAN
104 #define SWAP_WORDS 1
105 #endif
106 #else
107 #define SWAP_PIXELS 1
108 #define NAME glue(glue(lbbp_, BORDER), BITS)
109 #ifdef WORDS_BIGENDIAN
110 #define SWAP_WORDS 1
111 #endif
112 #endif
114 #define FN_2(x, y) FN(x, y) FN(x+1, y)
115 #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
116 #define FN_8(y) FN_4(0, y) FN_4(4, y)
118 static void glue(pl110_draw_line1_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
120 uint32_t data;
121 while (width > 0) {
122 data = *(uint32_t *)src;
123 #ifdef SWAP_PIXELS
124 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]);
125 #else
126 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]);
127 #endif
128 #ifdef SWAP_WORDS
129 FN_8(24)
130 FN_8(16)
131 FN_8(8)
132 FN_8(0)
133 #else
134 FN_8(0)
135 FN_8(8)
136 FN_8(16)
137 FN_8(24)
138 #endif
139 #undef FN
140 width -= 32;
141 src += 4;
145 static void glue(pl110_draw_line2_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
147 uint32_t data;
148 while (width > 0) {
149 data = *(uint32_t *)src;
150 #ifdef SWAP_PIXELS
151 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]);
152 #else
153 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]);
154 #endif
155 #ifdef SWAP_WORDS
156 FN_4(0, 24)
157 FN_4(0, 16)
158 FN_4(0, 8)
159 FN_4(0, 0)
160 #else
161 FN_4(0, 0)
162 FN_4(0, 8)
163 FN_4(0, 16)
164 FN_4(0, 24)
165 #endif
166 #undef FN
167 width -= 16;
168 src += 4;
172 static void glue(pl110_draw_line4_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
174 uint32_t data;
175 while (width > 0) {
176 data = *(uint32_t *)src;
177 #ifdef SWAP_PIXELS
178 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]);
179 #else
180 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]);
181 #endif
182 #ifdef SWAP_WORDS
183 FN_2(0, 24)
184 FN_2(0, 16)
185 FN_2(0, 8)
186 FN_2(0, 0)
187 #else
188 FN_2(0, 0)
189 FN_2(0, 8)
190 FN_2(0, 16)
191 FN_2(0, 24)
192 #endif
193 #undef FN
194 width -= 8;
195 src += 4;
199 static void glue(pl110_draw_line8_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
201 uint32_t data;
202 while (width > 0) {
203 data = *(uint32_t *)src;
204 #define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]);
205 #ifdef SWAP_WORDS
206 FN(24)
207 FN(16)
208 FN(8)
209 FN(0)
210 #else
211 FN(0)
212 FN(8)
213 FN(16)
214 FN(24)
215 #endif
216 #undef FN
217 width -= 4;
218 src += 4;
222 static void glue(pl110_draw_line16_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
224 uint32_t data;
225 unsigned int r, g, b;
226 while (width > 0) {
227 data = *(uint32_t *)src;
228 #ifdef SWAP_WORDS
229 data = bswap32(data);
230 #endif
231 #ifdef RGB
232 #define LSB r
233 #define MSB b
234 #else
235 #define LSB b
236 #define MSB r
237 #endif
238 #if 0
239 LSB = data & 0x1f;
240 data >>= 5;
241 g = data & 0x3f;
242 data >>= 6;
243 MSB = data & 0x1f;
244 data >>= 5;
245 #else
246 LSB = (data & 0x1f) << 3;
247 data >>= 5;
248 g = (data & 0x3f) << 2;
249 data >>= 6;
250 MSB = (data & 0x1f) << 3;
251 data >>= 5;
252 #endif
253 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
254 LSB = (data & 0x1f) << 3;
255 data >>= 5;
256 g = (data & 0x3f) << 2;
257 data >>= 6;
258 MSB = (data & 0x1f) << 3;
259 data >>= 5;
260 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
261 #undef MSB
262 #undef LSB
263 width -= 2;
264 src += 4;
268 static void glue(pl110_draw_line32_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
270 uint32_t data;
271 unsigned int r, g, b;
272 while (width > 0) {
273 data = *(uint32_t *)src;
274 #ifdef RGB
275 #define LSB r
276 #define MSB b
277 #else
278 #define LSB b
279 #define MSB r
280 #endif
281 #ifdef SWAP_WORDS
282 LSB = data & 0xff;
283 g = (data >> 8) & 0xff;
284 MSB = (data >> 16) & 0xff;
285 #else
286 LSB = (data >> 24) & 0xff;
287 g = (data >> 16) & 0xff;
288 MSB = (data >> 8) & 0xff;
289 #endif
290 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
291 #undef MSB
292 #undef LSB
293 width--;
294 src += 4;
298 #undef SWAP_PIXELS
299 #undef NAME
300 #undef SWAP_WORDS
301 #undef ORDER
303 #endif