home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name kbequip -- Sense extended BIOS, enhanced keyboard,
- * and report whether extended BIOS is selected.
- *
- * Synopsis have_ext_bios = kbequip();
- *
- * int have_ext_bios KB_EXTENDED if extended BIOS
- * keyboard functions available,
- * KB_NOEXTENDED if not.
- *
- * Description This function detects the presence of the extended BIOS
- * keyboard services and, if they are found, the presence
- * of an Enhanced Keyboard.
- *
- * Returns have_ext_bios KB_EXTENDED if extended BIOS
- * keyboard functions available,
- * KB_NOEXTENDED if not.
- * b_kbxten KB_EXTENDED if extended BIOS keyboard
- * functions available,
- * KB_NOEXTENDED if not.
- * b_kbnhan KB_ENHANCED if Enhanced Keyboard
- * detected,
- * KB_NOENHANCED if not.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
-
- #include <dos.h>
-
- #include <bkeybrd.h>
-
- int b_kbxten = KB_NOEXTENDED; /* Presence of extended BIOS functions. */
-
- int b_kbnhan = KB_NOENHANCED; /* Presence of enhanced keyboard. */
-
- int b_kbusex = KB_USE_NORMAL; /* Flag controlling whether to use */
- /* normal or extended keyboard functions*/
-
- typedef struct /* KEYPAIR: Character and key */
- { /* code as stored in BIOS */
- char ch; /* keyboard buffer. */
- char keycode;
- } KEYPAIR;
-
- int kbequip()
- {
- static int did_kbequip = 0; /* Flag indicating whether we've*/
- /* done presence test before. */
- int i,ints_were_on;
- struct /* Copy of BIOS keyboard buffer */
- {
- unsigned int head;
- unsigned int tail;
- KEYPAIR queue[16];
- } savebuf;
- union REGS inregs,outregs;
-
- if (!did_kbequip) /* Skip if we've done this before. */
- {
- ints_were_on = utintflg(UT_INTOFF); /* Prevent keystrokes */
- /* while testing. */
-
- /* Save copy of keyboard buffer */
- utmovmem(KB_BUFHEADADDR,
- (char far *) &savebuf,
- sizeof(savebuf));
-
- /* Flush the buffer. */
- utpokew(KB_BUFHEADADDR,savebuf.tail);
-
- inregs.x.ax = 0x05ff; /* Stuff key sequence 0xffff */
- inregs.x.cx = 0xffff; /* using extended function 5. */
- int86(KB_BIOS_INT,&inregs,&outregs);
- utintflg(UT_INTOFF);
-
- if (outregs.h.al == 0) /* Successfully stuffed? */
- for (i = 0; b_kbxten == KB_NOEXTENDED && i < 16; i++)
- {
- inregs.h.ah = 0x10; /* Try extended function 0x10 */
- /* to read the data back. */
- int86(KB_BIOS_INT,&inregs,&outregs);
- utintflg(UT_INTOFF);
- if (outregs.x.ax == 0xffff) /* Found the data, so */
- b_kbxten = KB_EXTENDED; /* must be extended. */
- }
-
- if ( b_kbxten == KB_EXTENDED
- && (0x10 & utpeekb(uttofaru(KB_DATASEG,0x0096))))
- b_kbnhan = KB_ENHANCED;
-
- /* Restore keyboard buffer. */
- utmovmem((char far *) &savebuf,
- KB_BUFHEADADDR,
- sizeof(savebuf));
-
- did_kbequip = 1; /* Prevent repeated tests. */
- utintflg(ints_were_on);
- }
-
- return b_kbxten;
- }