home *** CD-ROM | disk | FTP | other *** search
- /* keyboard interface */
-
- /* Copywrite Mark P. Schapira 1984,1985 */
-
- #define keyb 0x16
-
-
- /* 8088 registers data structure */
- typedef struct
- {
- int ax;
- int bx;
- int cx;
- int dx;
- int si;
- int di;
- int ds;
- int es;
- } regset;
-
-
-
-
- char get_key(rtcode) /* get next keystroke from the keyboard */
- int *rtcode; /* if keystroke has a corresponding ascii code then this
- contains the scan code in the high order byte and the
- ascii code in the low order byte, otherwise the low order
- byte contains a zero and the high order byte contains
- the extended code */
-
- {
- regset r;
- /* ah = 0 */
- r.ax= (0<<8) ;
- /* wait for user to press key */
- sysint(keyb,&r,&r);
- /* return the contents of the ax register to the caller */
- *rtcode = r.ax;
- /* the value of the function is the ascii code or zero */
- return ((char) (r.ax & 0xff)) ;
- }
-
- qget_key() /* get a key if there is any keystroke lying the the keyboard
- buffer */
-
- {
- regset r;
- int rtcd;
- int zroflg=0x40;
- int stat;
-
- /*ah=1 */
- r.ax = (1<<8) ;
- /* determine keyboard status */
- stat = sysint(keyb,&r,&r);
- /* if zro flag is set */
- if ((stat & zroflg) != 0 )
- {
- /* nothing is in the keyboard buffer */
- return (0);
- }
-
- else
- {
- /* there is a keystroke in the keyboard buffer, retrieve it */
- get_key(&rtcd);
- /* and return it to the caller */
- return(rtcd);
- }
-
- }
-
-
- get_kstat() /* read keyboard status */
- {
- regset r;
-
- /* ah = 2 */
- r.ax = (2<<8) ;
- sysint(keyb,&r,&r) ;
- /* return the keyboard status which is found in al */
- return(r.ax&0xff) ;
- }
-
-