Annotation of xinu/sys/ttyiin.c, revision 1.1.1.2

1.1       root        1: /* ttyiin.c ttyiin, erase1, eputc, echoch */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <tty.h>
                      6: #include <io.h>
1.1.1.2 ! root        7: 
        !             8: /* set up macros for appropriate SLU as spec. by SLUCHIP:
        !             9:    if SLUCHIP==6850, #include slu6850.h, #define TTYIIN ttyiin6850, etc.
        !            10:    if SLUCHIP==7201, #include slu7201.h, #define TTYIIN ttyiin7201, etc.
        !            11:    if SLUCHIP undef.,#include slu.h, #define TTYIIN ttyiin  (orig. case)
        !            12:    similarly sluaccess.h, other TTY fns */
        !            13: #include <sluinclude.h>
1.1       root       14: 
                     15: /*------------------------------------------------------------------------
                     16:  *  ttyiin  --  lower-half tty device driver for input interrupts
                     17:  *------------------------------------------------------------------------
                     18:  */
1.1.1.2 ! root       19: INTPROC TTYIIN(ttyp, cptr, error)
        !            20:        register struct tty     *ttyp;  /* pointer to tty block         */
        !            21:        register struct csr     *cptr;  /* pointer to cont. & stat. reg */
        !            22:        register int    error;
1.1       root       23: {
1.1.1.2 ! root       24:        register int    ch;
        !            25:        Bool    cerr;
        !            26:        int     ct;
        !            27: 
        !            28: #ifdef DEBUG
        !            29: /*     kprintf("ttyiin(%x, %x)\n", ttyp, cptr);
        !            30:  */
        !            31: #endif
        !            32:        ch = slugetch(cptr);
        !            33:        if (ttyp->imode == IMRAW) {
        !            34:                if (scount(ttyp->isem) >= IBUFLEN)
        !            35:                        return;
        !            36:                if (error)                      /* character error      */
        !            37:                        ttyp->ibuff[ttyp->ihead++] = ch | IOCHERR;
        !            38:                else
        !            39:                        ttyp->ibuff[ttyp->ihead++] = ch;
        !            40:                if (ttyp->ihead >= IBUFLEN)     /* wrap buffer pointer  */
        !            41:                        ttyp->ihead = 0;
        !            42:                signal(ttyp->isem);
1.1       root       43:        } else {                                /* cbreak | cooked mode */
1.1.1.2 ! root       44:                cerr = error ? IOCHERR : 0;
        !            45:                ch &= SLUCHMASK;
        !            46:                if ( ch == RETURN && ttyp->icrlf )
1.1       root       47:                        ch = NEWLINE;
1.1.1.2 ! root       48:                if (ttyp->oflow) {
        !            49:                        if (ch == ttyp->ostart) {
        !            50:                                ttyp->oheld = FALSE;
1.1       root       51:                                return;
                     52:                        }
1.1.1.2 ! root       53:                        if (ch == ttyp->ostop) {
        !            54:                                ttyp->oheld = TRUE;
1.1       root       55:                                return;
                     56:                        }
                     57:                }
1.1.1.2 ! root       58:                ttyp->oheld = FALSE;
        !            59:                if (ttyp->imode == IMCBREAK) {          /* cbreak mode  */
        !            60:                        if (scount(ttyp->isem) >= IBUFLEN) {
        !            61:                                eputc(ttyp->ifullc,ttyp,cptr);
1.1       root       62:                                return;
                     63:                        }
1.1.1.2 ! root       64:                        ttyp->ibuff[ttyp->ihead++] = ch | cerr;
        !            65:                        if (ttyp->ihead >= IBUFLEN)
        !            66:                                ttyp->ihead = 0;
        !            67:                        if (ttyp->iecho)
        !            68:                                echoch(ch,ttyp,cptr);
        !            69:                        if (scount(ttyp->isem) < IBUFLEN)
        !            70:                                signal(ttyp->isem);
1.1       root       71:                } else {                                /* cooked mode  */
1.1.1.2 ! root       72:                        if (ch == ttyp->ikillc && ttyp->ikill) {
        !            73:                                ttyp->ihead -= ttyp->icursor;
        !            74:                                if (ttyp->ihead < 0)
        !            75:                                        ttyp->ihead += IBUFLEN;
        !            76:                                ttyp->icursor = 0;
        !            77:                                eputc(RETURN,ttyp,cptr);
        !            78:                                eputc(NEWLINE,ttyp,cptr);
1.1       root       79:                                return;
                     80:                        }
1.1.1.2 ! root       81:                        if (ch == ttyp->ierasec && ttyp->ierase) {
        !            82:                                if (ttyp->icursor > 0) {
        !            83:                                        ttyp->icursor--;
        !            84:                                        erase1(ttyp,cptr);
1.1       root       85:                                }
                     86:                                return;
                     87:                        }
1.1.1.2 ! root       88:                        if (ch == NEWLINE || ch == RETURN) {
        !            89:                                if (ttyp->iecho)
        !            90:                                        echoch(ch,ttyp,cptr);
        !            91:                                ttyp->ibuff[ttyp->ihead++] = ch | cerr;
        !            92:                                if (ttyp->ihead >= IBUFLEN)
        !            93:                                        ttyp->ihead = 0;
        !            94:                                ct = ttyp->icursor+1; /* +1 for \n or \r*/
        !            95:                                ttyp->icursor = 0;
        !            96:                                signaln(ttyp->isem,ct);
1.1       root       97:                                return;
                     98:                        }
1.1.1.2 ! root       99:                        ct = scount(ttyp->isem);
1.1       root      100:                        ct = ct < 0 ? 0 : ct;
1.1.1.2 ! root      101:                        if ((ct + ttyp->icursor) >= IBUFLEN-1) {
        !           102:                                eputc(ttyp->ifullc,ttyp,cptr);
1.1       root      103:                                return;
                    104:                        }
1.1.1.2 ! root      105:                        if (ttyp->iecho)
        !           106:                                echoch(ch,ttyp,cptr);
        !           107:                        ttyp->icursor++;
        !           108:                        ttyp->ibuff[ttyp->ihead++] = ch | cerr;
        !           109:                        if (ttyp->ihead >= IBUFLEN)
        !           110:                                ttyp->ihead = 0;
1.1       root      111:                }
                    112:        }
                    113: }
                    114: 
                    115: /*------------------------------------------------------------------------
                    116:  *  erase1  --  erase one character honoring erasing backspace
                    117:  *------------------------------------------------------------------------
                    118:  */
