Annotation of 43BSDReno/sys/hpdev/ite.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 University of Utah.
        !             3:  * Copyright (c) 1990 The Regents of the University of California.
        !             4:  * All rights reserved.
        !             5:  *
        !             6:  * This code is derived from software contributed to Berkeley by
        !             7:  * the Systems Programming Group of the University of Utah Computer
        !             8:  * Science Department.
        !             9:  *
        !            10:  * Redistribution is only permitted until one year after the first shipment
        !            11:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
        !            12:  * binary forms are permitted provided that: (1) source distributions retain
        !            13:  * this entire copyright notice and comment, and (2) distributions including
        !            14:  * binaries display the following acknowledgement:  This product includes
        !            15:  * software developed by the University of California, Berkeley and its
        !            16:  * contributors'' in the documentation or other materials provided with the
        !            17:  * distribution and in all advertising materials mentioning features or use
        !            18:  * of this software.  Neither the name of the University nor the names of
        !            19:  * its contributors may be used to endorse or promote products derived from
        !            20:  * this software without specific prior written permission.
        !            21:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            22:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            23:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            24:  *
        !            25:  * from: Utah $Hdr: ite.c 1.22 89/08/17$
        !            26:  *
        !            27:  *     @(#)ite.c       7.2 (Berkeley) 6/22/90
        !            28:  */
        !            29: 
        !            30: /*
        !            31:  * Bit-mapped display terminal emulator machine independent code.
        !            32:  * This is a very rudimentary.  Much more can be abstracted out of
        !            33:  * the hardware dependent routines.
        !            34:  */
        !            35: #include "ite.h"
        !            36: #if NITE > 0
        !            37: 
        !            38: #include "grf.h"
        !            39: 
        !            40: #undef NITE
        !            41: #define NITE   NGRF
        !            42: 
        !            43: #include "param.h"
        !            44: #include "conf.h"
        !            45: #include "user.h"
        !            46: #include "proc.h"
        !            47: #include "ioctl.h"
        !            48: #include "tty.h"
        !            49: #include "systm.h"
        !            50: #include "uio.h"
        !            51: #include "malloc.h"
        !            52: 
        !            53: #include "itevar.h"
        !            54: #include "iteioctl.h"
        !            55: #include "kbdmap.h"
        !            56: 
        !            57: #include "machine/cpu.h"
        !            58: 
        !            59: #define set_attr(ip, attr)     ((ip)->attribute |= (attr))
        !            60: #define clr_attr(ip, attr)     ((ip)->attribute &= ~(attr))
        !            61: 
        !            62: extern  int nodev();
        !            63: 
        !            64: int topcat_scroll(),   topcat_init(),          topcat_deinit();
        !            65: int topcat_clear(),    topcat_putc(),          topcat_cursor();
        !            66: int gatorbox_scroll(), gatorbox_init(),        gatorbox_deinit();
        !            67: int gatorbox_clear(),  gatorbox_putc(),        gatorbox_cursor();
        !            68: int rbox_scroll(),     rbox_init(),            rbox_deinit();
        !            69: int rbox_clear(),      rbox_putc(),            rbox_cursor();
        !            70: int dvbox_scroll(),    dvbox_init(),           dvbox_deinit();
        !            71: int dvbox_clear(),     dvbox_putc(),           dvbox_cursor();
        !            72: 
        !            73: struct itesw itesw[] =
        !            74: {
        !            75:        topcat_init,            topcat_deinit,          topcat_clear,
        !            76:        topcat_putc,            topcat_cursor,          topcat_scroll,
        !            77: 
        !            78:        gatorbox_init,          gatorbox_deinit,        gatorbox_clear,
        !            79:        gatorbox_putc,          gatorbox_cursor,        gatorbox_scroll,
        !            80: 
        !            81:        rbox_init,              rbox_deinit,            rbox_clear,
        !            82:        rbox_putc,              rbox_cursor,            rbox_scroll,
        !            83: 
        !            84:        dvbox_init,             dvbox_deinit,           dvbox_clear,
        !            85:        dvbox_putc,             dvbox_cursor,           dvbox_scroll,
        !            86: };
        !            87: 
        !            88: /*
        !            89:  * # of chars are output in a single itestart() call.
        !            90:  * If this is too big, user processes will be blocked out for
        !            91:  * long periods of time while we are emptying the queue in itestart().
        !            92:  * If it is too small, console output will be very ragged.
        !            93:  */
        !            94: int    iteburst = 64;
        !            95: 
        !            96: int    nite = NITE;
        !            97: struct  tty *kbd_tty = NULL;
        !            98: struct tty ite_tty[NITE];
        !            99: struct  ite_softc ite_softc[NITE];
        !           100: 
        !           101: int    itestart();
        !           102: extern int ttrstrt();
        !           103: extern struct tty *constty;
        !           104: 
        !           105: /*
        !           106:  * Primary attribute buffer to be used by the first bitmapped console
        !           107:  * found. Secondary displays alloc the attribute buffer as needed.
        !           108:  * Size is based on a 68x128 display, which is currently our largest.
        !           109:  */
        !           110: u_char  console_attributes[0x2200];
        !           111: 
        !           112: /*
        !           113:  * Perform functions necessary to setup device as a terminal emulator.
        !           114:  */
        !           115: iteon(dev, flag)
        !           116:        dev_t dev;
        !           117: {
        !           118:        int unit = UNIT(dev);
        !           119:        struct tty *tp = &ite_tty[unit];
        !           120:        struct ite_softc *ip = &ite_softc[unit];
        !           121: 
        !           122:        if (unit < 0 || unit >= NITE || (ip->flags&ITE_ALIVE) == 0)
        !           123:                return(ENXIO);
        !           124:        /* force ite active, overriding graphics mode */
        !           125:        if (flag & 1) {
        !           126:                ip->flags |= ITE_ACTIVE;
        !           127:                ip->flags &= ~(ITE_INGRF|ITE_INITED);
        !           128:        }
        !           129:        /* leave graphics mode */
        !           130:        if (flag & 2) {
        !           131:                ip->flags &= ~ITE_INGRF;
        !           132:                if ((ip->flags & ITE_ACTIVE) == 0)
        !           133:                        return(0);
        !           134:        }
        !           135:        ip->flags |= ITE_ACTIVE;
        !           136:        if (ip->flags & ITE_INGRF)
        !           137:                return(0);
        !           138:        if (kbd_tty == NULL || kbd_tty == tp) {
        !           139:                kbd_tty = tp;
        !           140:                kbdenable();
        !           141:        }
        !           142:        iteinit(dev);
        !           143:        return(0);
        !           144: }
        !           145: 
        !           146: iteinit(dev)
        !           147:      dev_t dev;
        !           148: {
        !           149:        int unit = UNIT(dev);
        !           150:        struct ite_softc *ip = &ite_softc[unit];
        !           151: 
        !           152:        if (ip->flags & ITE_INITED)
        !           153:                return;
        !           154:        
        !           155:        ip->curx = 0;
        !           156:        ip->cury = 0;
        !           157:        ip->cursorx = 0;
        !           158:        ip->cursory = 0;
        !           159: 
        !           160:        (*itesw[ip->type].ite_init)(ip);
        !           161:        (*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
        !           162: 
        !           163:        ip->attribute = 0;
        !           164:        if (ip->attrbuf == NULL)
        !           165:                ip->attrbuf = (u_char *)
        !           166:                        malloc(ip->rows * ip->cols, M_DEVBUF, M_WAITOK);
        !           167:        bzero(ip->attrbuf, (ip->rows * ip->cols));
        !           168: 
        !           169:        ip->imode = 0;
        !           170:        ip->flags |= ITE_INITED;
        !           171: }
        !           172: 
        !           173: /*
        !           174:  * "Shut down" device as terminal emulator.
        !           175:  * Note that we do not deinit the console device unless forced.
        !           176:  * Deinit'ing the console every time leads to a very active
        !           177:  * screen when processing /etc/rc.
        !           178:  */
        !           179: iteoff(dev, flag)
        !           180:        dev_t dev;
        !           181: {
        !           182:        register struct ite_softc *ip = &ite_softc[UNIT(dev)];
        !           183: 
        !           184:        if (flag & 2)
        !           185:                ip->flags |= ITE_INGRF;
        !           186:        if ((ip->flags & ITE_ACTIVE) == 0)
        !           187:                return;
        !           188:        if ((flag & 1) ||
        !           189:            (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
        !           190:                (*itesw[ip->type].ite_deinit)(ip);
        !           191:        if ((flag & 2) == 0)
        !           192:                ip->flags &= ~ITE_ACTIVE;
        !           193: }
        !           194: 
        !           195: /*ARGSUSED*/
        !           196: iteopen(dev, flag)
        !           197:        dev_t dev;
        !           198: {
        !           199:        int unit = UNIT(dev);
        !           200:        register struct tty *tp = &ite_tty[unit];
        !           201:        register struct ite_softc *ip = &ite_softc[unit];
        !           202:        register int error;
        !           203:        int first = 0;
        !           204: 
        !           205:        if ((tp->t_state&(TS_ISOPEN|TS_XCLUDE)) == (TS_ISOPEN|TS_XCLUDE)
        !           206:            && u.u_uid != 0)
        !           207:                return (EBUSY);
        !           208:        if ((ip->flags & ITE_ACTIVE) == 0) {
        !           209:                error = iteon(dev, 0);
        !           210:                if (error)
        !           211:                        return (error);
        !           212:                first = 1;
        !           213:        }
        !           214:        tp->t_oproc = itestart;
        !           215:        tp->t_param = NULL;
        !           216:        tp->t_dev = dev;
        !           217:        if ((tp->t_state&TS_ISOPEN) == 0) {
        !           218:                ttychars(tp);
        !           219:                tp->t_iflag = TTYDEF_IFLAG;
        !           220:                tp->t_oflag = TTYDEF_OFLAG;
        !           221:                tp->t_cflag = CS8|CREAD;
        !           222:                tp->t_lflag = TTYDEF_LFLAG;
        !           223:                tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
        !           224:                tp->t_state = TS_ISOPEN|TS_CARR_ON;
        !           225:                ttsetwater(tp);
        !           226:        }
        !           227:        error = (*linesw[tp->t_line].l_open)(dev, tp);
        !           228:        if (error == 0) {
        !           229:                tp->t_winsize.ws_row = ip->rows;
        !           230:                tp->t_winsize.ws_col = ip->cols;
        !           231:        } else if (first)
        !           232:                iteoff(dev, 0);
        !           233:        return (error);
        !           234: }
        !           235: 
        !           236: /*ARGSUSED*/
        !           237: iteclose(dev, flag)
        !           238:        dev_t dev;
        !           239: {
        !           240:        register struct tty *tp = &ite_tty[UNIT(dev)];
        !           241: 
        !           242:        (*linesw[tp->t_line].l_close)(tp);
        !           243:        ttyclose(tp);
        !           244:        iteoff(dev, 0);
        !           245:        return(0);
        !           246: }
        !           247: 
        !           248: iteread(dev, uio, flag)
        !           249:        dev_t dev;
        !           250:        struct uio *uio;
        !           251: {
        !           252:        register struct tty *tp = &ite_tty[UNIT(dev)];
        !           253: 
        !           254:        return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
        !           255: }
        !           256: 
        !           257: itewrite(dev, uio, flag)
        !           258:        dev_t dev;
        !           259:        struct uio *uio;
        !           260: {
        !           261:        int unit = UNIT(dev);
        !           262:        register struct tty *tp = &ite_tty[unit];
        !           263: 
        !           264:        if ((ite_softc[unit].flags & ITE_ISCONS) && constty &&
        !           265:            (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN))
        !           266:                tp = constty;
        !           267:        return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
        !           268: }
        !           269: 
        !           270: iteioctl(dev, cmd, addr, flag)
        !           271:        dev_t dev;
        !           272:        caddr_t addr;
        !           273: {
        !           274:        register struct tty *tp = &ite_tty[UNIT(dev)];
        !           275:        int error;
        !           276: 
        !           277:        error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag);
        !           278:        if (error >= 0)
        !           279:                return (error);
        !           280:        error = ttioctl(tp, cmd, addr, flag);
        !           281:        if (error >= 0)
        !           282:                return (error);
        !           283:        return (ENOTTY);
        !           284: }
        !           285: 
        !           286: itestart(tp)
        !           287:        register struct tty *tp;
        !           288: {
        !           289:        register int cc, s;
        !           290:        int hiwat = 0;
        !           291: 
        !           292:        s = spltty();
        !           293:        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
        !           294:                splx(s);
        !           295:                return;
        !           296:        }
        !           297:        tp->t_state |= TS_BUSY;
        !           298:        cc = tp->t_outq.c_cc;
        !           299:        if (cc <= tp->t_lowat) {
        !           300:                if (tp->t_state & TS_ASLEEP) {
        !           301:                        tp->t_state &= ~TS_ASLEEP;
        !           302:                        wakeup(&tp->t_outq);
        !           303:                }
        !           304:                if (tp->t_wsel) {
        !           305:                        selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
        !           306:                        tp->t_wsel = 0;
        !           307:                        tp->t_state &= ~TS_WCOLL;
        !           308:                }
        !           309:        }
        !           310:        /*
        !           311:         * Limit the amount of output we do in one burst
        !           312:         * to prevent hogging the CPU.
        !           313:         */
        !           314:        if (cc > iteburst) {
        !           315:                hiwat++;
        !           316:                cc = iteburst;
        !           317:        }
        !           318:        while (--cc >= 0) {
        !           319:                register int c;
        !           320: 
        !           321:                c = getc(&tp->t_outq);
        !           322:                /*
        !           323:                 * iteputchar() may take a long time and we don't want to
        !           324:                 * block all interrupts for long periods of time.  Since
        !           325:                 * there is no need to stay at high priority while outputing
        !           326:                 * the character (since we don't have to worry about
        !           327:                 * interrupts), we don't.  We just need to make sure that
        !           328:                 * we don't reenter iteputchar, which is guarenteed by the
        !           329:                 * earlier setting of TS_BUSY.
        !           330:                 */
        !           331:                splx(s);
        !           332:                iteputchar(c, tp->t_dev);
        !           333:                spltty();
        !           334:        }
        !           335:        if (hiwat) {
        !           336:                tp->t_state |= TS_TIMEOUT;
        !           337:                timeout(ttrstrt, tp, 1);
        !           338:        }
        !           339:        tp->t_state &= ~TS_BUSY;
        !           340:        splx(s);
        !           341: }
        !           342: 
        !           343: itefilter(stat, c)
        !           344:      register char stat, c;
        !           345: {
        !           346:        static int capsmode = 0;
        !           347:        static int metamode = 0;
        !           348:        register char code, *str;
        !           349: 
        !           350:        if (kbd_tty == NULL)
        !           351:                return;
        !           352: 
        !           353:        switch (c & 0xFF) {
        !           354:        case KBD_CAPSLOCK:
        !           355:                capsmode = !capsmode;
        !           356:                return;
        !           357: 
        !           358:        case KBD_EXT_LEFT_DOWN:
        !           359:        case KBD_EXT_RIGHT_DOWN:
        !           360:                metamode = 1;
        !           361:                return;
        !           362:                
        !           363:        case KBD_EXT_LEFT_UP:
        !           364:        case KBD_EXT_RIGHT_UP:
        !           365:                metamode = 0;
        !           366:                return;
        !           367:        }
        !           368: 
        !           369:        c &= KBD_CHARMASK;
        !           370:        switch ((stat>>KBD_SSHIFT) & KBD_SMASK) {
        !           371: 
        !           372:        case KBD_KEY:
        !           373:                if (!capsmode) {
        !           374:                        code = kbd_keymap[c];
        !           375:                        break;
        !           376:                }
        !           377:                /* fall into... */
        !           378: 
        !           379:        case KBD_SHIFT:
        !           380:                code = kbd_shiftmap[c];
        !           381:                break;
        !           382: 
        !           383:        case KBD_CTRL:
        !           384:                code = kbd_ctrlmap[c];
        !           385:                break;
        !           386:                
        !           387:        case KBD_CTRLSHIFT:     
        !           388:                code = kbd_ctrlshiftmap[c];
        !           389:                break;
        !           390:         }
        !           391: 
        !           392:        if (code == NULL && (str = kbd_stringmap[c]) != NULL) {
        !           393:                while (*str)
        !           394:                        (*linesw[kbd_tty->t_line].l_rint)(*str++, kbd_tty);
        !           395:        } else {
        !           396:                if (metamode)
        !           397:                        code |= 0x80;
        !           398:                (*linesw[kbd_tty->t_line].l_rint)(code, kbd_tty);
        !           399:        }
        !           400: }
        !           401: 
        !           402: iteputchar(c, dev)
        !           403:        register int c;
        !           404:        dev_t dev;  
        !           405: {
        !           406:        int unit = UNIT(dev);
        !           407:        register struct ite_softc *ip = &ite_softc[unit];
        !           408:        register struct itesw *sp = &itesw[ip->type];
        !           409:        register int n;
        !           410: 
        !           411:        if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
        !           412:                return;
        !           413: 
        !           414:        if (ip->escape) {
        !           415: doesc:
        !           416:                switch (ip->escape) {
        !           417: 
        !           418:                case '&':                       /* Next can be a,d, or s */
        !           419:                        if (ip->fpd++) {
        !           420:                                ip->escape = c;
        !           421:                                ip->fpd = 0;
        !           422:                        }
        !           423:                        return;
        !           424: 
        !           425:                case 'a':                               /* cursor change */
        !           426:                        switch (c) {
        !           427: 
        !           428:                        case 'Y':                       /* Only y coord. */
        !           429:                                ip->cury = MIN(ip->pos, ip->rows-1);
        !           430:                                ip->pos = 0;
        !           431:                                ip->escape = 0;
        !           432:                                (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           433:                                clr_attr(ip, ATTR_INV);
        !           434:                                break;
        !           435: 
        !           436:                        case 'y':                       /* y coord first */
        !           437:                                ip->cury = MIN(ip->pos, ip->rows-1);
        !           438:                                ip->pos = 0;
        !           439:                                ip->fpd = 0;
        !           440:                                break;
        !           441: 
        !           442:                        case 'C':                       /* x coord */
        !           443:                                ip->curx = MIN(ip->pos, ip->cols-1);
        !           444:                                ip->pos = 0;
        !           445:                                ip->escape = 0;
        !           446:                                (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           447:                                clr_attr(ip, ATTR_INV);
        !           448:                                break;
        !           449: 
        !           450:                        default:             /* Possibly a 3 digit number. */
        !           451:                                if (c >= '0' && c <= '9' && ip->fpd < 3) {
        !           452:                                        ip->pos = ip->pos * 10 + (c - '0');
        !           453:                                        ip->fpd++;
        !           454:                                } else {
        !           455:                                        ip->pos = 0;
        !           456:                                        ip->escape = 0;
        !           457:                                }
        !           458:                                break;
        !           459:                        }
        !           460:                        return;
        !           461: 
        !           462:                case 'd':                               /* attribute change */
        !           463:                        switch (c) {
        !           464: 
        !           465:                        case 'B':
        !           466:                                set_attr(ip, ATTR_INV);
        !           467:                                break;
        !           468:                        case 'D':
        !           469:                                /* XXX: we don't do anything for underline */
        !           470:                                set_attr(ip, ATTR_UL);
        !           471:                                break;
        !           472:                        case '@':
        !           473:                                clr_attr(ip, ATTR_ALL);
        !           474:                                break;
        !           475:                        }
        !           476:                        ip->escape = 0;
        !           477:                        return;
        !           478: 
        !           479:                case 's':                               /* keypad control */
        !           480:                        switch (ip->fpd) {
        !           481: 
        !           482:                        case 0:
        !           483:                                ip->hold = c;
        !           484:                                ip->fpd++;
        !           485:                                return;
        !           486: 
        !           487:                        case 1:
        !           488:                                if (c == 'A') {
        !           489:                                        switch (ip->hold) {
        !           490:        
        !           491:                                        case '0':
        !           492:                                                clr_attr(ip, ATTR_KPAD);
        !           493:                                                break;
        !           494:                                        case '1':
        !           495:                                                set_attr(ip, ATTR_KPAD);
        !           496:                                                break;
        !           497:                                        }
        !           498:                                }
        !           499:                                ip->hold = 0;
        !           500:                        }
        !           501:                        ip->escape = 0;
        !           502:                        return;
        !           503: 
        !           504:                case 'i':                       /* back tab */
        !           505:                        if (ip->curx > TABSIZE) {
        !           506:                                n = ip->curx - (ip->curx & (TABSIZE - 1));
        !           507:                                ip->curx -= n;
        !           508:                        } else
        !           509:                                ip->curx = 0;
        !           510:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           511:                        ip->escape = 0;
        !           512:                        return;
        !           513: 
        !           514:                case '3':                       /* clear all tabs */
        !           515:                        goto ignore;
        !           516: 
        !           517:                case 'K':                       /* clear_eol */
        !           518:                        ite_clrtoeol(ip, sp, ip->cury, ip->curx);
        !           519:                        ip->escape = 0;
        !           520:                        return;
        !           521: 
        !           522:                case 'J':                       /* clear_eos */
        !           523:                        ite_clrtoeos(ip, sp);
        !           524:                        ip->escape = 0;
        !           525:                        return;
        !           526: 
        !           527:                case 'B':                       /* cursor down 1 line */
        !           528:                        if (++ip->cury == ip->rows) {
        !           529:                                --ip->cury;
        !           530:                                (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
        !           531:                                ite_clrtoeol(ip, sp, ip->cury, 0);
        !           532:                        }
        !           533:                        else
        !           534:                                (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           535:                        clr_attr(ip, ATTR_INV);
        !           536:                        ip->escape = 0;
        !           537:                        return;
        !           538: 
        !           539:                case 'C':                       /* cursor forward 1 char */
        !           540:                        ip->escape = 0;
        !           541:                        itecheckwrap(ip, sp);
        !           542:                        return;
        !           543: 
        !           544:                case 'A':                       /* cursor up 1 line */
        !           545:                        if (ip->cury > 0) {
        !           546:                                ip->cury--;
        !           547:                                (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           548:                        }
        !           549:                        ip->escape = 0;
        !           550:                        clr_attr(ip, ATTR_INV);
        !           551:                        return;
        !           552: 
        !           553:                case 'P':                       /* delete character */
        !           554:                        ite_dchar(ip, sp);
        !           555:                        ip->escape = 0;
        !           556:                        return;
        !           557: 
        !           558:                case 'M':                       /* delete line */
        !           559:                        ite_dline(ip, sp);
        !           560:                        ip->escape = 0;
        !           561:                        return;
        !           562: 
        !           563:                case 'Q':                       /* enter insert mode */
        !           564:                        ip->imode = 1;
        !           565:                        ip->escape = 0;
        !           566:                        return;
        !           567: 
        !           568:                case 'R':                       /* exit insert mode */
        !           569:                        ip->imode = 0;
        !           570:                        ip->escape = 0;
        !           571:                        return;
        !           572: 
        !           573:                case 'L':                       /* insert blank line */
        !           574:                        ite_iline(ip, sp);
        !           575:                        ip->escape = 0;
        !           576:                        return;
        !           577: 
        !           578:                case 'h':                       /* home key */
        !           579:                        ip->cury = ip->curx = 0;
        !           580:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           581:                        ip->escape = 0;
        !           582:                        return;
        !           583: 
        !           584:                case 'D':                       /* left arrow key */
        !           585:                        if (ip->curx > 0) {
        !           586:                                ip->curx--;
        !           587:                                (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           588:                        }
        !           589:                        ip->escape = 0;
        !           590:                        return;
        !           591: 
        !           592:                case '1':                       /* set tab in all rows */
        !           593:                        goto ignore;
        !           594: 
        !           595:                case ESC:
        !           596:                        if ((ip->escape = c) == ESC)
        !           597:                                break;
        !           598:                        ip->fpd = 0;
        !           599:                        goto doesc;
        !           600: 
        !           601:                default:
        !           602: ignore:
        !           603:                        ip->escape = 0;
        !           604:                        return;
        !           605: 
        !           606:                }
        !           607:        }
        !           608: 
        !           609:        switch (c &= 0x7F) {
        !           610: 
        !           611:        case '\n':
        !           612: 
        !           613:                if (++ip->cury == ip->rows) {
        !           614:                        --ip->cury;
        !           615:                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
        !           616:                        ite_clrtoeol(ip, sp, ip->cury, 0);
        !           617:                }
        !           618:                else
        !           619:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           620:                clr_attr(ip, ATTR_INV);
        !           621:                break;
        !           622: 
        !           623:        case '\r':
        !           624:                if (ip->curx) {
        !           625:                        ip->curx = 0;
        !           626:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           627:                }
        !           628:                break;
        !           629:        
        !           630:        case '\b':
        !           631:                if (--ip->curx < 0)
        !           632:                        ip->curx = 0;
        !           633:                else
        !           634:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           635:                break;
        !           636: 
        !           637:        case '\t':
        !           638:                if (ip->curx < TABEND(unit)) {
        !           639:                        n = TABSIZE - (ip->curx & (TABSIZE - 1));
        !           640:                        ip->curx += n;
        !           641:                        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           642:                } else
        !           643:                        itecheckwrap(ip, sp);
        !           644:                break;
        !           645: 
        !           646:        case CTRL('G'):
        !           647:                if (&ite_tty[unit] == kbd_tty)
        !           648:                        kbdbell();
        !           649:                break;
        !           650: 
        !           651:        case ESC:
        !           652:                ip->escape = ESC;
        !           653:                break;
        !           654: 
        !           655:        default:
        !           656:                if (c < ' ' || c == DEL)
        !           657:                        break;
        !           658:                if (ip->imode)
        !           659:                        ite_ichar(ip, sp);
        !           660:                if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
        !           661:                        attrset(ip, ATTR_INV);
        !           662:                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_INV);
        !           663:                }                       
        !           664:                else
        !           665:                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
        !           666:                (*sp->ite_cursor)(ip, DRAW_CURSOR);
        !           667:                itecheckwrap(ip, sp);
        !           668:                break;
        !           669:        }
        !           670: }
        !           671: 
        !           672: itecheckwrap(ip, sp)
        !           673:      register struct ite_softc *ip;
        !           674:      register struct itesw *sp;
        !           675: {
        !           676:        if (++ip->curx == ip->cols) {
        !           677:                ip->curx = 0;
        !           678:                clr_attr(ip, ATTR_INV);
        !           679:                if (++ip->cury == ip->rows) {
        !           680:                        --ip->cury;
        !           681:                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
        !           682:                        ite_clrtoeol(ip, sp, ip->cury, 0);
        !           683:                        return;
        !           684:                }
        !           685:        }
        !           686:        (*sp->ite_cursor)(ip, MOVE_CURSOR);
        !           687: }
        !           688: 
        !           689: ite_dchar(ip, sp)
        !           690:      register struct ite_softc *ip;
        !           691:      register struct itesw *sp;
        !           692: {
        !           693:        (*sp->ite_scroll)(ip, ip->cury, ip->curx + 1, 1, SCROLL_LEFT);
        !           694:        attrmov(ip, ip->cury, ip->curx + 1, ip->cury, ip->curx,
        !           695:                1, ip->cols - ip->curx - 1);
        !           696:        attrclr(ip, ip->cury, ip->cols - 1, 1, 1);
        !           697:        (*sp->ite_putc)(ip, ' ', ip->cury, ip->cols - 1, ATTR_NOR);
        !           698:        (*sp->ite_cursor)(ip, DRAW_CURSOR);
        !           699: }
        !           700: 
        !           701: ite_ichar(ip, sp)
        !           702:      register struct ite_softc *ip;
        !           703:      register struct itesw *sp;
        !           704: {
        !           705:        (*sp->ite_scroll)(ip, ip->cury, ip->curx, 1, SCROLL_RIGHT);
        !           706:        attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + 1,
        !           707:                1, ip->cols - ip->curx - 1);
        !           708:        attrclr(ip, ip->cury, ip->curx, 1, 1);
        !           709:        (*sp->ite_putc)(ip, ' ', ip->cury, ip->curx, ATTR_NOR);
        !           710:        (*sp->ite_cursor)(ip, DRAW_CURSOR);
        !           711: }
        !           712: 
        !           713: ite_dline(ip, sp)
        !           714:      register struct ite_softc *ip;
        !           715:      register struct itesw *sp;
        !           716: {
        !           717:        (*sp->ite_scroll)(ip, ip->cury + 1, 0, 1, SCROLL_UP);
        !           718:        attrmov(ip, ip->cury + 1, 0, ip->cury, 0,
        !           719:                ip->rows - ip->cury - 1, ip->cols);
        !           720:        ite_clrtoeol(ip, sp, ip->rows - 1, 0);
        !           721: }
        !           722: 
        !           723: ite_iline(ip, sp)
        !           724:      register struct ite_softc *ip;
        !           725:      register struct itesw *sp;
        !           726: {
        !           727:        (*sp->ite_scroll)(ip, ip->cury, 0, 1, SCROLL_DOWN);
        !           728:        attrmov(ip, ip->cury, 0, ip->cury + 1, 0,
        !           729:                ip->rows - ip->cury - 1, ip->cols);
        !           730:        ite_clrtoeol(ip, sp, ip->cury, 0);
        !           731: }
        !           732: 
        !           733: ite_clrtoeol(ip, sp, y, x)
        !           734:      register struct ite_softc *ip;
        !           735:      register struct itesw *sp;
        !           736:      register int y, x;
        !           737: {
        !           738:        (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
        !           739:        attrclr(ip, y, x, 1, ip->cols - x);
        !           740:        (*sp->ite_cursor)(ip, DRAW_CURSOR);
        !           741: }
        !           742: 
        !           743: ite_clrtoeos(ip, sp)
        !           744:      register struct ite_softc *ip;
        !           745:      register struct itesw *sp;
        !           746: {
        !           747:        (*sp->ite_clear)(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
        !           748:        attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
        !           749:        (*sp->ite_cursor)(ip, DRAW_CURSOR);
        !           750: }
        !           751: 
        !           752: /*
        !           753:  * Console functions
        !           754:  */
        !           755: #include "machine/cons.h"
        !           756: #include "grfioctl.h"
        !           757: #include "grfvar.h"
        !           758: 
        !           759: #ifdef DEBUG
        !           760: /*
        !           761:  * Minimum ITE number at which to start looking for a console.
        !           762:  * Setting to 0 will do normal search, 1 will skip first ITE device,
        !           763:  * NITE will skip ITEs and use serial port.
        !           764:  */
        !           765: int    whichconsole = 0;
        !           766: #endif
        !           767: 
        !           768: itecnprobe(cp)
        !           769:        struct consdev *cp;
        !           770: {
        !           771:        register struct ite_softc *ip;
        !           772:        int i, maj, unit, pri;
        !           773:        extern int iteopen();
        !           774: 
        !           775:        /* locate the major number */
        !           776:        for (maj = 0; maj < nchrdev; maj++)
        !           777:                if (cdevsw[maj].d_open == iteopen)
        !           778:                        break;
        !           779: 
        !           780:        /* urk! */
        !           781:        grfconfig();
        !           782: 
        !           783:        /* check all the individual displays and find the best */
        !           784:        unit = -1;
        !           785:        pri = CN_DEAD;
        !           786:        for (i = 0; i < NITE; i++) {
        !           787:                struct grf_softc *gp = &grf_softc[i];
        !           788: 
        !           789:                ip = &ite_softc[i];
        !           790:                if ((gp->g_flags & GF_ALIVE) == 0)
        !           791:                        continue;
        !           792:                ip->flags = (ITE_ALIVE|ITE_CONSOLE);
        !           793: 
        !           794:                /* XXX - we need to do something about mapping these */
        !           795:                switch (gp->g_type) {
        !           796: 
        !           797:                case GT_TOPCAT:
        !           798:                case GT_LRCATSEYE:
        !           799:                case GT_HRCCATSEYE:
        !           800:                case GT_HRMCATSEYE:
        !           801:                        ip->type = ITE_TOPCAT;
        !           802:                        break;
        !           803:                case GT_GATORBOX:
        !           804:                        ip->type = ITE_GATORBOX;
        !           805:                        break;
        !           806:                case GT_RENAISSANCE:
        !           807:                        ip->type = ITE_RENAISSANCE;
        !           808:                        break;
        !           809:                case GT_DAVINCI:
        !           810:                        ip->type = ITE_DAVINCI;
        !           811:                        break;
        !           812:                }
        !           813: #ifdef DEBUG
        !           814:                if (i < whichconsole)
        !           815:                        continue;
        !           816: #endif
        !           817:                if ((int)gp->g_display.gd_regaddr == GRFIADDR) {
        !           818:                        pri = CN_INTERNAL;
        !           819:                        unit = i;
        !           820:                } else if (unit < 0) {
        !           821:                        pri = CN_NORMAL;
        !           822:                        unit = i;
        !           823:                }
        !           824:        }
        !           825: 
        !           826:        /* initialize required fields */
        !           827:        cp->cn_dev = makedev(maj, unit);
        !           828:        cp->cn_tp = &ite_tty[unit];
        !           829:        cp->cn_pri = pri;
        !           830: }
        !           831: 
        !           832: itecninit(cp)
        !           833:        struct consdev *cp;
        !           834: {
        !           835:        int unit = UNIT(cp->cn_dev);
        !           836:        struct ite_softc *ip = &ite_softc[unit];
        !           837: 
        !           838:        ip->attrbuf = console_attributes;
        !           839:        iteinit(cp->cn_dev);
        !           840:        ip->flags |= (ITE_ACTIVE|ITE_ISCONS);
        !           841:        kbd_tty = &ite_tty[unit];
        !           842: }
        !           843: 
        !           844: /*ARGSUSED*/
        !           845: itecngetc(dev)
        !           846:        dev_t dev;
        !           847: {
        !           848:        register int c;
        !           849:        int stat;
        !           850: 
        !           851:        c = kbdgetc(&stat);
        !           852:        switch ((stat >> KBD_SSHIFT) & KBD_SMASK) {
        !           853:        case KBD_SHIFT:
        !           854:                c = kbd_shiftmap[c & KBD_CHARMASK];
        !           855:                break;
        !           856:        case KBD_CTRL:
        !           857:                c = kbd_ctrlmap[c & KBD_CHARMASK];
        !           858:                break;
        !           859:        case KBD_KEY:
        !           860:                c = kbd_keymap[c & KBD_CHARMASK];
        !           861:                break;
        !           862:        default:
        !           863:                c = 0;
        !           864:                break;
        !           865:        }
        !           866:        return(c);
        !           867: }
        !           868: 
        !           869: itecnputc(dev, c)
        !           870:        dev_t dev;
        !           871:        int c;
        !           872: {
        !           873:        static int paniced = 0;
        !           874:        struct ite_softc *ip = &ite_softc[UNIT(dev)];
        !           875:        extern char *panicstr;
        !           876: 
        !           877:        if (panicstr && !paniced &&
        !           878:            (ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) {
        !           879:                (void) iteon(dev, 3);
        !           880:                paniced = 1;
        !           881:        }
        !           882:        iteputchar(c, dev);
        !           883: }
        !           884: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.