home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / newemacs / keybadt.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  85 lines

  1. /* keyboard interface */
  2.  
  3. /* Copywrite Mark P. Schapira 1984,1985 */
  4.  
  5. #define keyb 0x16
  6.  
  7.  
  8. /* 8088 registers data structure */
  9. typedef struct
  10.     {
  11.     int ax;
  12.     int bx;
  13.     int cx; 
  14.     int dx;
  15.     int si;
  16.     int di;
  17.     int ds;
  18.     int es;
  19.     } regset;
  20.  
  21.  
  22.  
  23.  
  24. char get_key(rtcode) /* get next keystroke from the keyboard */
  25. int *rtcode; /* if keystroke has a corresponding ascii code then this 
  26.             contains the scan code in the high order byte and the 
  27.             ascii code in the low order byte, otherwise the low order
  28.             byte contains a zero and the high order byte contains 
  29.             the extended code  */
  30.  
  31.     {
  32.     regset r;
  33.     /* ah = 0 */
  34.     r.ax= (0<<8) ;
  35.     /* wait for user to press key */
  36.     sysint(keyb,&r,&r);
  37.     /* return the contents of the ax register to the caller */
  38.     *rtcode = r.ax;
  39.     /* the value of the function is the ascii code or zero */
  40.     return ((char) (r.ax & 0xff)) ;
  41.     }
  42.  
  43. qget_key() /* get a key if there is any keystroke lying the the keyboard 
  44.             buffer */
  45.  
  46.     {
  47.     regset r;
  48.     int rtcd;
  49.     int zroflg=0x40;
  50.     int stat; 
  51.  
  52.     /*ah=1 */
  53.     r.ax = (1<<8) ;
  54.     /* determine keyboard status */
  55.     stat = sysint(keyb,&r,&r);
  56.     /* if zro flag is set */
  57.     if ((stat & zroflg) != 0 ) 
  58.         {
  59.         /* nothing is in the keyboard buffer */
  60.         return (0);
  61.         }
  62.  
  63.     else
  64.         {
  65.         /* there is a keystroke in the keyboard buffer, retrieve it */
  66.         get_key(&rtcd);
  67.         /* and return it to the caller */
  68.         return(rtcd);
  69.         }
  70.  
  71.     }
  72.  
  73.  
  74. get_kstat() /* read keyboard status */
  75.     {
  76.     regset r;
  77.  
  78.     /* ah = 2 */
  79.     r.ax = (2<<8) ;
  80.     sysint(keyb,&r,&r) ;
  81.     /* return the keyboard status which is found in al */
  82.     return(r.ax&0xff) ;
  83.     }
  84.  
  85.