Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / drivers / video / fbcon-cfb4.c
blob98b3fd1194a9c526ed7a42470da3a0570d678951
1 /*
2 * linux/drivers/video/cfb4.c -- Low level frame buffer operations for 4 bpp
3 * packed pixels
5 * Created 26 Dec 1997 by Michael Schmitz
6 * Based on the old macfb.c 4bpp code by Alan Cox
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
10 * more details.
13 #include <linux/module.h>
14 #include <linux/tty.h>
15 #include <linux/console.h>
16 #include <linux/string.h>
17 #include <linux/fb.h>
19 #include <video/fbcon.h>
20 #include <video/fbcon-cfb4.h>
24 * 4 bpp packed pixels
28 * IFF the font is even pixel aligned (that is to say each
29 * character start is a byte start in the pixel pairs). That
30 * avoids us having to mask bytes and means we won't be here
31 * all week. On a MacII that matters _lots_
34 static u16 nibbletab_cfb4[] = {
35 #if defined(__BIG_ENDIAN)
36 0x0000,0x000f,0x00f0,0x00ff,
37 0x0f00,0x0f0f,0x0ff0,0x0fff,
38 0xf000,0xf00f,0xf0f0,0xf0ff,
39 0xff00,0xff0f,0xfff0,0xffff
40 #elif defined(__LITTLE_ENDIAN)
41 0x0000,0xf000,0x0f00,0xff00,
42 0x00f0,0xf0f0,0x0ff0,0xfff0,
43 0x000f,0xf00f,0x0f0f,0xff0f,
44 0x00ff,0xf0ff,0x0fff,0xffff
45 #else
46 #error FIXME: No endianness??
47 #endif
51 void fbcon_cfb4_setup(struct display *p)
53 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual>>1;
54 p->next_plane = 0;
57 void fbcon_cfb4_bmove(struct display *p, int sy, int sx, int dy, int dx,
58 int height, int width)
60 int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
61 u8 *src,*dst;
63 if (sx == 0 && dx == 0 && width * 4 == bytes) {
64 fb_memmove(p->screen_base + dy * linesize,
65 p->screen_base + sy * linesize,
66 height * linesize);
68 else {
69 if (dy < sy || (dy == sy && dx < sx)) {
70 src = p->screen_base + sy * linesize + sx * 4;
71 dst = p->screen_base + dy * linesize + dx * 4;
72 for (rows = height * fontheight(p) ; rows-- ;) {
73 fb_memmove(dst, src, width * 4);
74 src += bytes;
75 dst += bytes;
78 else {
79 src = p->screen_base + (sy+height) * linesize + sx * 4
80 - bytes;
81 dst = p->screen_base + (dy+height) * linesize + dx * 4
82 - bytes;
83 for (rows = height * fontheight(p) ; rows-- ;) {
84 fb_memmove(dst, src, width * 4);
85 src -= bytes;
86 dst -= bytes;
92 void fbcon_cfb4_clear(struct vc_data *conp, struct display *p, int sy, int sx,
93 int height, int width)
95 u8 *dest0,*dest;
96 int bytes=p->next_line,lines=height * fontheight(p), rows, i;
97 u32 bgx;
99 /* if(p->screen_base!=0xFDD00020)
100 mac_boom(1);*/
101 dest = p->screen_base + sy * fontheight(p) * bytes + sx * 4;
103 bgx=attr_bgcol_ec(p,conp);
104 bgx |= (bgx << 4); /* expand the colour to 32bits */
105 bgx |= (bgx << 8);
106 bgx |= (bgx << 16);
108 if (sx == 0 && width * 4 == bytes) {
109 for (i = 0 ; i < lines * width ; i++) {
110 fb_writel (bgx, dest);
111 dest+=4;
113 } else {
114 dest0=dest;
115 for (rows = lines; rows-- ; dest0 += bytes) {
116 dest=dest0;
117 for (i = 0 ; i < width ; i++) {
118 /* memset ?? */
119 fb_writel (bgx, dest);
120 dest+=4;
126 void fbcon_cfb4_putc(struct vc_data *conp, struct display *p, int c, int yy,
127 int xx)
129 u8 *dest,*cdat;
130 int bytes=p->next_line,rows;
131 u32 eorx,fgx,bgx;
133 dest = p->screen_base + yy * fontheight(p) * bytes + xx * 4;
134 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
136 fgx=attr_fgcol(p,c);
137 bgx=attr_bgcol(p,c);
138 fgx |= (fgx << 4);
139 fgx |= (fgx << 8);
140 bgx |= (bgx << 4);
141 bgx |= (bgx << 8);
142 eorx = fgx ^ bgx;
144 for (rows = fontheight(p) ; rows-- ; dest += bytes) {
145 fb_writew((nibbletab_cfb4[*cdat >> 4] & eorx) ^ bgx, dest+0);
146 fb_writew((nibbletab_cfb4[*cdat++ & 0xf] & eorx) ^ bgx, dest+2);
150 void fbcon_cfb4_putcs(struct vc_data *conp, struct display *p,
151 const unsigned short *s, int count, int yy, int xx)
153 u8 *cdat, *dest, *dest0;
154 u16 c;
155 int rows,bytes=p->next_line;
156 u32 eorx, fgx, bgx;
158 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * 4;
159 fgx=attr_fgcol(p,scr_readw(s));
160 bgx=attr_bgcol(p,scr_readw(s));
161 fgx |= (fgx << 4);
162 fgx |= (fgx << 8);
163 fgx |= (fgx << 16);
164 bgx |= (bgx << 4);
165 bgx |= (bgx << 8);
166 bgx |= (bgx << 16);
167 eorx = fgx ^ bgx;
168 while (count--) {
169 c = scr_readw(s++) & p->charmask;
170 cdat = p->fontdata + c * fontheight(p);
172 for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
173 fb_writew((nibbletab_cfb4[*cdat >> 4] & eorx) ^ bgx, dest+0);
174 fb_writew((nibbletab_cfb4[*cdat++ & 0xf] & eorx) ^ bgx, dest+2);
176 dest0+=4;
180 void fbcon_cfb4_revc(struct display *p, int xx, int yy)
182 u8 *dest;
183 int bytes=p->next_line, rows;
185 dest = p->screen_base + yy * fontheight(p) * bytes + xx * 4;
186 for (rows = fontheight(p) ; rows-- ; dest += bytes) {
187 fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
193 * `switch' for the low level operations
196 struct display_switch fbcon_cfb4 = {
197 setup: fbcon_cfb4_setup,
198 bmove: fbcon_cfb4_bmove,
199 clear: fbcon_cfb4_clear,
200 putc: fbcon_cfb4_putc,
201 putcs: fbcon_cfb4_putcs,
202 revc: fbcon_cfb4_revc,
203 fontwidthmask: FONTWIDTH(8)
207 #ifdef MODULE
208 int init_module(void)
210 return 0;
213 void cleanup_module(void)
215 #endif /* MODULE */
219 * Visible symbols for modules
222 EXPORT_SYMBOL(fbcon_cfb4);
223 EXPORT_SYMBOL(fbcon_cfb4_setup);
224 EXPORT_SYMBOL(fbcon_cfb4_bmove);
225 EXPORT_SYMBOL(fbcon_cfb4_clear);
226 EXPORT_SYMBOL(fbcon_cfb4_putc);
227 EXPORT_SYMBOL(fbcon_cfb4_putcs);
228 EXPORT_SYMBOL(fbcon_cfb4_revc);