Annotation of coherent/d/PS2_KERNEL/io.386/kb.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Keyboard/display driver.
                      3:  * Coherent, IBM PC/XT/AT.
                      4:  */
                      5: #include <sys/coherent.h>
                      6: #ifdef _I386
                      7: #include <sys/reg.h>
                      8: #else
                      9: #include <sys/i8086.h>
                     10: #endif
                     11: #include <sys/con.h>
                     12: #include <sys/devices.h>
                     13: #include <errno.h>
                     14: #include <sys/stat.h>
                     15: #include <sys/tty.h>
                     16: #include <signal.h>
                     17: #include <sys/sched.h>
                     18: #include <sys/silo.h>
                     19: 
                     20: #define        SPC     0376                    /* Special encoding */
                     21: #define XXX    0377                    /* Non-character */
                     22: #define        KBDATA  0x60                    /* Keyboard data */
                     23: #define        KBCTRL  0x61                    /* Keyboard control */
                     24: #define        KBFLAG  0x80                    /* Keyboard reset flag */
                     25: #define        LEDCMD  0xED                    /* status indicator command */
                     26: #define        KBACK   0xFA                    /* status indicator acknowledge */
                     27: #define        EXTENDED1 0xE1                  /* extended key seq initiator */
                     28: 
                     29: #define        KEYUP   0x80                    /* Key up change */
                     30: #define        KEYSC   0x7F                    /* Key scan code mask */
                     31: #define        LSHIFT  0x2A-1                  /* Left shift key */
                     32: #define LSHIFTA 0x2B-1                 /* Alternate left-shift key */
                     33: #define        RSHIFT  0x36-1                  /* Right shift key */
                     34: #define        CTRL    0x1D-1                  /* Control key */
                     35: /*-- #define   CAPLOCK 0x1D-1  --*/            /* Control key */
                     36: #define        ALT     0x38-1                  /* Alt key */
                     37: #define        CAPLOCK 0x3A-1                  /* Caps lock key */
                     38: /*-- #define   CTRL    0x3A-1  --*/            /* Caps lock key */
                     39: #define        NUMLOCK 0x45-1                  /* Numeric lock key */
                     40: #define        DELETE  0x53-1                  /* Del, as in CTRL-ALT-DEL */
                     41: #define BACKSP 0x0E-1                  /* Back space */
                     42: #define SCRLOCK        0x46-1                  /* Scroll lock */
                     43: 
                     44: /* Shift flags */
                     45: #define        SRS     0x01                    /* Right shift key on */
                     46: #define        SLS     0x02                    /* Left shift key on */
                     47: #define CTS    0x04                    /* Ctrl key on */
                     48: #define ALS    0x08                    /* Alt key on */
                     49: #define CPLS   0x10                    /* Caps lock on */
                     50: #define NMLS   0x20                    /* Num lock on */
                     51: #define AKPS   0x40                    /* Alternate keypad shift */
                     52: #define SHFT   0x80                    /* Shift key flag */
                     53: 
                     54: /* Function key information */
                     55: #define        NFKEY   20                      /* Number of settable functions */
                     56: #define        NFCHAR  150                     /* Number of characters settable */
                     57: #define        NFBUF   (NFKEY*2+NFCHAR+1)      /* Size of buffer */
                     58: 
                     59: /*
                     60:  * Functions.
                     61:  */
                     62: int    isrint();
                     63: int    istime();
                     64: void   isbatch();
                     65: int    mmstart();
                     66: int    isopen();
                     67: int    isclose();
                     68: int    isread();
                     69: int    mmwrite();
                     70: int    isioctl();
                     71: void   mmwatch();
                     72: int    isload();
                     73: int    isuload();
                     74: int    ispoll();
                     75: int    nulldev();
                     76: int    nonedev();
                     77: 
                     78: static int     isioctl0();
                     79: 
                     80: /*
                     81:  * Configuration table.
                     82:  */
                     83: CON iscon ={
                     84:        DFCHR|DFPOL,                    /* Flags */
                     85:        KB_MAJOR,                       /* Major index */
                     86:        isopen,                         /* Open */
                     87:        isclose,                        /* Close */
                     88:        nulldev,                        /* Block */
                     89:        isread,                         /* Read */
                     90:        mmwrite,                        /* Write */
                     91: #ifdef _I386
                     92:        isioctl0,                       /* Ioctl */
                     93: #else
                     94:        isioctl,                        /* Ioctl */
                     95: #endif
                     96:        nulldev,                        /* Powerfail */
                     97:        mmwatch,                        /* Timeout */
                     98:        isload,                         /* Load */
                     99:        isuload,                        /* Unload */
                    100:        ispoll                          /* Poll */
                    101: };
                    102: 
                    103: /*
                    104:  * Flag indicating turbo machine.
                    105:  */
                    106: int isturbo = 0;
                    107: 
                    108: /*
                    109:  * Terminal structure.
                    110:  */
                    111: TTY    istty = {
                    112:        {0}, {0}, 0, mmstart, NULL, 0, 0
                    113: };
                    114: 
                    115: static silo_t in_silo;
                    116: 
                    117: /*
                    118:  * State variables.
                    119:  */
                    120: int            islock;                 /* Keyboard locked flag */
                    121: int            isbusy;                 /* Raw input conversion busy */
                    122: static char    shift;                  /* Overall shift state */
                    123: static char    scroll;                 /* Scroll lock state */
                    124: static  char   lshift = LSHIFT;        /* Left shift alternate state */
                    125: static char    isfbuf[NFBUF];          /* Function key values */
                    126: static char    *isfval[NFKEY];         /* Function key string pointers */
                    127: static int     ledcmd;                 /* LED update command flag */
                    128: static int     extended;               /* extended key scan count */
                    129: 
                    130: /*
                    131:  * Tables for converting key code to ASCII.
                    132:  * lmaptab specifies unshifted conversion,
                    133:  * umaptab specifies shifted conversion,
                    134:  * smaptab specifies the shift states which are active.
                    135:  * An entry of XXX says the key is dead.
                    136:  * An entry of SPC requires further processing.
                    137:  *
                    138:  * Key codes:
                    139:  *     ESC .. <- == 1 .. 14
                    140:  *     -> .. \n == 15 .. 28
                    141:  *     CTRL .. ` == 29 .. 41
                    142:  *     ^Shift .. PrtSc == 42 .. 55
                    143:  *     ALT .. CapsLock == 56 .. 58
                    144:  *     F1 .. F10 == 59 .. 68
                    145:  *     NumLock .. Del == 69 .. 83
                    146:  */
                    147: static unsigned char lmaptab[] ={
                    148:             '\33',  '1',  '2',  '3',  '4',  '5',  '6',         /* 1 - 7 */
                    149:         '7',  '8',  '9',  '0',  '-',  '=', '\b', '\t',         /* 8 - 15 */
                    150:         'q',  'w',  'e',  'r',  't',  'y',  'u',  'i',         /* 16 - 23 */
                    151:         'o',  'p',  '[',  ']', '\r',  XXX,  'a',  's',         /* 24 - 31 */
                    152:         'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';',         /* 32 - 39 */
                    153:         '\'', '`',  XXX,  '\\',  'z',  'x',  'c',  'v',        /* 40 - 47 */
                    154:         'b',  'n',  'm',  ',',  '.',  '/',  XXX,  '*',         /* 48 - 55 */
                    155:         XXX,  ' ',  XXX,  SPC,  SPC,  SPC,  SPC,  SPC,         /* 56 - 63 */
                    156:         SPC,  SPC,  SPC,  SPC,  SPC,  SPC,  SPC,  SPC,         /* 64 - 71 */
                    157:         SPC,  SPC,  '-',  SPC,  SPC,  SPC,  '+',  SPC,         /* 72 - 79 */
                    158:         SPC,  SPC,  SPC,  SPC                                  /* 80 - 83 */
                    159: };
                    160: 
                    161: static unsigned char umaptab[] ={
                    162:             '\33',  '!',  '@',  '#',  '$',  '%',  '^',         /* 1 - 7 */
                    163:         '&',  '*',  '(',  ')',  '_',  '+', '\b', SPC,          /* 8 - 15 */
                    164:         'Q',  'W',  'E',  'R',  'T',  'Y',  'U',  'I',         /* 16 - 23 */
                    165:         'O',  'P',  '{',  '}', '\r',  XXX,  'A',  'S',         /* 24 - 31 */
                    166:         'D',  'F',  'G',  'H',  'J',  'K',  'L',  ':',         /* 32 - 39 */
                    167:         '"',  '~',  XXX,  '|',  'Z',  'X',  'C',  'V',         /* 40 - 47 */
                    168:         'B',  'N',  'M',  '<',  '>',  '?',  XXX,  '*',         /* 48 - 55 */
                    169:         XXX,  ' ',  XXX,  SPC,  SPC,  SPC,  SPC,  SPC,         /* 56 - 63 */
                    170:         SPC,  SPC,  SPC,  SPC,  SPC,  SPC,  SPC,  SPC,         /* 64 - 71 */
                    171:         SPC,  SPC,  '-',  SPC,  SPC,  SPC,  '+',  SPC,         /* 72 - 79 */
                    172:         SPC,  SPC,  SPC,  SPC                                  /* 80 - 83 */
                    173: };
                    174: 
                    175: #define SS0    0                       /* No shift */
                    176: #define SS1    (SLS|SRS|CTS)           /* Shift, Ctrl */
                    177: #define SES    (SLS|SRS)               /* Shift */
                    178: #define LET    (SLS|SRS|CPLS|CTS)      /* Shift, Caps, Ctrl */
                    179: #define KEY    (SLS|SRS|NMLS|AKPS)     /* Shift, Num, Alt keypad */
                    180: 
                    181: static unsigned char smaptab[] ={
                    182:               SS0,  SES,  SS1,  SES,  SES,  SES,  SS1,         /* 1 - 7 */
                    183:         SES,  SES,  SES,  SES,  SS1,  SES,  CTS,  SES,         /* 8 - 15 */
                    184:         LET,  LET,  LET,  LET,  LET,  LET,  LET,  LET,         /* 16 - 23 */
                    185:         LET,  LET,  SS1,  SS1,  CTS, SHFT,  LET,  LET,         /* 24 - 31 */
                    186:         LET,  LET,  LET,  LET,  LET,  LET,  LET,  SES,         /* 32 - 39 */
                    187:         SES,  SS1, SHFT,  SS1,  LET,  LET,  LET,  LET,         /* 40 - 47 */
                    188:         LET,  LET,  LET,  SES,  SES,  SES, SHFT,  SES,         /* 48 - 55 */
                    189:        SHFT,  SS1, SHFT,  SS0,  SS0,  SS0,  SS0,  SS0,         /* 56 - 63 */
                    190:         SS0,  SS0,  SS0,  SS0,  SS0, SHFT,  KEY,  KEY,         /* 64 - 71 */
                    191:         KEY,  KEY,  SS0,  KEY,  KEY,  KEY,  SS0,  KEY,         /* 72 - 79 */
                    192:         KEY,  KEY,  KEY,  KEY                                  /* 80 - 83 */
                    193: };
                    194: 
                    195: /*
                    196:  * Load entry point.
                    197:  *  Do reset the keyboard because it gets terribly munged
                    198:  *  if you type during the boot.
                    199:  */
                    200: isload()
                    201: {
                    202:        register short i;/* was: int i .. the loop below is hardly portable */
                    203: 
                    204:        /*
                    205:         * Reset keyboard if NOT an XT turbo.
                    206:         */
                    207:        if ( ! isturbo ) {
                    208:                outb(KBCTRL, 0x0C);             /* Clock low */
                    209:                for (i = 10582; --i >= 0; );    /* For 20ms */
                    210:                outb(KBCTRL, 0xCC);             /* Clock high */
                    211:                for (i = 0; --i != 0; )
                    212:                        ;
                    213:                i = inb(KBDATA);
                    214:                outb(KBCTRL, 0xCC);                     /* Clear keyboard */
                    215:                outb(KBCTRL, 0x4D);                     /* Enable keyboard */
                    216:        }
                    217: 
                    218:        /*
                    219:         * Enable mmwatch() invocation every second.
                    220:         */
                    221:        drvl[KB_MAJOR].d_time = 1;
                    222: 
                    223:        /*
                    224:         * Seize keyboard interrupt.
                    225:         */
                    226:        setivec(1, isrint);
                    227: 
                    228:        /*
                    229:         * Initialize video display.
                    230:         */
                    231:        mmstart( &istty );
                    232: }
                    233: 
                    234: /*
                    235:  * Unload entry point.
                    236:  */
                    237: isuload()
                    238: {
                    239:        clrivec(1);
                    240: }
                    241: 
                    242: /*
                    243:  * Default function key strings (terminated by -1 [\377])
                    244:  */
                    245: static char *deffuncs[] = {
                    246:        "\33[1x\377",   /* F1 */
                    247:        "\33[2x\377",   /* F2 */
                    248:        "\33[3x\377",   /* F3 */
                    249:        "\33[4x\377",   /* F4 */
                    250:        "\33[5x\377",   /* F5 */
                    251:        "\33[6x\377",   /* F6 */
                    252:        "\33[7x\377",   /* F7 */
                    253:        "\33[8x\377",   /* F8 */
                    254:        "\33[9x\377",   /* F9 */
                    255:        "\33[0x\377",   /* F10 - historical value */
                    256:        "\33[1y\377",   /* F11 */
                    257:        "\33[2y\377",   /* F12 */
                    258:        "\33[3y\377",   /* F13 */
                    259:        "\33[4y\377",   /* F14 */
                    260:        "\33[5y\377",   /* F15 */
                    261:        "\33[6y\377",   /* F16 */
                    262:        "\33[7y\377",   /* F17 */
                    263:        "\33[8y\377",   /* F18 */
                    264:        "\33[9y\377",   /* F19 */
                    265:        "\33[0y\377"    /* F20 */
                    266: };
                    267: 
                    268: /*
                    269:  * Open routine.
                    270:  */
                    271: isopen(dev, mode)
                    272: dev_t dev;
                    273: unsigned int mode;
                    274: {
                    275:        register int s;
                    276: 
                    277:        if (minor(dev) != 0) {
                    278:                u.u_error = ENXIO;
                    279:                return;
                    280:        }
                    281:        if ((istty.t_flags&T_EXCL)!=0 && super()==0) {
                    282:                u.u_error = ENODEV;
                    283:                return;
                    284:        }
                    285:        ttsetgrp(&istty, dev, mode);
                    286: 
                    287:        s = sphi();
                    288:        if (istty.t_open++ == 0)
                    289:        {  initkeys();   /* init function keys */
                    290:           istty.t_flags = T_CARR;  /* indicate "carrier" */
                    291:           ttopen(&istty);
                    292:        }
                    293:        spl(s);
                    294:        updleds();                      /* update keyboard status LEDS */
                    295: }
                    296: 
                    297: /* Init function keys */
                    298: initkeys()
                    299: {      register int i;
                    300:        register char *cp1, *cp2;
                    301: 
                    302:        for (i=0; i<NFKEY; i++)
                    303:            isfval[i] = 0;          /* clear function key buffer */
                    304:        cp2 = isfbuf;               /* pointer to key buffer */
                    305:        for (i=0; i<NFKEY; i++)
                    306:        {  isfval[i] = cp2;         /* save pointer to key string */
                    307:           cp1 = deffuncs[i];       /* get init string pointer */
                    308:           while ((*cp2++ = *cp1++) != -1)  /* copy key data */
                    309:             if (cp2 >= &isfbuf[NFBUF-3])   /* overflow? */
                    310:                return;
                    311:        }
                    312: }
                    313: 
                    314: /*
                    315:  * Close a tty.
                    316:  */
                    317: isclose(dev)
                    318: {
                    319:        register int s;
                    320: 
                    321:        s = sphi();
                    322:        if (--istty.t_open == 0)
                    323:        {       s = sphi();
                    324:                ttclose(&istty);
                    325:                spl(s);
                    326:        }
                    327: }
                    328: 
                    329: /*
                    330:  * Read routine.
                    331:  */
                    332: isread(dev, iop)
                    333: dev_t dev;
                    334: IO *iop;
                    335: {
                    336:        ttread(&istty, iop, 0);
                    337:        if (istty.t_oq.cq_cc)
                    338:                mmtime(&istty);
                    339: }
                    340: 
                    341: /*
                    342:  * Ioctl routine.
                    343:  */
                    344: #ifdef _I386
                    345: isioctl0(dev, com, vec)
                    346: dev_t dev;
                    347: struct sgttyb *vec;
                    348: {
                    349:        tioc286(dev, com, vec, isioctl);
                    350: }
                    351: #endif
                    352: 
                    353: isioctl(dev, com, vec)
                    354: dev_t dev;
                    355: struct sgttyb *vec;
                    356: {
                    357:        register int s;
                    358: 
                    359:        switch(com) {
                    360:        case TIOCSETF:
                    361:        case TIOCGETF:
                    362:                isfunction(com, (char *)vec);
                    363:                goto ioc_done;;
                    364:        case TIOCSHIFT:   /* switch left-SHIFT and "\" */
                    365:                lshift = LSHIFTA;    /* alternate values */
                    366:                lmaptab[41] = '\\';
                    367:                lmaptab[42] = XXX;
                    368:                umaptab[41] = '|';
                    369:                umaptab[42] = XXX;
                    370:                smaptab[41] = SS1;
                    371:                smaptab[42] = SHFT;
                    372:                goto ioc_done;;
                    373:        case TIOCCSHIFT:  /* normal (default) left-SHIFT and "\" */
                    374:                lshift = LSHIFT;     /* normal values */
                    375:                lmaptab[41] = XXX;
                    376:                lmaptab[42] = '\\';
                    377:                umaptab[41] = XXX;
                    378:                umaptab[42] = '|';
                    379:                smaptab[41] = SHFT;
                    380:                smaptab[42] = SS1;
                    381:                goto ioc_done;;
                    382:        }
                    383:        s = sphi();
                    384:        ttioctl(&istty, com, vec);
                    385:        spl(s);
                    386: 
                    387: ioc_done:
                    388:        return;
                    389: }
                    390: 
                    391: /*
                    392:  * Set and receive the function keys.
                    393:  */
                    394: isfunction(c, v)
                    395: int c;
                    396: char *v;
                    397: {
                    398:        register char *cp;
                    399:        register int i;
                    400: 
                    401:        if (c == TIOCGETF) {
                    402:                for (cp = isfbuf; cp < &isfbuf[NFBUF]; cp++)
                    403:                    putubd(v++, *cp);
                    404:        } else {
                    405:                for (i=0; i<NFKEY; i++)         /* zap current settings */
                    406:                        isfval[i] = 0;
                    407:                cp = isfbuf;                    /* pointer to key buffer */
                    408:                for (i=0; i<NFKEY; i++) {
                    409:                        isfval[i] = cp;         /* save pointer to key string */
                    410:                        while ((*cp++ = getubd(v++)) != -1)  /* copy key data */
                    411:                                if (cp >= &isfbuf[NFBUF-3])  /* overflow? */
                    412:                                        return;
                    413:                }
                    414:        }
                    415: }
                    416: 
                    417: 
                    418: /*
                    419:  * Poll routine.
                    420:  */
                    421: ispoll( dev, ev, msec )
                    422: dev_t dev;
                    423: int ev;
                    424: int msec;
                    425: {
                    426:        return ttpoll(&istty, ev, msec);
                    427: }
                    428: 
                    429: /*
                    430:  * Receive interrupt.
                    431:  */
                    432: isrint()
                    433: {
                    434:        register int    c;
                    435:        register int    s;
                    436:        register int    r;
                    437:        int     savests;
                    438:        int     update_leds = 0;
                    439: 
                    440:        /*
                    441:         * Schedule raw input handler if not already active.
                    442:         */
                    443:        if ( isbusy == 0 ) {
                    444:                isbusy = 1;
                    445:                defer( isbatch, &istty );
                    446:        }
                    447: 
                    448:        /*
                    449:         * Pull character from the data
                    450:         * port. Pulse the KBFLAG in the control
                    451:         * port to reset the data buffer.
                    452:         */
                    453:        r = inb(KBDATA) & 0xFF;
                    454:        c = inb(KBCTRL);
                    455:        outb(KBCTRL, c|KBFLAG);
                    456:        outb(KBCTRL, c);
                    457: #if    KBDEBUG
                    458:        printf("kbd: %d\n", r);                 /* print scan code/direction */
                    459: #endif
                    460:        if (ledcmd) {
                    461:                ledcmd = 0;
                    462:                if (r == KBACK) {               /* output to status LEDS */
                    463:                        c = scroll & 1;
                    464:                        if (shift & NMLS)
                    465:                                c |= 2;
                    466:                        if (shift & CPLS)
                    467:                                c |= 4;
                    468:                        outb(KBDATA, c);
                    469:                }
                    470:                return;
                    471:        }
                    472:        if (extended > 0) {                     /* if multi-character seq, */
                    473:                --extended;                     /* ... ignore this char */
                    474:                return;
                    475:        }
                    476:        if (r == EXTENDED1) {                   /* ignore extended sequences */
                    477:                extended = 5;
                    478:                return;
                    479:        }
                    480:        if (r == 0xFF)
                    481:                return; /* Overrun */
                    482:        c = (r & KEYSC) - 1;
                    483:        /*
                    484:         * Check for reset.
                    485:         */
                    486:        if ((r&KEYUP) == 0 && c == DELETE && (shift&(CTS|ALS)) == (CTS|ALS))
                    487:                boot();
                    488: 
                    489:        /*
                    490:         * Track "shift" keys.
                    491:         */
                    492:        s = smaptab[c];
                    493:        if (s&SHFT) {
                    494:                if (r&KEYUP) {                  /* "shift" released */
                    495:                        if (c == RSHIFT)
                    496:                                shift &= ~SRS;
                    497:                        else if (c == lshift)
                    498:                                shift &= ~SLS;
                    499:                        else if (c == CTRL)
                    500:                                shift &= ~CTS;
                    501:                        else if (c == ALT)
                    502:                                shift &= ~ALS;
                    503:                } else {                        /* "shift" pressed */
                    504:                        if (c == lshift)
                    505:                                shift |= SLS;
                    506:                        else if (c == RSHIFT)
                    507:                                shift |= SRS;
                    508:                        else if (c == CTRL)
                    509:                                shift |= CTS;
                    510:                        else if (c == ALT)
                    511:                                shift |= ALS;
                    512:                        else if (c == CAPLOCK) {
                    513:                                shift ^= CPLS;  /* toggle cap lock */
                    514:                                updleds();
                    515:                        } else if (c == NUMLOCK) {
                    516:                                shift ^= NMLS;  /* toggle num lock */
                    517:                                updleds();
                    518:                        }
                    519:                }
                    520:                return;
                    521:        }
                    522: 
                    523:        /*
                    524:         * No other key up codes of interest.
                    525:         */
                    526:        if (r&KEYUP)
                    527:                return;
                    528: 
                    529:        /*
                    530:         * If the tty is not open the character is
                    531:         * just tossed away.
                    532:         */
                    533:        if (istty.t_open == 0)
                    534:                return;
                    535: 
                    536:        /*
                    537:         * Map character, based on the
                    538:         * current state of the shift, control,
                    539:         * meta and lock flags.
                    540:         */
                    541:        if (shift & CTS) {
                    542:                if (s == CTS)                   /* Map Ctrl (BS | NL) */
                    543:                        c = (c == BACKSP) ? 0x7F : 0x0A;
                    544:                else if (s==SS1 || s==LET)      /* Normal Ctrl map */
                    545:                        c = umaptab[c]&0x1F;    /* Clear bits 5-6 */
                    546:                else
                    547:                        return;                 /* Ignore this char */
                    548:        } else if (s &= shift) {
                    549:                if (shift & SES) {               /* if shift on */
                    550:                        if (s & (CPLS|NMLS))     /* if caps/num lock */
                    551:                                c = lmaptab[c];  /* use unshifted */
                    552:                        else
                    553:                                c = umaptab[c];  /* use shifted */
                    554:                } else {                         /* if shift not on */
                    555:                        if (s & (CPLS|NMLS))     /* if caps/num lock */
                    556:                                c = umaptab[c];  /* use shifted */
                    557:                        else
                    558:                                c = lmaptab[c];  /* use unshifted */
                    559:                }
                    560:        } else
                    561:                c = lmaptab[c];                  /* use unshifted */
                    562: 
                    563:        /*
                    564:         * Act on character.
                    565:         */
                    566:        if (c == XXX)
                    567:                return;                          /* char to ignore */
                    568: 
                    569:        if (c != SPC) {                  /* not special char? */
                    570:                if (shift & ALS)         /* ALT (meta bit)? */
                    571:                        c |= 0x80;       /* set meta */
                    572:                isin(c);                 /* send the char */
                    573:        } else
                    574:                update_leds += isspecial(r);     /* special chars */
                    575:        if (update_leds) {
                    576:                savests = sphi();
                    577:                outb(KBDATA, LEDCMD);
                    578:                ledcmd = 1;
                    579:                spl(savests);
                    580:        }
                    581: }
                    582: 
                    583: /*
                    584:  * Handle special input sequences.
                    585:  * The character passed is the key number.
                    586:  *
                    587:  * The keypad is translated by the following table,
                    588:  * the first entry is the normal sequence, the second the shifted,
                    589:  * and the third the alternate keypad sequence.
                    590:  */
                    591: static char *keypad[][3] = {
                    592:        { "\33[H",  "7", "\33?w" },     /* 71 */
                    593:        { "\33[A",  "8", "\33?x" },     /* 72 */
                    594:        { "\33[V",  "9", "\33?y" },     /* 73 */
                    595:        { "\33[D",  "4", "\33?t" },     /* 75 */
                    596:        { "\0337",  "5", "\33?u" },     /* 76 */
                    597:        { "\33[C",  "6", "\33?v" },     /* 77 */
                    598:        { "\33[24H","1", "\33?q" },     /* 79 */
                    599:        { "\33[B",  "2", "\33?r" },     /* 80 */
                    600:        { "\33[U",  "3", "\33?s" },     /* 81 */
                    601:        { "\33[@",  "0", "\33?p" },     /* 82 */
                    602:        { "\33[P", ".",  "\33?n" }      /* 83 */
                    603: };
                    604: 
                    605: isspecial(c)
                    606: int c;
                    607: {
                    608:        register char *cp;
                    609:        register int s;
                    610:        int     update_leds = 0;
                    611: 
                    612:        cp = 0;
                    613: 
                    614:        switch (c) {
                    615:        case 15:                                        /* cursor back tab */
                    616:                cp = "\033[Z";
                    617:                break;
                    618:        case 59: case 60: case 61: case 62: case 63:    /* Function keys */
                    619:        case 64: case 65: case 66: case 67: case 68:
                    620:                /* offset to function string */
                    621:                if ( shift & ALS )
                    622:                        cp = isfval[c-49];
                    623:                else
                    624:                        cp = isfval[c-59];
                    625:                break;
                    626: 
                    627:        case 70:                /* Scroll Lock -- stop/start output */
                    628:        {
                    629:                static char cbuf[2];
                    630: 
                    631:                cp = &cbuf[0];  /* working buffer */
                    632:                if (!(istty.t_sgttyb.sg_flags&RAWIN)) { /* not if in RAW mode */
                    633:                        ++update_leds;
                    634:                        if (istty.t_flags & T_STOP) {   /* output stopped? */
                    635:                           cbuf[0] = istty.t_tchars.t_startc;  /* start it */
                    636:                           scroll = 0;
                    637:                        } else {
                    638:                           cbuf[0] = istty.t_tchars.t_stopc;   /* stop output */
                    639:                           scroll = 1;
                    640:                        }
                    641:                }
                    642:                break;
                    643:        }
                    644: 
                    645:        case 79:                /* 1/End */
                    646:        case 80:                /* 2/DOWN */
                    647:        case 81:                /* 3/PgDn */
                    648:        case 82:                /* 0/Ins */
                    649:        case 83:                /* ./Del */
                    650:                --c;            /* adjust code */
                    651:        case 75:                /* 4/LEFT */
                    652:        case 76:                /* 5 */
                    653:        case 77:                /* 6/RIGHT */
                    654:                --c;            /* adjust code */
                    655:        case 71:                /* 7/Home/Clear */
                    656:        case 72:                /* 8/UP */
                    657:        case 73:                /* 9/PgUp */
                    658:                s = 0;                  /* start off with normal keypad */
                    659:                if (shift&NMLS)         /* num lock? */
                    660:                        s = 1;          /* set shift pad */
                    661:                if (shift&SES)          /* shift? */
                    662:                        s ^= 1;         /* toggle shift pad */
                    663:                if (shift&AKPS)         /* alternate pad? */
                    664:                        s = 2;          /* set alternate pad */
                    665:                cp = keypad[c-71][s];   /* get keypad value */
                    666:                break;
                    667:        }
                    668:        if (cp)                                 /* send string */
                    669:                while ((*cp != 0) && (*cp != -1))
                    670:                        isin( *cp++ & 0377 );
                    671:        return update_leds;
                    672: }
                    673: 
                    674: /**
                    675:  *
                    676:  * void
                    677:  * ismmfunc( c )       -- process keyboard related output escape sequences
                    678:  * char c;
                    679:  */
                    680: void
                    681: ismmfunc(c)
                    682: register int c;
                    683: {
                    684:        switch (c) {
                    685:        case 't':       /* Enter numlock */
                    686:                shift |= NMLS;
                    687:                updleds();                      /* update LED status */
                    688:                break;
                    689:        case 'u':       /* Leave numlock */
                    690:                shift &= ~NMLS;
                    691:                updleds();                      /* update LED status */
                    692:                break;
                    693:        case '=':       /* Enter alternate keypad */
                    694:                shift |= AKPS;
                    695:                break;
                    696:        case '>':       /* Exit alternate keypad */
                    697:                shift &= ~AKPS;
                    698:                break;
                    699:        case 'c':       /* Reset terminal */
                    700:                islock = 0;
                    701:                shift  = 0;
                    702:                initkeys();
                    703:                updleds();                      /* update LED status */
                    704:                break;
                    705:        }
                    706: }
                    707: 
                    708: /**
                    709:  *
                    710:  * void
                    711:  * isin( c )   -- append character to raw input silo
                    712:  * char c;
                    713:  */
                    714: static
                    715: isin( c )
                    716: register int c;
                    717: {
                    718:        int cache_it = 1;
                    719:        TTY * tp = &istty;
                    720: 
                    721:        /*
                    722:         * If using software incoming flow control, process and
                    723:         * discard t_stopc and t_startc.
                    724:         */
                    725:        if (!ISRIN) {
                    726:                if (ISSTOP) {
                    727:                        if ((tp->t_flags&T_STOP) == 0)
                    728:                                tp->t_flags |= T_STOP;
                    729:                        cache_it = 0;
                    730:                }
                    731:                if (ISSTART) {
                    732:                        tp->t_flags &= ~T_STOP;
                    733:                        ttstart(tp);
                    734:                        cache_it = 0;
                    735:                }
                    736:        }
                    737: 
                    738:        /*
                    739:         * Cache received character.
                    740:         */
                    741:        if (cache_it) {
                    742:                in_silo.si_buf[ in_silo.si_ix ] = c;
                    743: 
                    744:                if ( ++in_silo.si_ix >= sizeof(in_silo.si_buf) )
                    745:                        in_silo.si_ix = 0;
                    746:        }
                    747: }
                    748: 
                    749: /**
                    750:  *
                    751:  * void
                    752:  * isbatch()   -- raw input conversion routine
                    753:  *
                    754:  *     Action: Enable the video display.
                    755:  *             Canonize the raw input silo.
                    756:  *
                    757:  *     Notes:  isbatch() was scheduled as a deferred process by isrint().
                    758:  */
                    759: static void
                    760: isbatch( tp )
                    761: register TTY * tp;
                    762: {
                    763:        register int c;
                    764:        static int lastc;
                    765: 
                    766:        /*
                    767:         * Ensure video display is enabled.
                    768:         */
                    769:        mm_von();
                    770: 
                    771:        isbusy = 0;
                    772: 
                    773:        /*
                    774:         * Process all cached characters.
                    775:         */
                    776:        while ( in_silo.si_ix != in_silo.si_ox ) {
                    777: 
                    778:                /*
                    779:                 * Get next cached char.
                    780:                 */
                    781:                c = in_silo.si_buf[ in_silo.si_ox ];
                    782: 
                    783:                if ( in_silo.si_ox >= sizeof(in_silo.si_buf) - 1 )
                    784:                        in_silo.si_ox = 0;
                    785:                else
                    786:                        in_silo.si_ox++;
                    787: 
                    788:                if ( (islock == 0) || ISINTR || ISQUIT ) {
                    789:                        ttin( tp, c );
                    790:                }
                    791: 
                    792:                else if ( (c == 'b') && (lastc == '\033') ) {
                    793:                        islock = 0;
                    794:                        ttin( tp, lastc );
                    795:                        ttin( tp, c );
                    796:                }
                    797: 
                    798:                else if ( (c == 'c') && (lastc == '\033') ) {
                    799:                        ttin( tp, lastc );
                    800:                        ttin( tp, c );
                    801:                }
                    802: 
                    803:                else
                    804:                        putchar('\007');
                    805: 
                    806:                lastc = c;
                    807:        }
                    808: }
                    809: 
                    810: /*
                    811:  * update the keyboard status LEDS
                    812:  */
                    813: updleds()
                    814: {
                    815:        int     s;
                    816: 
                    817:        s = sphi();
                    818:        outb(KBDATA, LEDCMD);
                    819:        ledcmd = 1;
                    820:        spl(s);
                    821: }
                    822: 
                    823: /*
                    824:  * unlock the scroll in case an interrupt character is received
                    825:  */
                    826: kbunscroll()
                    827: {
                    828:        scroll = 0;
                    829:        updleds();
                    830: }

unix.superglobalmegacorp.com

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