Replace tabs by 8 spaces. No code change, by Herve Poussineau.
[qemu/dscho.git] / hw / pl110_template.h
blobed533aca1905100b82fe6ed9f0a123ec0d0dff61
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 #define ORDER 0
28 #include "pl110_template.h"
29 #define ORDER 1
30 #include "pl110_template.h"
31 #define ORDER 2
32 #include "pl110_template.h"
34 static drawfn glue(pl110_draw_fn_,BITS)[18] =
36 glue(pl110_draw_line1_lblp,BITS),
37 glue(pl110_draw_line2_lblp,BITS),
38 glue(pl110_draw_line4_lblp,BITS),
39 glue(pl110_draw_line8_lblp,BITS),
40 glue(pl110_draw_line16_lblp,BITS),
41 glue(pl110_draw_line32_lblp,BITS),
43 glue(pl110_draw_line1_bbbp,BITS),
44 glue(pl110_draw_line2_bbbp,BITS),
45 glue(pl110_draw_line4_bbbp,BITS),
46 glue(pl110_draw_line8_bbbp,BITS),
47 glue(pl110_draw_line16_bbbp,BITS),
48 glue(pl110_draw_line32_bbbp,BITS),
50 glue(pl110_draw_line1_lbbp,BITS),
51 glue(pl110_draw_line2_lbbp,BITS),
52 glue(pl110_draw_line4_lbbp,BITS),
53 glue(pl110_draw_line8_lbbp,BITS),
54 glue(pl110_draw_line16_lbbp,BITS),
55 glue(pl110_draw_line32_lbbp,BITS)
58 #undef BITS
59 #undef COPY_PIXEL
61 #else
63 #if ORDER == 0
64 #define NAME glue(lblp, BITS)
65 #ifdef WORDS_BIGENDIAN
66 #define SWAP_WORDS 1
67 #endif
68 #elif ORDER == 1
69 #define NAME glue(bbbp, BITS)
70 #ifndef WORDS_BIGENDIAN
71 #define SWAP_WORDS 1
72 #endif
73 #else
74 #define SWAP_PIXELS 1
75 #define NAME glue(lbbp, BITS)
76 #ifdef WORDS_BIGENDIAN
77 #define SWAP_WORDS 1
78 #endif
79 #endif
81 #define FN_2(x, y) FN(x, y) FN(x+1, y)
82 #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
83 #define FN_8(y) FN_4(0, y) FN_4(4, y)
85 static void glue(pl110_draw_line1_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
87 uint32_t data;
88 while (width > 0) {
89 data = *(uint32_t *)src;
90 #ifdef SWAP_PIXELS
91 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]);
92 #else
93 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]);
94 #endif
95 #ifdef SWAP_WORDS
96 FN_8(24)
97 FN_8(16)
98 FN_8(8)
99 FN_8(0)
100 #else
101 FN_8(0)
102 FN_8(8)
103 FN_8(16)
104 FN_8(24)
105 #endif
106 #undef FN
107 width -= 32;
108 src += 4;
112 static void glue(pl110_draw_line2_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
114 uint32_t data;
115 while (width > 0) {
116 data = *(uint32_t *)src;
117 #ifdef SWAP_PIXELS
118 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]);
119 #else
120 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]);
121 #endif
122 #ifdef SWAP_WORDS
123 FN_4(0, 24)
124 FN_4(0, 16)
125 FN_4(0, 8)
126 FN_4(0, 0)
127 #else
128 FN_4(0, 0)
129 FN_4(0, 8)
130 FN_4(0, 16)
131 FN_4(0, 24)
132 #endif
133 #undef FN
134 width -= 16;
135 src += 4;
139 static void glue(pl110_draw_line4_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
141 uint32_t data;
142 while (width > 0) {
143 data = *(uint32_t *)src;
144 #ifdef SWAP_PIXELS
145 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]);
146 #else
147 #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]);
148 #endif
149 #ifdef SWAP_WORDS
150 FN_2(0, 24)
151 FN_2(0, 16)
152 FN_2(0, 8)
153 FN_2(0, 0)
154 #else
155 FN_2(0, 0)
156 FN_2(0, 8)
157 FN_2(0, 16)
158 FN_2(0, 24)
159 #endif
160 #undef FN
161 width -= 8;
162 src += 4;
166 static void glue(pl110_draw_line8_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
168 uint32_t data;
169 while (width > 0) {
170 data = *(uint32_t *)src;
171 #define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]);
172 #ifdef SWAP_WORDS
173 FN(24)
174 FN(16)
175 FN(8)
176 FN(0)
177 #else
178 FN(0)
179 FN(8)
180 FN(16)
181 FN(24)
182 #endif
183 #undef FN
184 width -= 4;
185 src += 4;
189 static void glue(pl110_draw_line16_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
191 uint32_t data;
192 unsigned int r, g, b;
193 while (width > 0) {
194 data = *(uint32_t *)src;
195 #ifdef SWAP_WORDS
196 data = bswap32(data);
197 #endif
198 #if 0
199 r = data & 0x1f;
200 data >>= 5;
201 g = data & 0x3f;
202 data >>= 6;
203 b = data & 0x1f;
204 data >>= 5;
205 #else
206 r = (data & 0x1f) << 3;
207 data >>= 5;
208 g = (data & 0x3f) << 2;
209 data >>= 6;
210 b = (data & 0x1f) << 3;
211 data >>= 5;
212 #endif
213 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
214 r = (data & 0x1f) << 3;
215 data >>= 5;
216 g = (data & 0x3f) << 2;
217 data >>= 6;
218 b = (data & 0x1f) << 3;
219 data >>= 5;
220 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
221 width -= 2;
222 src += 4;
226 static void glue(pl110_draw_line32_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
228 uint32_t data;
229 unsigned int r, g, b;
230 while (width > 0) {
231 data = *(uint32_t *)src;
232 #ifdef SWAP_WORDS
233 r = data & 0xff;
234 g = (data >> 8) & 0xff;
235 b = (data >> 16) & 0xff;
236 #else
237 r = (data >> 24) & 0xff;
238 g = (data >> 16) & 0xff;
239 b = (data >> 8) & 0xff;
240 #endif
241 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
242 width--;
243 src += 4;
247 #undef SWAP_PIXELS
248 #undef NAME
249 #undef SWAP_WORDS
250 #undef ORDER
252 #endif