1.1.1.2 ! root      119: LOCAL erase1(ttyp,cptr)
        !           120:        register struct tty     *ttyp;
1.1       root      121:        register struct csr     *cptr;
                    122: {
1.1.1.2 ! root      123:        register char   ch;
        !           124: 
        !           125: #ifdef DEBUG
        !           126:        kprintf("erase1(%x, %x)\n", ttyp, cptr);
        !           127: #endif
1.1       root      128: 
1.1.1.2 ! root      129:        if (--(ttyp->ihead) < 0)
        !           130:                ttyp->ihead += IBUFLEN;
        !           131:        ch = ttyp->ibuff[ttyp->ihead];
        !           132:        if (ttyp->iecho) {
1.1       root      133:                if (ch < BLANK || ch == 0177) {
1.1.1.2 ! root      134:                        if (ttyp->evis) {
        !           135:                                eputc(BACKSP,ttyp,cptr);
        !           136:                                if (ttyp->ieback) {
        !           137:                                        eputc(BLANK,ttyp,cptr);
        !           138:                                        eputc(BACKSP,ttyp,cptr);
1.1       root      139:                                }
                    140:                        }
1.1.1.2 ! root      141:                        eputc(BACKSP,ttyp,cptr);
        !           142:                        if (ttyp->ieback) {
        !           143:                                eputc(BLANK,ttyp,cptr);
        !           144:                                eputc(BACKSP,ttyp,cptr);
1.1       root      145:                        }
                    146:                } else {
1.1.1.2 ! root      147:                        eputc(BACKSP,ttyp,cptr);
        !           148:                        if (ttyp->ieback) {
        !           149:                                eputc(BLANK,ttyp,cptr);
        !           150:                                eputc(BACKSP,ttyp,cptr);
1.1       root      151:                        }
                    152:                }
1.1.1.2 ! root      153:        } else {
        !           154:               slutenable(cptr);        /* restart output */
        !           155:        }
1.1       root      156: }
                    157: 
                    158: /*------------------------------------------------------------------------
                    159:  *  echoch  --  echo a character with visual and ocrlf options
                    160:  *------------------------------------------------------------------------
                    161:  */
1.1.1.2 ! root      162: LOCAL echoch(ch, ttyp, cptr)
        !           163:        register char   ch;             /* character to echo            */
        !           164:        register struct tty     *ttyp;  /* pointer to I/O block for dev */
1.1       root      165:        register struct csr     *cptr;  /* csr address for this devptr  */
                    166: {
1.1.1.2 ! root      167: #ifdef DEBUG
        !           168: /*     kprintf("echoch(%c,%x,%x)\n", ch, ttyp, cptr); */
        !           169: #endif
        !           170:        if ((ch==NEWLINE||ch==RETURN)&&ttyp->ecrlf) {
        !           171:                eputc(RETURN,ttyp,cptr);
        !           172:                eputc(NEWLINE,ttyp,cptr);
        !           173:        } else if ((ch < BLANK || ch == 0177) && ttyp->evis) {
        !           174:                eputc(UPARROW,ttyp,cptr);
        !           175:                eputc(ch+0100,ttyp,cptr);       /* make it printable    */
1.1       root      176:        } else {
1.1.1.2 ! root      177:                eputc(ch,ttyp,cptr);
1.1       root      178:        }
                    179: }
                    180: 
                    181: /*------------------------------------------------------------------------
                    182:  *  eputc - put one character in the echo queue
                    183:  *------------------------------------------------------------------------
                    184:  */
1.1.1.2 ! root      185: LOCAL eputc(ch,ttyp,cptr)
        !           186:        register char   ch;
        !           187:        register struct tty     *ttyp;
1.1       root      188:        register struct csr     *cptr;
                    189: {
1.1.1.2 ! root      190: #ifdef DEBUG
        !           191: /*     kprintf("eputc(%c,%x,%x)\n", ch, ttyp, cptr); */
        !           192: #endif
        !           193:        ttyp->ebuff[ttyp->ehead++] = ch;
        !           194:        if (ttyp->ehead >= EBUFLEN)
        !           195:                ttyp->ehead = 0;
        !           196:        slutenable(cptr);       /* restart output */
1.1       root      197: }

unix.superglobalmegacorp.com

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