fbcon-ilbm.c 6.98 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 *  linux/drivers/video/ilbm.c -- Low level frame buffer operations for
 *				  interleaved bitplanes  la Amiga
 *
 *	Created 5 Apr 1997 by Geert Uytterhoeven
 *
 *  This file is subject to the terms and conditions of the GNU General Public
 *  License.  See the file COPYING in the main directory of this archive for
 *  more details.
 */

#include <linux/module.h>
#include <linux/tty.h>
#include <linux/console.h>
#include <linux/string.h>
#include <linux/fb.h>

#include <video/fbcon.h>
#include <video/fbcon-ilbm.h>


    /*
     *  Interleaved bitplanes  la Amiga
     *
     *  This code heavily relies on the fact that
     *
     *      next_line == interleave == next_plane*bits_per_pixel
     *
     *  But maybe it can be merged with the code for normal bitplanes without
     *  much performance loss?
     */

void fbcon_ilbm_setup(struct display *p)
{
35 36 37
    if (p->fb_info->fix.line_length) {
	p->next_line = p->fb_info->fix.line_length*p->var.bits_per_pixel;
	p->next_plane = p->fb_info->fix.line_length;
Linus Torvalds's avatar
Linus Torvalds committed
38
    } else {
39 40
	p->next_line = p->fb_info->fix.type_aux;
	p->next_plane = p->fb_info->fix.type_aux/p->var.bits_per_pixel;
Linus Torvalds's avatar
Linus Torvalds committed
41 42 43 44 45 46 47
    }
}

void fbcon_ilbm_bmove(struct display *p, int sy, int sx, int dy, int dx,
		      int height, int width)
{
    if (sx == 0 && dx == 0 && width == p->next_plane)
48 49
	fb_memmove(p->fb_info->screen_base+dy*fontheight(p)*p->next_line,
		  p->fb_info->screen_base+sy*fontheight(p)*p->next_line,
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52 53 54 55
		  height*fontheight(p)*p->next_line);
    else {
	u8 *src, *dest;
	u_int i;

	if (dy <= sy) {
56 57
	    src = p->fb_info->screen_base+sy*fontheight(p)*p->next_line+sx;
	    dest = p->fb_info->screen_base+dy*fontheight(p)*p->next_line+dx;
Linus Torvalds's avatar
Linus Torvalds committed
58 59 60 61 62 63
	    for (i = p->var.bits_per_pixel*height*fontheight(p); i--;) {
		fb_memmove(dest, src, width);
		src += p->next_plane;
		dest += p->next_plane;
	    }
	} else {
64 65
	    src = p->fb_info->screen_base+(sy+height)*fontheight(p)*p->next_line+sx;
	    dest = p->fb_info->screen_base+(dy+height)*fontheight(p)*p->next_line+dx;
Linus Torvalds's avatar
Linus Torvalds committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	    for (i = p->var.bits_per_pixel*height*fontheight(p); i--;) {
		src -= p->next_plane;
		dest -= p->next_plane;
		fb_memmove(dest, src, width);
	    }
	}
    }
}

void fbcon_ilbm_clear(struct vc_data *conp, struct display *p, int sy, int sx,
		      int height, int width)
{
    u8 *dest;
    u_int i, rows;
    int bg, bg0;

82
    dest = p->fb_info->screen_base+sy*fontheight(p)*p->next_line+sx;
Linus Torvalds's avatar
Linus Torvalds committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

    bg0 = attr_bgcol_ec(p,conp);
    for (rows = height*fontheight(p); rows--;) {
	bg = bg0;
	for (i = p->var.bits_per_pixel; i--; dest += p->next_plane) {
	    if (bg & 1)
		fb_memset255(dest, width);
	    else
		fb_memclear(dest, width);
	    bg >>= 1;
	}
    }
}

void fbcon_ilbm_putc(struct vc_data *conp, struct display *p, int c, int yy,
		     int xx)
{
    u8 *dest, *cdat;
    u_int rows, i;
    u8 d;
    int fg0, bg0, fg, bg;

105
    dest = p->fb_info->screen_base+yy*fontheight(p)*p->next_line+xx;
Linus Torvalds's avatar
Linus Torvalds committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    cdat = p->fontdata+(c&p->charmask)*fontheight(p);
    fg0 = attr_fgcol(p,c);
    bg0 = attr_bgcol(p,c);

    for (rows = fontheight(p); rows--;) {
	d = *cdat++;
	fg = fg0;
	bg = bg0;
	for (i = p->var.bits_per_pixel; i--; dest += p->next_plane) {
	    if (bg & 1){
		if (fg & 1)
		    *dest = 0xff;
		else
		    *dest = ~d;
	    }else{
		if (fg & 1)
		    *dest = d;
		else
		    *dest = 0x00;
	    }
	    bg >>= 1;
	    fg >>= 1;
	}
    }
}

    /*
     *  I've split the console character loop in two parts:
     *
     *      - slow version: this blits one character at a time
     *
     *      - fast version: this blits 4 characters at a time at a longword
     *			    aligned address, to reduce the number of expensive
     *			    Chip RAM accesses.
     *
     *  Experiments on my A4000/040 revealed that this makes a console switch
     *  on a 640x400 screen with 256 colors about 3 times faster.
     *
     *  -- Geert
     */

