home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / KBEQUIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.0 KB  |  104 lines

  1. /**
  2. *
  3. * Name        kbequip -- Sense extended BIOS, enhanced keyboard,
  4. *               and report whether extended BIOS is selected.
  5. *
  6. * Synopsis    have_ext_bios = kbequip();
  7. *
  8. *        int have_ext_bios KB_EXTENDED if extended BIOS
  9. *                    keyboard functions available,
  10. *                  KB_NOEXTENDED if not.
  11. *
  12. * Description    This function detects the presence of the extended BIOS
  13. *        keyboard services and, if they are found, the presence
  14. *        of an Enhanced Keyboard.
  15. *
  16. * Returns    have_ext_bios      KB_EXTENDED if extended BIOS
  17. *                    keyboard functions available,
  18. *                  KB_NOEXTENDED if not.
  19. *        b_kbxten      KB_EXTENDED if extended BIOS keyboard
  20. *                    functions available,
  21. *                  KB_NOEXTENDED if not.
  22. *        b_kbnhan      KB_ENHANCED if Enhanced Keyboard
  23. *                    detected,
  24. *                  KB_NOENHANCED if not.
  25. *
  26. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  27. *
  28. **/
  29.  
  30. #include <dos.h>
  31.  
  32. #include <bkeybrd.h>
  33.  
  34. int b_kbxten = KB_NOEXTENDED; /* Presence of extended BIOS functions. */
  35.  
  36. int b_kbnhan = KB_NOENHANCED; /* Presence of enhanced keyboard.       */
  37.  
  38. int b_kbusex = KB_USE_NORMAL; /* Flag controlling whether to use      */
  39.                   /* normal or extended keyboard functions*/
  40.  
  41. typedef struct                  /* KEYPAIR:  Character and key  */
  42. {                      /* code as stored in BIOS       */
  43.     char ch;                  /* keyboard buffer.          */
  44.     char keycode;
  45. } KEYPAIR;
  46.  
  47. int kbequip()
  48. {
  49.     static int did_kbequip = 0;       /* Flag indicating whether we've*/
  50.                       /* done presence test before.   */
  51.     int i,ints_were_on;
  52.     struct                  /* Copy of BIOS keyboard buffer */
  53.     {
  54.     unsigned int head;
  55.     unsigned int tail;
  56.     KEYPAIR      queue[16];
  57.     } savebuf;
  58.     union REGS inregs,outregs;
  59.  
  60.     if (!did_kbequip)          /* Skip if we've done this before.      */
  61.     {
  62.     ints_were_on = utintflg(UT_INTOFF);    /* Prevent keystrokes */
  63.                         /* while testing.     */
  64.  
  65.                       /* Save copy of keyboard buffer */
  66.     utmovmem(KB_BUFHEADADDR,
  67.          (char far *) &savebuf,
  68.          sizeof(savebuf));
  69.  
  70.                       /* Flush the buffer.          */
  71.     utpokew(KB_BUFHEADADDR,savebuf.tail);
  72.  
  73.     inregs.x.ax = 0x05ff;          /* Stuff key sequence 0xffff    */
  74.     inregs.x.cx = 0xffff;          /* using extended function 5.   */
  75.     int86(KB_BIOS_INT,&inregs,&outregs);
  76.     utintflg(UT_INTOFF);
  77.  
  78.     if (outregs.h.al == 0)          /* Successfully stuffed?          */
  79.         for (i = 0; b_kbxten == KB_NOEXTENDED && i < 16; i++)
  80.         {
  81.         inregs.h.ah = 0x10;   /* Try extended function 0x10   */
  82.                       /* to read the data back.       */
  83.         int86(KB_BIOS_INT,&inregs,&outregs);
  84.         utintflg(UT_INTOFF);
  85.         if (outregs.x.ax == 0xffff)    /* Found the data, so */
  86.             b_kbxten = KB_EXTENDED;    /* must be extended.  */
  87.         }
  88.  
  89.     if (   b_kbxten == KB_EXTENDED
  90.         && (0x10 & utpeekb(uttofaru(KB_DATASEG,0x0096))))
  91.         b_kbnhan = KB_ENHANCED;
  92.  
  93.                       /* Restore keyboard buffer.     */
  94.     utmovmem((char far *) &savebuf,
  95.          KB_BUFHEADADDR,
  96.          sizeof(savebuf));
  97.  
  98.     did_kbequip = 1;          /* Prevent repeated tests.      */
  99.     utintflg(ints_were_on);
  100.     }
  101.  
  102.     return b_kbxten;
  103. }
  104.