home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / keyboard / inkey.arc / INKEY.C next >
Text File  |  1983-09-25  |  3KB  |  81 lines

  1. /*
  2.     .title inkey
  3. ;+
  4. ; index Read character from the keyboard
  5. ;
  6. ; usage
  7. ;    int inkey(&chara, &scancode, nowait)
  8. ;
  9. ; in
  10. ;       int nowait;
  11. ;
  12. ; out
  13. ;     char chara;
  14. ;    int  scancode;
  15. ;
  16. ; Description
  17. ;
  18. ;    this function reads the keyboard. The read can be wait or
  19. ;    nowait. With wait I/O a key is always read and the function always
  20. ;    returns with a true value. With no-wait if no key was pressed the
  21. ;    function would return with a false value. If a key is pressed in
  22. ;    no-wait mode, a wait read with guaranteed success is issued to
  23. ;    make sure that the keyboard buffer is updated accordingly.
  24. ;
  25. ;    When a key is read, a character code in character form , and a scan
  26. ;    code in int form is returned. See the Technical Reference Manual
  27. ;    pages 2-16 thru 2-17, and Appendix C for the codes. For the function
  28. ;    keys and sometimes the numeric key pad, there may not be a character
  29. ;    code returned, the value inserted is the null character, or 0
  30. ;
  31. ; status
  32. ;
  33. ; bugs
  34. ;
  35. ; updates
  36. ;    Date    Vers    Who    Description
  37. ;    8/31/83 0001    CMC    Initial version
  38. ;
  39. ;
  40. ;   Communications Programming Inc.
  41. ;   C. M. Cheng 8/83
  42. ;-
  43. */
  44.  
  45. #include "csig.h"
  46.  
  47. int inkey(chara, scancode, nowait)
  48.  
  49. char *chara;
  50. int *scancode, nowait;
  51.  
  52. {
  53.  
  54.     int intnum;                             /* INTERRUPT NUMBER */
  55.     int al, ah, flg;                       /* WORK VARIABLES */
  56.     int inreg[4], outreg[4];                /* I/O REGISTERS */
  57.     char *cax;
  58.  
  59.     if (nowait == 0)
  60.        { al = 0; ah = 0; }
  61.      else
  62.        { al = 0, ah = 1; }
  63.     inreg[0] = (ah << 8) + al;              /* FORMULATE AX */
  64.     intnum = 22;                            /* FOR KEYNOARD */
  65.                                             /*   INTERRUPT CALL */
  66.     flg = sysint(intnum, &inreg, &outreg);
  67.     if ( (nowait != 0) &&                   /* NOTHING AVAIL. ON */
  68.          ( (flg & zf) != 0) )               /*   NOWAIT I/O */
  69.           return(false);
  70.     if (nowait != 0)                        /* SOMETHING THERE ON */
  71.        {                                    /*    NOWAIT I/O, USE   */
  72.           inreg[0] = 0;                     /*    WAIT I/O TO READ  */
  73.           flg = sysint(intnum, &inreg, &outreg );  /*  IT FOR SYSTEM   */
  74.        }                                    /*    POINTER SAKE      */
  75.     cax = &outreg[0];
  76.     *chara = *cax;
  77.     *scancode = outreg[0] >> 8;
  78.     return(true);
  79. }
  80.  
  81.