Import 2.3.15pre2
[davej-history.git] / drivers / video / fbcon-cfb4.c
blob6248c28eee894783e4793b3179963c3925aa9681
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 mymemmove(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 mymemmove(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 mymemmove(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 ((u32 *)dest)[0]=bgx;
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 ((u32 *)dest)[0]=bgx;
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 ((u16 *)dest)[0]=
146 (nibbletab_cfb4[*cdat >> 4] & eorx) ^ bgx;
147 ((u16 *)dest)[1]=
148 (nibbletab_cfb4[*cdat++ & 0xf] & eorx) ^ bgx;
152 void fbcon_cfb4_putcs(struct vc_data *conp, struct display *p,
153 const unsigned short *s, int count, int yy, int xx)
155 u8 *cdat, *dest, *dest0;
156 u16 c;
157 int rows,bytes=p->next_line;
158 u32 eorx, fgx, bgx;
160 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * 4;
161 fgx=attr_fgcol(p,scr_readw(s));
162 bgx=attr_bgcol(p,scr_readw(s));
163 fgx |= (fgx << 4);
164 fgx |= (fgx << 8);
165 fgx |= (fgx << 16);
166 bgx |= (bgx << 4);
167 bgx |= (bgx << 8);
168 bgx |= (bgx << 16);
169 eorx = fgx ^ bgx;
170 while (count--) {
171 c = scr_readw(s++) & p->charmask;
172 cdat = p->fontdata + c * fontheight(p);
174 for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
175 ((u16 *)dest)[0]=
176 (nibbletab_cfb4[*cdat >> 4] & eorx) ^ bgx;
177 ((u16 *)dest)[1]=
178 (nibbletab_cfb4[*cdat++ & 0xf] & eorx) ^ bgx;
180 dest0+=4;
184 void fbcon_cfb4_revc(struct display *p, int xx, int yy)
186 u8 *dest;
187 int bytes=p->next_line, rows;
189 dest = p->screen_base + yy * fontheight(p) * bytes + xx * 4;
190 for (rows = fontheight(p) ; rows-- ; dest += bytes) {
191 ((u32 *)dest)[0] ^= 0xffffffff;
197 * `switch' for the low level operations
200 struct display_switch fbcon_cfb4 = {
201 fbcon_cfb4_setup, fbcon_cfb4_bmove, fbcon_cfb4_clear, fbcon_cfb4_putc,
202 fbcon_cfb4_putcs, fbcon_cfb4_revc, NULL, NULL, NULL, FONTWIDTH(8)
206 #ifdef MODULE
207 int init_module(void)
209 return 0;
212 void cleanup_module(void)
214 #endif /* MODULE */
218 * Visible symbols for modules
221 EXPORT_SYMBOL(fbcon_cfb4);
222 EXPORT_SYMBOL(fbcon_cfb4_setup);
223 EXPORT_SYMBOL(fbcon_cfb4_bmove);
224 EXPORT_SYMBOL(fbcon_cfb4_clear);
225 EXPORT_SYMBOL(fbcon_cfb4_putc);
226 EXPORT_SYMBOL(fbcon_cfb4_putcs);
227 EXPORT_SYMBOL(fbcon_cfb4_revc);