void fbcon_ilbm_putcs(struct vc_data *conp, struct display *p, 
		      const unsigned short *s, int count, int yy, int xx)
{
    u8 *dest0, *dest, *cdat1, *cdat2, *cdat3, *cdat4;
    u_int rows, i;
    u16 c1, c2, c3, c4;
    u32 d;
    int fg0, bg0, fg, bg;

156
    dest0 = p->fb_info->screen_base+yy*fontheight(p)*p->next_line+xx;
Linus Torvalds's avatar
Linus Torvalds committed
157 158 159
    c1 = scr_readw(s);
    fg0 = attr_fgcol(p, c1);
    bg0 = attr_bgcol(p, c1);
Linus Torvalds's avatar
Linus Torvalds committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

    while (count--)
	if (xx&3 || count < 3) {	/* Slow version */
	    c1 = scr_readw(s++) & p->charmask;
	    dest = dest0++;
	    xx++;

	    cdat1 = p->fontdata+c1*fontheight(p);
	    for (rows = fontheight(p); rows--;) {
		d = *cdat1++;
		fg = fg0;
		bg = bg0;
		for (i = p->var.bits_per_pixel; i--; dest += p->next_plane) {
		    if (bg & 1){
			if (fg & 1)
			    *dest = 0xff;
			else
			    *dest = ~d;
		    }else{
			if (fg & 1)
			    *dest = d;
			else
			    *dest = 0x00;
		    }
		    bg >>= 1;
		    fg >>= 1;
		}
	    }
	} else {		/* Fast version */
	    c1 = scr_readw(&s[0]) & p->charmask;
	    c2 = scr_readw(&s[1]) & p->charmask;
	    c3 = scr_readw(&s[2]) & p->charmask;
	    c4 = scr_readw(&s[3]) & p->charmask;

	    dest = dest0;
	    cdat1 = p->fontdata+c1*fontheight(p);
	    cdat2 = p->fontdata+c2*fontheight(p);
	    cdat3 = p->fontdata+c3*fontheight(p);
	    cdat4 = p->fontdata+c4*fontheight(p);
	    for (rows = fontheight(p); rows--;) {
#if defined(__BIG_ENDIAN)
		d = *cdat1++<<24 | *cdat2++<<16 | *cdat3++<<8 | *cdat4++;
#elif defined(__LITTLE_ENDIAN)
		d = *cdat1++ | *cdat2++<<8 | *cdat3++<<16 | *cdat4++<<24;
#else
#error FIXME: No endianness??
#endif
		fg = fg0;
		bg = bg0;
		for (i = p->var.bits_per_pixel; i--; dest += p->next_plane) {
		    if (bg & 1){
			if (fg & 1)
			    *(u32 *)dest = 0xffffffff;
			else
			    *(u32 *)dest = ~d;
		    }else{
			if (fg & 1)
			    *(u32 *)dest = d;
			else
			    *(u32 *)dest = 0x00000000;
		    }
		    bg >>= 1;
		    fg >>= 1;
		}
	    }
	    s += 4;
	    dest0 += 4;
	    xx += 4;
	    count -= 3;
	}
}

void fbcon_ilbm_revc(struct display *p, int xx, int yy)
{
    u8 *dest, *dest0;
    u_int rows, i;
    int mask;

238
    dest0 = p->fb_info->screen_base+yy*fontheight(p)*p->next_line+xx;
Linus Torvalds's avatar
Linus Torvalds committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
    mask = p->fgcol ^ p->bgcol;

    /*
     *  This should really obey the individual character's
     *  background and foreground colors instead of simply
     *  inverting.
     */

    for (i = p->var.bits_per_pixel; i--; dest0 += p->next_plane) {
	if (mask & 1) {
	    dest = dest0;
	    for (rows = fontheight(p); rows--; dest += p->next_line)
		*dest = ~*dest;
	}
	mask >>= 1;
    }
}


    /*
     *  `switch' for the low level operations
     */

struct display_switch fbcon_ilbm = {
    setup:		fbcon_ilbm_setup,
    bmove:		fbcon_ilbm_bmove,
    clear:		fbcon_ilbm_clear,
    putc:		fbcon_ilbm_putc,
    putcs:		fbcon_ilbm_putcs,
    revc:		fbcon_ilbm_revc,
    fontwidthmask:	FONTWIDTH(8)
};


#ifdef MODULE
Linus Torvalds's avatar
Linus Torvalds committed
274 275
MODULE_LICENSE("GPL");

Linus Torvalds's avatar
Linus Torvalds committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
int init_module(void)
{
    return 0;
}

void cleanup_module(void)
{}
#endif /* MODULE */


    /*
     *  Visible symbols for modules
     */

EXPORT_SYMBOL(fbcon_ilbm);
EXPORT_SYMBOL(fbcon_ilbm_setup);
EXPORT_SYMBOL(fbcon_ilbm_bmove);
EXPORT_SYMBOL(fbcon_ilbm_clear);
EXPORT_SYMBOL(fbcon_ilbm_putc);
EXPORT_SYMBOL(fbcon_ilbm_putcs);
EXPORT_SYMBOL(fbcon_ilbm_revc);