linux/drivers/video/fbdev/atafb_iplan2p4.c
<<
>>
Prefs
   1/*
   2 *  linux/drivers/video/iplan2p4.c -- Low level frame buffer operations for
   3 *                                    interleaved bitplanes à la Atari (4
   4 *                                    planes, 2 bytes interleave)
   5 *
   6 *      Created 5 Apr 1997 by Geert Uytterhoeven
   7 *
   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.
  11 */
  12
  13#include <linux/module.h>
  14#include <linux/string.h>
  15#include <linux/fb.h>
  16
  17#include <asm/setup.h>
  18
  19#include "atafb.h"
  20
  21#define BPL     4
  22#include "atafb_utils.h"
  23
  24void atafb_iplan2p4_copyarea(struct fb_info *info, u_long next_line,
  25                             int sy, int sx, int dy, int dx,
  26                             int height, int width)
  27{
  28        /*  bmove() has to distinguish two major cases: If both, source and
  29         *  destination, start at even addresses or both are at odd
  30         *  addresses, just the first odd and last even column (if present)
  31         *  require special treatment (memmove_col()). The rest between
  32         *  then can be copied by normal operations, because all adjacent
  33         *  bytes are affected and are to be stored in the same order.
  34         *    The pathological case is when the move should go from an odd
  35         *  address to an even or vice versa. Since the bytes in the plane
  36         *  words must be assembled in new order, it seems wisest to make
  37         *  all movements by memmove_col().
  38         */
  39
  40        u8 *src, *dst;
  41        u32 *s, *d;
  42        int w, l , i, j;
  43        u_int colsize;
  44        u_int upwards = (dy < sy) || (dy == sy && dx < sx);
  45
  46        colsize = height;
  47        if (!((sx ^ dx) & 15)) {
  48                /* odd->odd or even->even */
  49
  50                if (upwards) {
  51                        src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
  52                        dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
  53                        if (sx & 15) {
  54                                memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
  55                                src += BPL * 2;
  56                                dst += BPL * 2;
  57                                width -= 8;
  58                        }
  59                        w = width >> 4;
  60                        if (w) {
  61                                s = (u32 *)src;
  62                                d = (u32 *)dst;
  63                                w *= BPL / 2;
  64                                l = next_line - w * 4;
  65                                for (j = height; j > 0; j--) {
  66                                        for (i = w; i > 0; i--)
  67                                                *d++ = *s++;
  68                                        s = (u32 *)((u8 *)s + l);
  69                                        d = (u32 *)((u8 *)d + l);
  70                                }
  71                        }
  72                        if (width & 15)
  73                                memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
  74                                              0xff00ff00, height, next_line - BPL * 2);
  75                } else {
  76                        src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
  77                        dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
  78
  79                        if ((sx + width) & 15) {
  80                                src -= BPL * 2;
  81                                dst -= BPL * 2;
  82                                memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
  83                                width -= 8;
  84                        }
  85                        w = width >> 4;
  86                        if (w) {
  87                                s = (u32 *)src;
  88                                d = (u32 *)dst;
  89                                w *= BPL / 2;
  90                                l = next_line - w * 4;
  91                                for (j = height; j > 0; j--) {
  92                                        for (i = w; i > 0; i--)
  93                                                *--d = *--s;
  94                                        s = (u32 *)((u8 *)s - l);
  95                                        d = (u32 *)((u8 *)d - l);
  96                                }
  97                        }
  98                        if (sx & 15)
  99                                memmove32_col(dst - (width - 16) / (8 / BPL),
 100                                              src - (width - 16) / (8 / BPL),
 101                                              0xff00ff, colsize, -next_line - BPL * 2);
 102                }
 103        } else {
 104                /* odd->even or even->odd */
 105                if (upwards) {
 106                        u32 *src32, *dst32;
 107                        u32 pval[4], v, v1, mask;
 108                        int i, j, w, f;
 109
 110                        src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
 111                        dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
 112
 113                        mask = 0xff00ff00;
 114                        f = 0;
 115                        w = width;
 116                        if (sx & 15) {
 117                                f = 1;
 118                                w += 8;
 119                        }
 120                        if ((sx + width) & 15)
 121                                f |= 2;
 122                        w >>= 4;
 123                        for (i = height; i; i--) {
 124                                src32 = (u32 *)src;
 125                                dst32 = (u32 *)dst;
 126
 127                                if (f & 1) {
 128                                        pval[0] = (*src32++ << 8) & mask;
 129                                        pval[1] = (*src32++ << 8) & mask;
 130                                } else {
 131                                        pval[0] = dst32[0] & mask;
 132                                        pval[1] = dst32[1] & mask;
 133                                }
 134
 135                                for (j = w; j > 0; j--) {
 136                                        v = *src32++;
 137                                        v1 = v & mask;
 138                                        *dst32++ = pval[0] | (v1 >> 8);
 139                                        pval[0] = (v ^ v1) << 8;
 140                                        v = *src32++;
 141                                        v1 = v & mask;
 142                                        *dst32++ = pval[1] | (v1 >> 8);
 143                                        pval[1] = (v ^ v1) << 8;
 144                                }
 145
 146                                if (f & 2) {
 147                                        dst32[0] = (dst32[0] & mask) | pval[0];
 148                                        dst32[1] = (dst32[1] & mask) | pval[1];
 149                                }
 150
 151                                src += next_line;
 152                                dst += next_line;
 153                        }
 154                } else {
 155                        u32 *src32, *dst32;
 156                        u32 pval[4], v, v1, mask;
 157                        int i, j, w, f;
 158
 159                        src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
 160                        dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
 161
 162                        mask = 0xff00ff;
 163                        f = 0;
 164                        w = width;
 165                        if ((dx + width) & 15)
 166                                f = 1;
 167                        if (sx & 15) {
 168                                f |= 2;
 169                                w += 8;
 170                        }
 171                        w >>= 4;
 172                        for (i = height; i; i--) {
 173                                src32 = (u32 *)src;
 174                                dst32 = (u32 *)dst;
 175
 176                                if (f & 1) {
 177                                        pval[0] = dst32[-1] & mask;
 178                                        pval[1] = dst32[-2] & mask;
 179                                } else {
 180                                        pval[0] = (*--src32 >> 8) & mask;
 181                                        pval[1] = (*--src32 >> 8) & mask;
 182                                }
 183
 184                                for (j = w; j > 0; j--) {
 185                                        v = *--src32;
 186                                        v1 = v & mask;
 187                                        *--dst32 = pval[0] | (v1 << 8);
 188                                        pval[0] = (v ^ v1) >> 8;
 189                                        v = *--src32;
 190                                        v1 = v & mask;
 191                                        *--dst32 = pval[1] | (v1 << 8);
 192                                        pval[1] = (v ^ v1) >> 8;
 193                                }
 194
 195                                if (!(f & 2)) {
 196                                        dst32[-1] = (dst32[-1] & mask) | pval[0];
 197                                        dst32[-2] = (dst32[-2] & mask) | pval[1];
 198                                }
 199
 200                                src -= next_line;
 201                                dst -= next_line;
 202                        }
 203                }
 204        }
 205}
 206
 207void atafb_iplan2p4_fillrect(struct fb_info *info, u_long next_line, u32 color,
 208                             int sy, int sx, int height, int width)
 209{
 210        u32 *dest;
 211        int rows, i;
 212        u32 cval[4];
 213
 214        dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
 215        if (sx & 15) {
 216                u8 *dest8 = (u8 *)dest + 1;
 217
 218                expand8_col2mask(color, cval);
 219
 220                for (i = height; i; i--) {
 221                        fill8_col(dest8, cval);
 222                        dest8 += next_line;
 223                }
 224                dest += BPL / 2;
 225                width -= 8;
 226        }
 227
 228        expand16_col2mask(color, cval);
 229        rows = width >> 4;
 230        if (rows) {
 231                u32 *d = dest;
 232                u32 off = next_line - rows * BPL * 2;
 233                for (i = height; i; i--) {
 234                        d = fill16_col(d, rows, cval);
 235                        d = (u32 *)((long)d + off);
 236                }
 237                dest += rows * BPL / 2;
 238                width &= 15;
 239        }
 240
 241        if (width) {
 242                u8 *dest8 = (u8 *)dest;
 243
 244                expand8_col2mask(color, cval);
 245
 246                for (i = height; i; i--) {
 247                        fill8_col(dest8, cval);
 248                        dest8 += next_line;
 249                }
 250        }
 251}
 252
 253void atafb_iplan2p4_linefill(struct fb_info *info, u_long next_line,
 254                             int dy, int dx, u32 width,
 255                             const u8 *data, u32 bgcolor, u32 fgcolor)
 256{
 257        u32 *dest;
 258        const u16 *data16;
 259        int rows;
 260        u32 fgm[4], bgm[4], m;
 261
 262        dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
 263        if (dx & 15) {
 264                fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
 265                dest += BPL / 2;
 266                width -= 8;
 267        }
 268
 269        if (width >= 16) {
 270                data16 = (const u16 *)data;
 271                expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
 272
 273                for (rows = width / 16; rows; rows--) {
 274                        u16 d = *data16++;
 275                        m = d | ((u32)d << 16);
 276                        *dest++ = (m & fgm[0]) ^ bgm[0];
 277                        *dest++ = (m & fgm[1]) ^ bgm[1];
 278                }
 279
 280                data = (const u8 *)data16;
 281                width &= 15;
 282        }
 283
 284        if (width)
 285                fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
 286}
 287
 288#ifdef MODULE
 289MODULE_LICENSE("GPL");
 290
 291int init_module(void)
 292{
 293        return 0;
 294}
 295
 296void cleanup_module(void)
 297{
 298}
 299#endif /* MODULE */
 300
 301
 302    /*
 303     *  Visible symbols for modules
 304     */
 305
 306EXPORT_SYMBOL(atafb_iplan2p4_copyarea);
 307EXPORT_SYMBOL(atafb_iplan2p4_fillrect);
 308EXPORT_SYMBOL(atafb_iplan2p4_linefill);
 309