|
|
1.1 root 1: /* ttyread.c - ttyread, readcopy */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <tty.h>
6: #include <io.h>
7:
8: /*------------------------------------------------------------------------
9: * ttyread - read one or more characters from a tty device
10: *------------------------------------------------------------------------
11: */
12: ttyread(devptr, buff, count)
1.1.1.2 ! root 13: struct devsw *devptr;
! 14: int count;
! 15: char *buff;
1.1 root 16: {
1.1.1.2 ! root 17: register struct tty *ttyp;
! 18: int avail, numread;
1.1 root 19:
1.1.1.2 ! root 20: #ifdef DEBUG
! 21: dotrace("ttyread", &devptr, 3);
! 22: #endif
1.1 root 23: if (count < 0)
24: return(SYSERR);
1.1.1.2 ! root 25: disable();
! 26:
! 27: avail = scount( (ttyp= &tty[devptr->dvminor])->isem );
! 28: if ( (count = (count==0 ? avail : count)) == 0) {
! 29: restore();
! 30: return(0);
1.1 root 31: }
1.1.1.2 ! root 32: numread = count;
! 33: if (avail >= count) {
! 34: readcopy(buff, ttyp, count);
! 35: restore();
! 36: return(numread);
1.1 root 37: }
1.1.1.2 ! root 38: if (avail > 0) {
! 39: readcopy(buff, ttyp, avail);
! 40: buff += avail;
! 41: count -= avail;
1.1 root 42: }
1.1.1.2 ! root 43: restore();
! 44: for ( ; count>0 ; count--)
! 45: *buff++ = ttygetc(devptr);
! 46: return(numread);
! 47: }
! 48:
! 49: /*------------------------------------------------------------------------
! 50: * readcopy - high speed copy procedure used by ttyread
! 51: *------------------------------------------------------------------------
! 52: */
! 53: LOCAL readcopy(buff,ttyp,count)
! 54: register char *buff;
! 55: struct tty *ttyp;
! 56: int count;
! 57: {
! 58: register char *qtail, *qend, *uend; /* copy loop variables */
! 59:
! 60: qtail = &ttyp->ibuff[ttyp->itail];
! 61: qend = &ttyp->ibuff[IBUFLEN];
! 62: uend = buff + count;
! 63: while ( buff < uend ) {
! 64: *buff++ = *qtail++;
! 65: if ( qtail >= qend )
! 66: qtail = ttyp->ibuff;
1.1 root 67: }
1.1.1.2 ! root 68: ttyp->itail = qtail-ttyp->ibuff;
! 69: sreset(ttyp->isem, scount(ttyp->isem)-count);
1.1 root 70: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.