home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12044a < prev    next >
Text File  |  1990-10-15  |  4KB  |  123 lines

  1. /*
  2.  *  CHAR.C
  3.  *
  4.  *  main interrupt routine; also keyboard read routine
  5.  */
  6.  
  7. #include    "char.h"
  8.  
  9. /*-------- Prototypes ---------*/
  10.  
  11.                 /* handle init call */
  12. extern void char_init (void);
  13.                 /* look up key code for reassignment */
  14. extern char *k_seek (void);
  15.                 /* read the keyboard */
  16. extern void rawread (void);
  17.                 /* see if char is available at the keyboard */
  18. extern int  rawstat (void);
  19.                 /* write byte into ring buffer */
  20. extern void r_write (char);
  21.                 /* write character to screen */
  22. extern void w_putc (void);
  23.  
  24. /*
  25.  *  rd_getc()
  26.  *
  27.  *  rd_getc() reads a character from the keyboard, hanging until
  28.  *  there is one.  If the character has been reassigned, copy the
  29.  *  reassignment buffer into the ring buffer.  Otherwise, write
  30.  *  the character itself (with leading nul byte for extended
  31.  *  keys) into the ring buffer
  32.  */
  33.  
  34. void    rd_getc()
  35.     {
  36.     if (r_index == w_index)
  37.         {
  38.         rawread();
  39.         if (k_seek())
  40.             {
  41.             for (k = 0; k < *len; k++)
  42.                 r_write(*ptr++);
  43.             }
  44.         else
  45.             {
  46.             if (keycheck & 0177400)
  47.                 r_write(0);
  48.             r_write(((char) keycheck) & 0000377);
  49.             }
  50.         }
  51.     }
  52.  
  53. /*
  54.  *  interrupt()
  55.  *
  56.  *  interrupt() takes care of the commands as they come in from
  57.  *  the request header.  Of all the commands, only the device
  58.  *  initialization call is a separate function; this reduces
  59.  *  stack overhead.  char_init() is a separate function, alone in
  60.  *  its own module, so that it can report its own address as the
  61.  *  end of the driver.
  62.  */
  63.  
  64. void    interrupt()
  65.     {
  66.     count = rh->count;
  67.     transfer = rh->transfer;
  68.     switch (rh->command)
  69.         {
  70.         case    0:      /* initialization */
  71.             char_init();
  72.             break;
  73.         case    4:      /* read */
  74.             while (count)
  75.                 {
  76.                 rd_getc();
  77.                 *transfer++ = r_buf[ r_index++ ] & 000377;
  78.                 r_index &= RLIMIT;
  79.                 count--;
  80.                 }
  81.             rh->status = DONE;
  82.             break;
  83.         case    5:      /* non-destructive read */
  84.             if (r_index == w_index)
  85.                 {
  86.                 if (!rawstat())
  87.                     {
  88.                     rh->status = BUSY | DONE;
  89.                     break;
  90.                     }
  91.                 rd_getc();
  92.                 }
  93.             rh->status = DONE;
  94.             rh->data = r_buf[ r_index ];
  95.             break;
  96.         case    7:      /* flush input buffers */
  97.             r_index = w_index = 0;
  98.             while (rawstat())
  99.                 rawread();
  100.             rh->status = DONE;
  101.             break;
  102.         case    8:      /* write */
  103.         case    9:      /* write with verify */
  104.             while (count)
  105.                 {
  106.                 outchar = *transfer++;
  107.                 w_putc();
  108.                 count--;
  109.                 }
  110.         case    1:      /* media check */
  111.         case    2:      /* build parameter block */
  112.         case    6:      /* input status */
  113.         case    10:     /* output status */
  114.         case    11:     /* flush output buffers */
  115.             rh->status = DONE;
  116.             break;
  117.         case    3:      /* ioctl read */
  118.         default:
  119.             rh->status = UNKNOWN_COMMAND | ERROR | DONE;
  120.             break;
  121.         }
  122.     }
  123.