2 * linux/drivers/video/iplan2p8.c -- Low level frame buffer operations for
3 * interleaved bitplanes à la Atari (8
4 * planes, 2 bytes interleave)
6 * Created 5 Apr 1997 by Geert Uytterhoeven
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
13 #include <linux/module.h>
14 #include <linux/tty.h>
15 #include <linux/console.h>
16 #include <linux/string.h>
19 #include <asm/byteorder.h>
22 #include <asm/setup.h>
25 #include <video/fbcon.h>
26 #include <video/fbcon-iplan2p8.h>
30 * Interleaved bitplanes à la Atari (8 planes, 2 bytes interleave)
32 * In 8 plane mode, 256 colors would be possible, but only the first
33 * 16 are used by the console code (the upper 4 bits are
34 * background/unused). For that, the following functions mask off the
35 * higher 4 bits of each color.
38 /* Increment/decrement 8 plane addresses */
40 #define INC_8P(p) do { if (!((long)(++(p)) & 1)) (p) += 14; } while(0)
41 #define DEC_8P(p) do { if ((long)(--(p)) & 1) (p) -= 14; } while(0)
43 /* Perform the m68k movepl operation extended to 64 bits. */
44 static inline void movepl2(u8 *d, u32 val1, u32 val2)
46 #if defined __mc68000__ && !defined CPU_M68060_ONLY
47 asm volatile ("movepl %1,%0@(0); movepl %2,%0@(8)"
48 : : "a" (d), "d" (val1), "d" (val2));
50 d[0] = (val1 >> 24) & 0xff;
51 d[2] = (val1 >> 16) & 0xff;
52 d[4] = (val1 >> 8) & 0xff;
54 d[8] = (val2 >> 24) & 0xff;
55 d[10] = (val2 >> 16) & 0xff;
56 d[12] = (val2 >> 8) & 0xff;
61 /* Sets the bytes in the visible column at d, height h, to the value
62 * val1,val2 for a 8 plane screen. The bits of the color in 'color' are
63 * moved (8 times) to the respective bytes. This means:
65 * for(h times; d += bpr)
66 * *d = (color & 1) ? 0xff : 0;
67 * *(d+2) = (color & 2) ? 0xff : 0;
68 * *(d+4) = (color & 4) ? 0xff : 0;
69 * *(d+6) = (color & 8) ? 0xff : 0;
70 * *(d+8) = (color & 16) ? 0xff : 0;
71 * *(d+10) = (color & 32) ? 0xff : 0;
72 * *(d+12) = (color & 64) ? 0xff : 0;
73 * *(d+14) = (color & 128) ? 0xff : 0;
76 static __inline__ void memclear_8p_col(void *d, size_t h, u32 val1,
81 movepl2(dd, val1, val2);
86 /* Sets a 8 plane region from 'd', length 'count' bytes, to the color
87 * val1..val4. 'd' has to be an even address and count must be divisible
88 * by 16, because only whole words and all planes are accessed. I.e.:
91 * *d = *(d+1) = (color & 1) ? 0xff : 0;
92 * *(d+2) = *(d+3) = (color & 2) ? 0xff : 0;
93 * *(d+4) = *(d+5) = (color & 4) ? 0xff : 0;
94 * *(d+6) = *(d+7) = (color & 8) ? 0xff : 0;
95 * *(d+8) = *(d+9) = (color & 16) ? 0xff : 0;
96 * *(d+10) = *(d+11) = (color & 32) ? 0xff : 0;
97 * *(d+12) = *(d+13) = (color & 64) ? 0xff : 0;
98 * *(d+14) = *(d+15) = (color & 128) ? 0xff : 0;
101 static __inline__ void memset_even_8p(void *d, size_t count, u32 val1,
102 u32 val2, u32 val3, u32 val4)
115 /* Copies a 8 plane column from 's', height 'h', to 'd'. */
117 static __inline__ void memmove_8p_col (void *d, void *s, int h, int bpr)
136 /* This expands a 8 bit color into two longs for two movepl (8 plane)
140 static const u32 four2long[] =
142 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000,
143 0x0000ff00, 0xff00ff00, 0x00ffff00, 0xffffff00,
144 0x000000ff, 0xff0000ff, 0x00ff00ff, 0xffff00ff,
145 0x0000ffff, 0xff00ffff, 0x00ffffff, 0xffffffff,
148 static __inline__ void expand8dl(u8 c, u32 *ret1, u32 *ret2)
150 *ret1 = four2long[c & 15];
151 *ret2 = four2long[c >> 4];
155 /* This expands a 8 bit color into four longs for four movel operations
159 static const u32 two2word[] =
161 #ifndef __LITTLE_ENDIAN
162 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
164 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
168 static inline void expand8ql(u8 c, u32 *rv1, u32 *rv2, u32 *rv3, u32 *rv4)
170 *rv1 = two2word[c & 4];
171 *rv2 = two2word[(c >> 2) & 4];
172 *rv3 = two2word[(c >> 4) & 4];
173 *rv4 = two2word[c >> 6];
177 /* This duplicates a byte 4 times into a long. */
179 static __inline__ u32 dup4l(u8 c)
190 void fbcon_iplan2p8_setup(struct display *p)
192 p->next_line = p->var.xres_virtual;
196 void fbcon_iplan2p8_bmove(struct display *p, int sy, int sx, int dy, int dx,
197 int height, int width)
199 /* bmove() has to distinguish two major cases: If both, source and
200 * destination, start at even addresses or both are at odd
201 * addresses, just the first odd and last even column (if present)
202 * require special treatment (memmove_col()). The rest between
203 * then can be copied by normal operations, because all adjacent
204 * bytes are affected and are to be stored in the same order.
205 * The pathological case is when the move should go from an odd
206 * address to an even or vice versa. Since the bytes in the plane
207 * words must be assembled in new order, it seems wisest to make
208 * all movements by memmove_col().
211 if (sx == 0 && dx == 0 && width * 8 == p->next_line) {
212 /* Special (but often used) case: Moving whole lines can be
213 * done with memmove()
215 fast_memmove(p->screen_base + dy * p->next_line * fontheight(p),
216 p->screen_base + sy * p->next_line * fontheight(p),
217 p->next_line * height * fontheight(p));
222 int bytes = p->next_line;
225 u_int upwards = (dy < sy) || (dy == sy && dx < sx);
227 if (fontheightlog(p)) {
228 linesize = bytes << fontheightlog(p);
229 colsize = height << fontheightlog(p);
231 linesize = bytes * fontheight(p);
232 colsize = height * fontheight(p);
234 if ((sx & 1) == (dx & 1)) {
235 /* odd->odd or even->even */
238 src = p->screen_base + sy * linesize + (sx>>1)*16 + (sx & 1);
239 dst = p->screen_base + dy * linesize + (dx>>1)*16 + (dx & 1);
241 memmove_8p_col(dst, src, colsize, bytes);
247 for(rows = colsize; rows > 0; --rows) {
248 fast_memmove (dst, src, (width >> 1) * 16);
255 src -= colsize * bytes;
256 dst -= colsize * bytes;
257 memmove_8p_col(dst + (width>>1)*16, src + (width>>1)*16,
261 if (!((sx+width-1) & 1)) {
262 src = p->screen_base + sy * linesize + ((sx+width-1)>>1)*16;
263 dst = p->screen_base + dy * linesize + ((dx+width-1)>>1)*16;
264 memmove_8p_col(dst, src, colsize, bytes);
267 src = p->screen_base + sy * linesize + (sx>>1)*16 + (sx & 1);
268 dst = p->screen_base + dy * linesize + (dx>>1)*16 + (dx & 1);
270 src += colsize * bytes + (sx & 1)*15;
271 dst += colsize * bytes + (sx & 1)*15;
272 for(rows = colsize; rows > 0; --rows) {
275 fast_memmove (dst, src, (width>>1)*16);
279 memmove_8p_col(dst-15, src-15, colsize, bytes);
282 /* odd->even or even->odd */
285 src = p->screen_base + sy * linesize + (sx>>1)*16 + (sx & 1);
286 dst = p->screen_base + dy * linesize + (dx>>1)*16 + (dx & 1);
287 for(cols = width; cols > 0; --cols) {
288 memmove_8p_col(dst, src, colsize, bytes);
295 src = p->screen_base + sy * linesize + (sx>>1)*16 + (sx & 1);
296 dst = p->screen_base + dy * linesize + (dx>>1)*16 + (dx & 1);
297 for(cols = width; cols > 0; --cols) {
298 memmove_8p_col(dst, src, colsize, bytes);
307 void fbcon_iplan2p8_clear(struct vc_data *conp, struct display *p, int sy,
308 int sx, int height, int width)
313 int bytes = p->next_line;
316 u32 cval1, cval2, cval3, cval4, pcval1, pcval2;
318 expand8ql(attr_bgcol_ec(p,conp), &cval1, &cval2, &cval3, &cval4);
320 if (fontheightlog(p))
321 lines = height << fontheightlog(p);
323 lines = height * fontheight(p);
325 if (sx == 0 && width * 8 == bytes) {
326 if (fontheightlog(p))
327 offset = (sy * bytes) << fontheightlog(p);
329 offset = sy * bytes * fontheight(p);
330 size = lines * bytes;
331 memset_even_8p(p->screen_base+offset, size, cval1, cval2, cval3, cval4);
333 if (fontheightlog(p))
334 offset = ((sy * bytes) << fontheightlog(p)) + (sx>>1)*16 + (sx & 1);
336 offset = sy * bytes * fontheight(p) + (sx>>1)*16 + (sx & 1);
337 start = p->screen_base + offset;
338 expand8dl(attr_bgcol_ec(p,conp), &pcval1, &pcval2);
340 /* Clears are split if the region starts at an odd column or
341 * end at an even column. These extra columns are spread
342 * across the interleaved planes. All in between can be
343 * cleared by normal fb_memclear_small(), because both bytes of
344 * the single plane words are affected.
348 memclear_8p_col(start, lines, pcval1, pcval2, bytes);
353 memclear_8p_col(start + (width>>1)*16, lines, pcval1,
358 for(rows = lines; rows-- ; start += bytes)
359 memset_even_8p(start, width*8, cval1, cval2, cval3, cval4);
363 void fbcon_iplan2p8_putc(struct vc_data *conp, struct display *p, int c,
369 int bytes = p->next_line;
370 u32 eorx1, eorx2, fgx1, fgx2, bgx1, bgx2, fdx;
372 if (fontheightlog(p)) {
373 dest = (p->screen_base + ((yy * bytes) << fontheightlog(p)) +
374 (xx>>1)*16 + (xx & 1));
375 cdat = p->fontdata + ((c & p->charmask) << fontheightlog(p));
377 dest = (p->screen_base + yy * bytes * fontheight(p) +
378 (xx>>1)*16 + (xx & 1));
379 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
382 expand8dl(attr_fgcol(p,c), &fgx1, &fgx2);
383 expand8dl(attr_bgcol(p,c), &bgx1, &bgx2);
384 eorx1 = fgx1 ^ bgx1; eorx2 = fgx2 ^ bgx2;
386 for(rows = fontheight(p) ; rows-- ; dest += bytes) {
387 fdx = dup4l(*cdat++);
388 movepl2(dest, (fdx & eorx1) ^ bgx1, (fdx & eorx2) ^ bgx2);
392 void fbcon_iplan2p8_putcs(struct vc_data *conp, struct display *p,
393 const unsigned short *s, int count, int yy, int xx)
400 u32 eorx1, eorx2, fgx1, fgx2, bgx1, bgx2, fdx;
402 bytes = p->next_line;
403 if (fontheightlog(p))
404 dest0 = (p->screen_base + ((yy * bytes) << fontheightlog(p)) +
405 (xx>>1)*16 + (xx & 1));
407 dest0 = (p->screen_base + yy * bytes * fontheight(p) +
408 (xx>>1)*16 + (xx & 1));
411 expand8dl(attr_fgcol(p, c), &fgx1, &fgx2);
412 expand8dl(attr_bgcol(p, c), &bgx1, &bgx2);
413 eorx1 = fgx1 ^ bgx1; eorx2 = fgx2 ^ bgx2;
417 /* I think, unrolling the loops like in the 1 plane case isn't
418 * practicable here, because the body is much longer for 4
419 * planes (mostly the dup4l()). I guess, unrolling this would
420 * need more than 256 bytes and so exceed the instruction
424 c = scr_readw(s++) & p->charmask;
425 if (fontheightlog(p))
426 cdat = p->fontdata + (c << fontheightlog(p));
428 cdat = p->fontdata + c * fontheight(p);
430 for(rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
431 fdx = dup4l(*cdat++);
432 movepl2(dest, (fdx & eorx1) ^ bgx1, (fdx & eorx2) ^ bgx2);
438 void fbcon_iplan2p8_revc(struct display *p, int xx, int yy)
444 if (fontheightlog(p))
445 dest = (p->screen_base + ((yy * p->next_line) << fontheightlog(p)) +
446 (xx>>1)*16 + (xx & 1));
448 dest = (p->screen_base + yy * p->next_line * fontheight(p) +
449 (xx>>1)*16 + (xx & 1));
451 bytes = p->next_line;
454 /* This should really obey the individual character's
455 * background and foreground colors instead of simply
456 * inverting. For 8 plane mode, only the lower 4 bits of the
457 * color are inverted, because only these color registers have
468 void fbcon_iplan2p8_clear_margins(struct vc_data *conp, struct display *p,
474 u32 cval1, cval2, cval3, cval4;
476 /* No need to handle right margin, cannot occur with fontwidth == 8 */
478 bytes = p->next_line;
479 if (fontheightlog(p)) {
480 lines = p->var.yres - (conp->vc_rows << fontheightlog(p));
481 offset = ((p->yscroll + conp->vc_rows) * bytes) << fontheightlog(p);
483 lines = p->var.yres - conp->vc_rows * fontheight(p);
484 offset = (p->yscroll + conp->vc_rows) * bytes * fontheight(p);
487 expand8ql(attr_bgcol_ec(p,conp), &cval1, &cval2, &cval3, &cval4);
488 memset_even_8p(p->screen_base+offset, lines * bytes,
489 cval1, cval2, cval3, cval4);
495 * `switch' for the low level operations
498 struct display_switch fbcon_iplan2p8 = {
499 setup: fbcon_iplan2p8_setup,
500 bmove: fbcon_iplan2p8_bmove,
501 clear: fbcon_iplan2p8_clear,
502 putc: fbcon_iplan2p8_putc,
503 putcs: fbcon_iplan2p8_putcs,
504 revc: fbcon_iplan2p8_revc,
505 clear_margins: fbcon_iplan2p8_clear_margins,
506 fontwidthmask: FONTWIDTH(8)
511 MODULE_LICENSE("GPL");
513 int init_module(void)
518 void cleanup_module(void)
524 * Visible symbols for modules
527 EXPORT_SYMBOL(fbcon_iplan2p8);
528 EXPORT_SYMBOL(fbcon_iplan2p8_setup);
529 EXPORT_SYMBOL(fbcon_iplan2p8_bmove);
530 EXPORT_SYMBOL(fbcon_iplan2p8_clear);
531 EXPORT_SYMBOL(fbcon_iplan2p8_putc);
532 EXPORT_SYMBOL(fbcon_iplan2p8_putcs);
533 EXPORT_SYMBOL(fbcon_iplan2p8_revc);
534 EXPORT_SYMBOL(fbcon_iplan2p8_clear_margins);