[BACK]Return to omrasops.c CVS log [TXT][DIR] Up to [local] / sys / arch / luna88k / dev

Annotation of sys/arch/luna88k/dev/omrasops.c, Revision 1.1.1.1

1.1       nbrk        1: /* $OpenBSD: omrasops.c,v 1.4 2006/11/29 19:08:22 miod Exp $ */
                      2: /* $NetBSD: omrasops.c,v 1.1 2000/01/05 08:48:56 nisimura Exp $ */
                      3:
                      4: /*-
                      5:  * Copyright (c) 2000 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Tohru Nishimura.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the NetBSD
                     22:  *     Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: /*
                     41:  * Designed speficically for 'm68k bitorder';
                     42:  *     - most significant byte is stored at lower address,
                     43:  *     - most significant bit is displayed at left most on screen.
                     44:  * Implementation relies on;
                     45:  *     - every memory references is done in aligned 32bit chunk,
                     46:  *     - font glyphs are stored in 32bit padded.
                     47:  */
                     48:
                     49: #include <sys/param.h>
                     50: #include <sys/systm.h>
                     51: #include <sys/device.h>
                     52:
                     53: #include <dev/wscons/wsconsio.h>
                     54: #include <dev/wscons/wsdisplayvar.h>
                     55: #include <dev/rasops/rasops.h>
                     56:
                     57: /* wscons emulator operations */
                     58: void   om_cursor(void *, int, int, int);
                     59: void   om_putchar(void *, int, int, u_int, long);
                     60: void   om_copycols(void *, int, int, int, int);
                     61: void   om_copyrows(void *, int, int, int num);
                     62: void   om_erasecols(void *, int, int, int, long);
                     63: void   om_eraserows(void *, int, int, long);
                     64:
                     65: #define        ALL1BITS        (~0U)
                     66: #define        ALL0BITS        (0U)
                     67: #define        BLITWIDTH       (32)
                     68: #define        ALIGNMASK       (0x1f)
                     69: #define        BYTESDONE       (4)
                     70:
                     71: #define        W(p) (*(u_int32_t *)(p))
                     72: #define        R(p) (*(u_int32_t *)((caddr_t)(p) + 0x40000))
                     73:
                     74: /*
                     75:  * Blit a character at the specified co-ordinates.
                     76:  */
                     77: void
                     78: om_putchar(cookie, row, startcol, uc, attr)
                     79:        void *cookie;
                     80:        int row, startcol;
                     81:        u_int uc;
                     82:        long attr;
                     83: {
                     84:        struct rasops_info *ri = cookie;
                     85:        caddr_t p;
                     86:        int scanspan, startx, height, width, align, y;
                     87:        u_int32_t lmask, rmask, glyph, inverse;
                     88:        int i, fg, bg;
                     89:        u_int8_t *fb;
                     90:
                     91:        scanspan = ri->ri_stride;
                     92:        y = ri->ri_font->fontheight * row;
                     93:        startx = ri->ri_font->fontwidth * startcol;
                     94:        height = ri->ri_font->fontheight;
                     95:        fb = ri->ri_font->data +
                     96:            (uc - ri->ri_font->firstchar) * ri->ri_fontscale;
                     97:        ri->ri_ops.unpack_attr(cookie, attr, &fg, &bg, NULL);
                     98:        inverse = (bg != 0) ? ALL1BITS : ALL0BITS;
                     99:
                    100:        p = (caddr_t)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
                    101:        align = startx & ALIGNMASK;
                    102:        width = ri->ri_font->fontwidth + align;
                    103:        lmask = ALL1BITS >> align;
                    104:        rmask = ALL1BITS << (-width & ALIGNMASK);
                    105:        if (width <= BLITWIDTH) {
                    106:                lmask &= rmask;
                    107:                while (height > 0) {
                    108:                        glyph = 0;
                    109:                        for (i = ri->ri_font->stride; i != 0; i--)
                    110:                                glyph = (glyph << 8) | *fb++;
                    111:                        glyph <<= (4 - ri->ri_font->stride) * NBBY;
                    112:                        glyph = (glyph >> align) ^ inverse;
                    113:                        W(p) = (R(p) & ~lmask) | (glyph & lmask);
                    114:                        p += scanspan;
                    115:                        height--;
                    116:                }
                    117:        }
                    118:        else {
                    119:                caddr_t q = p;
                    120:                u_int32_t lhalf, rhalf;
                    121:
                    122:                while (height > 0) {
                    123:                        glyph = 0;
                    124:                        for (i = ri->ri_font->stride; i != 0; i--)
                    125:                                glyph = (glyph << 8) | *fb++;
                    126:                        glyph <<= (4 - ri->ri_font->stride) * NBBY;
                    127:                        lhalf = (glyph >> align) ^ inverse;
                    128:                        W(p) = (R(p) & ~lmask) | (lhalf & lmask);
                    129:                        p += BYTESDONE;
                    130:                        rhalf = (glyph << (BLITWIDTH - align)) ^ inverse;
                    131:                        W(p) = (rhalf & rmask) | (R(p) & ~rmask);
                    132:
                    133:                        p = (q += scanspan);
                    134:                        height--;
                    135:                }
                    136:        }
                    137: }
                    138:
                    139: void
                    140: om_erasecols(cookie, row, startcol, ncols, attr)
                    141:        void *cookie;
                    142:        int row, startcol, ncols;
                    143:        long attr;
                    144: {
                    145:         struct rasops_info *ri = cookie;
                    146:         caddr_t p;
                    147:         int scanspan, startx, height, width, align, w, y;
                    148:         u_int32_t lmask, rmask, fill;
                    149:
                    150:         scanspan = ri->ri_stride;
                    151:         y = ri->ri_font->fontheight * row;
                    152:         startx = ri->ri_font->fontwidth * startcol;
                    153:         height = ri->ri_font->fontheight;
                    154:         w = ri->ri_font->fontwidth * ncols;
                    155:        fill = (attr != 0) ? ALL1BITS : ALL0BITS;
                    156:
                    157:        p = (caddr_t)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
                    158:        align = startx & ALIGNMASK;
                    159:        width = w + align;
                    160:        lmask = ALL1BITS >> align;
                    161:        rmask = ALL1BITS << (-width & ALIGNMASK);
                    162:        if (width <= BLITWIDTH) {
                    163:                lmask &= rmask;
                    164:                fill &= lmask;
                    165:                while (height > 0) {
                    166:                        W(p) = (R(p) & ~lmask) | fill;
                    167:                        p += scanspan;
                    168:                        height--;
                    169:                }
                    170:        }
                    171:        else {
                    172:                caddr_t q = p;
                    173:                while (height > 0) {
                    174:                        W(p) = (R(p) & ~lmask) | (fill & lmask);
                    175:                        width -= 2 * BLITWIDTH;
                    176:                        while (width > 0) {
                    177:                                p += BYTESDONE;
                    178:                                W(p) = fill;
                    179:                                width -= BLITWIDTH;
                    180:                        }
                    181:                        p += BYTESDONE;
                    182:                        W(p) = (fill & rmask) | (R(p) & ~rmask);
                    183:
                    184:                        p = (q += scanspan);
                    185:                        width = w + align;
                    186:                        height--;
                    187:                }
                    188:        }
                    189: }
                    190:
                    191: void
                    192: om_eraserows(cookie, startrow, nrows, attr)
                    193:        void *cookie;
                    194:        int startrow, nrows;
                    195:        long attr;
                    196: {
                    197:        struct rasops_info *ri = cookie;
                    198:        caddr_t p, q;
                    199:        int scanspan, starty, height, width, w;
                    200:        u_int32_t rmask, fill;
                    201:
                    202:        scanspan = ri->ri_stride;
                    203:        starty = ri->ri_font->fontheight * startrow;
                    204:        height = ri->ri_font->fontheight * nrows;
                    205:        w = ri->ri_emuwidth;
                    206:        fill = (attr == 1) ? ALL1BITS : ALL0BITS;
                    207:
                    208:        p = (caddr_t)ri->ri_bits + starty * scanspan;
                    209:        width = w;
                    210:         rmask = ALL1BITS << (-width & ALIGNMASK);
                    211:        q = p;
                    212:        while (height > 0) {
                    213:                W(p) = fill;                            /* always aligned */
                    214:                width -= 2 * BLITWIDTH;
                    215:                while (width > 0) {
                    216:                        p += BYTESDONE;
                    217:                        W(p) = fill;
                    218:                        width -= BLITWIDTH;
                    219:                }
                    220:                p += BYTESDONE;
                    221:                W(p) = (fill & rmask) | (R(p) & ~rmask);
                    222:                p = (q += scanspan);
                    223:                width = w;
                    224:                height--;
                    225:        }
                    226: }
                    227:
                    228: void
                    229: om_copyrows(cookie, srcrow, dstrow, nrows)
                    230:        void *cookie;
                    231:        int srcrow, dstrow, nrows;
                    232: {
                    233:         struct rasops_info *ri = cookie;
                    234:         caddr_t p, q;
                    235:        int scanspan, offset, srcy, height, width, w;
                    236:         u_int32_t rmask;
                    237:
                    238:        scanspan = ri->ri_stride;
                    239:        height = ri->ri_font->fontheight * nrows;
                    240:        offset = (dstrow - srcrow) * scanspan * ri->ri_font->fontheight;
                    241:        srcy = ri->ri_font->fontheight * srcrow;
                    242:        if (srcrow < dstrow && srcrow + nrows > dstrow) {
                    243:                scanspan = -scanspan;
                    244:                srcy += height;
                    245:        }
                    246:
                    247:        p = (caddr_t)ri->ri_bits + srcy * ri->ri_stride;
                    248:        w = ri->ri_emuwidth;
                    249:        width = w;
                    250:        rmask = ALL1BITS << (-width & ALIGNMASK);
                    251:        q = p;
                    252:        while (height > 0) {
                    253:                W(p + offset) = R(p);                   /* always aligned */
                    254:                width -= 2 * BLITWIDTH;
                    255:                while (width > 0) {
                    256:                        p += BYTESDONE;
                    257:                        W(p + offset) = R(p);
                    258:                        width -= BLITWIDTH;
                    259:                }
                    260:                p += BYTESDONE;
                    261:                W(p + offset) = (R(p) & rmask) | (R(p + offset) & ~rmask);
                    262:
                    263:                p = (q += scanspan);
                    264:                width = w;
                    265:                height--;
                    266:        }
                    267: }
                    268:
                    269: void
                    270: om_copycols(cookie, startrow, srccol, dstcol, ncols)
                    271:        void *cookie;
                    272:        int startrow, srccol, dstcol, ncols;
                    273: {
                    274:        struct rasops_info *ri = cookie;
                    275:        caddr_t sp, dp, basep;
                    276:        int scanspan, height, width, align, shift, w, y, srcx, dstx;
                    277:        u_int32_t lmask, rmask;
                    278:
                    279:        scanspan = ri->ri_stride;
                    280:        y = ri->ri_font->fontheight * startrow;
                    281:        srcx = ri->ri_font->fontwidth * srccol;
                    282:        dstx = ri->ri_font->fontwidth * dstcol;
                    283:        height = ri->ri_font->fontheight;
                    284:        w = ri->ri_font->fontwidth * ncols;
                    285:        basep = (caddr_t)ri->ri_bits + y * scanspan;
                    286:
                    287:        align = shift = srcx & ALIGNMASK;
                    288:        width = w + align;
                    289:        align = dstx & ALIGNMASK;
                    290:        lmask = ALL1BITS >> align;
                    291:        rmask = ALL1BITS << (-(w + align) & ALIGNMASK);
                    292:        shift = align - shift;
                    293:        sp = basep + (srcx / 32) * 4;
                    294:        dp = basep + (dstx / 32) * 4;
                    295:
                    296:        if (shift != 0)
                    297:                goto hardluckalignment;
                    298:
                    299:        /* alignments comfortably match */
                    300:        if (width <= BLITWIDTH) {
                    301:                lmask &= rmask;
                    302:                while (height > 0) {
                    303:                        W(dp) = (R(dp) & ~lmask) | (R(sp) & lmask);
                    304:                        dp += scanspan;
                    305:                        sp += scanspan;
                    306:                        height--;
                    307:                }
                    308:        }
                    309:        /* copy forward (left-to-right) */
                    310:        else if (dstcol < srccol || srccol + ncols < dstcol) {
                    311:                caddr_t sq = sp, dq = dp;
                    312:
                    313:                w = width;
                    314:                while (height > 0) {
                    315:                        W(dp) = (R(dp) & ~lmask) | (R(sp) & lmask);
                    316:                        width -= 2 * BLITWIDTH;
                    317:                        while (width > 0) {
                    318:                                sp += BYTESDONE;
                    319:                                dp += BYTESDONE;
                    320:                                W(dp) = R(sp);
                    321:                                width -= BLITWIDTH;
                    322:                        }
                    323:                        sp += BYTESDONE;
                    324:                        dp += BYTESDONE;
                    325:                        W(dp) = (R(sp) & rmask) | (R(dp) & ~rmask);
                    326:                        sp = (sq += scanspan);
                    327:                        dp = (dq += scanspan);
                    328:                        width = w;
                    329:                        height--;
                    330:                }
                    331:        }
                    332:        /* copy backward (right-to-left) */
                    333:        else {
                    334:                caddr_t sq, dq;
                    335:
                    336:                sq = (sp += width / 32 * 4);
                    337:                dq = (dp += width / 32 * 4);
                    338:                w = width;
                    339:                while (height > 0) {
                    340:                        W(dp) = (R(sp) & rmask) | (R(dp) & ~rmask);
                    341:                        width -= 2 * BLITWIDTH;
                    342:                        while (width > 0) {
                    343:                                sp -= BYTESDONE;
                    344:                                dp -= BYTESDONE;
                    345:                                W(dp) = R(sp);
                    346:                                width -= BLITWIDTH;
                    347:                        }
                    348:                        sp -= BYTESDONE;
                    349:                        dp -= BYTESDONE;
                    350:                        W(dp) = (R(dp) & ~lmask) | (R(sp) & lmask);
                    351:
                    352:                        sp = (sq += scanspan);
                    353:                        dp = (dq += scanspan);
                    354:                        width = w;
                    355:                        height--;
                    356:                }
                    357:        }
                    358:        return;
                    359:
                    360:     hardluckalignment:
                    361:        /* alignments painfully disagree */
                    362: }
                    363:
                    364: /*
                    365:  * Position|{enable|disable} the cursor at the specified location.
                    366:  */
                    367: void
                    368: om_cursor(cookie, on, row, col)
                    369:        void *cookie;
                    370:        int on, row, col;
                    371: {
                    372:        struct rasops_info *ri = cookie;
                    373:        caddr_t p;
                    374:        int scanspan, startx, height, width, align, y;
                    375:        u_int32_t lmask, rmask, image;
                    376:
                    377:        if (!on) {
                    378:                /* make sure it's on */
                    379:                if ((ri->ri_flg & RI_CURSOR) == 0)
                    380:                        return;
                    381:
                    382:                row = ri->ri_crow;
                    383:                col = ri->ri_ccol;
                    384:        } else {
                    385:                /* unpaint the old copy. */
                    386:                ri->ri_crow = row;
                    387:                ri->ri_ccol = col;
                    388:        }
                    389:
                    390:        scanspan = ri->ri_stride;
                    391:        y = ri->ri_font->fontheight * row;
                    392:        startx = ri->ri_font->fontwidth * col;
                    393:        height = ri->ri_font->fontheight;
                    394:
                    395:        p = (caddr_t)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
                    396:        align = startx & ALIGNMASK;
                    397:        width = ri->ri_font->fontwidth + align;
                    398:        lmask = ALL1BITS >> align;
                    399:        rmask = ALL1BITS << (-width & ALIGNMASK);
                    400:        if (width <= BLITWIDTH) {
                    401:                lmask &= rmask;
                    402:                while (height > 0) {
                    403:                        image = R(p);
                    404:                        W(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
                    405:                        p += scanspan;
                    406:                        height--;
                    407:                }
                    408:        }
                    409:        else {
                    410:                caddr_t q = p;
                    411:
                    412:                while (height > 0) {
                    413:                        image = R(p);
                    414:                        W(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
                    415:                        p += BYTESDONE;
                    416:                        image = R(p);
                    417:                        W(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
                    418:
                    419:                        p = (q += scanspan);
                    420:                        height--;
                    421:                }
                    422:        }
                    423:        ri->ri_flg ^= RI_CURSOR;
                    424: }

CVSweb