The file kbstf10.zip contains some keyboard utilities by Luigi Mancinelli. KBSTUFF.C KBSTUFF.COM KBSTUFFR.C KBSTUFFR.COM SEEKBBUF.C SEEKBBUF.COM KBSTFRES\KBSTFRES.ASM KBSTFRES\KBSTFRES.COM DISKBD\DISKBD.ASM DISKBD\DISKBD.COM DISKBD\UNINSTKL.C DISKBD\UNINSTKL.COM KBRESDIS\KBRESDIS.ASM KBRESDIS\KBRESDIS.COM KBRESDIS\KBDOSRES.C KBRESDIS\KBDOSRES.COM README.TXT -- This file The C sources are written for Borland Turbo C 2.0 and could require even a lot of work to be compiled with different versions of C. They are plain C and maybe could be easily translated in assembler, because they don't use tipical C functions. The asm programs are written to be assembled with the exclusive use of the DOS Debug and they are not easily converted to masm sources. The shareware program A86 of Eric Isaacson can be used instead. The philosophy I've adopted is to create very short TSRs, with a minimal initialization code, and to delegate the most of work to C programs that communicate with the TSRs. This is possible complying, for TSRs that trap interrupts, with the IBM's INTERRUPT sharing protocol. Thanks a lot to Chris Dunford for posting informations about IBM's INTERRUPT-SHARING PROTOCOL. +++++++++++++++++++++++++ SEEKBBUF.C - SEEKBBUF.COM This program can be used to inspect the keyboard buffer used by the the standard INT 9h handler, which is a circular buffer of 2-bytes words. The buffer must reside in the BIOS data segment (040h:0). At offset 80h must be found the offset of the first byte of the buffer, at 82h there should be the offset of the first byte after the buffer. This should be standard,but could happen that old BIOSes don't comply with this. Syntax: SEEKBBUF Press to exit from program. (c) 1996 by Luigi Mancinelli manci@alpha.science.unitn.it +++++++++++++++++++++++ KBSTUFF.C - KBSTUFF.COM This program stuffs the standard keyboard buffer, which is a circu- lar buffer of 2-bytes words. This 2-bytes words are in general formed by the ASCII translation in the low byte and the scan code in the high byte. Extended characters could have an ASCII translation of 0 or E0 (for the extended 101/102 keys keyboards) or F0 (other extended chars). You can inspect keys stored in the keyboard buffer from the standard INT 9h handler with the program SEEKBBUF.COM (with Turbo-c source). The way to use KBSTUFF is simple for c programmers. syntax: KBSTUFF [/R] /R Option. If present must be the first parameter, other- wise is interpreted as two characters to store. Reset the keyboard's buffer. are the characters to store in the buffer. Blanks and tabs are generally skipped, but you can use a C-type string, as, for example, "pippo a:\r" "\r\n\t\aError in C:\\work\r\n" "\76\xFDThis are octal and hexadecimal notation\?" \OOO and \xHHH are accepted as for ANSI C, but if the value of FFh is exceeded only the low byte is conside- red and the high is stripped. With this "normal" use only ASCII translation are sto- red, without scan code, as the keys would have been ge- nerated with the ALT-key+Keypad numbers combination. My extensions to C-string allow to store extended keys with a low byte of 0. To store the word 6800h, for example, many methods can be used: "\0\x68","\ex68" (where the escape sequence \e is an extension to the standard C-string syntax), "\0h" or "\eh" (where ascii('h')=0x68) The x is used as an escape character for the \e escape sequence, so if 7800h(=) has to be stored can be used: "\ex78","\0\x78","\0x" or "\exx" (c) 1996 by Luigi Mancinelli manci@alpha.science.unitn.it Note: If the program has to be recompiled, the tiny model has to be used and the resulting .exe has to be converted in .com (with the DOS utility EXE2BIN for example) or the program doesn't work. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ KBSTUFFR.C - KBSTUFFR.COM == KBSTFRES.ASM - KBSTFRES.COM The little assembly TSR KBSTFRES.COM hooks INT 1Ch (user interrupt), complying with IBM's INTERRUPT-SHARING PROTOCOL and stuffs the key- board buffer with the 2-bytes words it finds in his internal buffer. This 2-bytes words are in general formed by the ASCII translation in the low byte and the scan code in the high byte. Extended characters could have an ASCII translation of 0 or E0 (for the extended 101/102 keys keyboards) or F0 (other extended chars). You can inspect keys stored in the keyboard buffer from the standard INT 9h handler with the program SEEKBBUF.COM (with Turbo-c source). A word with value 0 shouldn't never be generated by standard INT 9h handler and so the TSR interprets a 0 in his buffer as a request of a pause, and the following word represent for it the number of clock- ticks to wait. A 0 as number of ticks is interpreted as 65536. Even a word with the high byte equals to 0xFF should never be gene- rated by the standard INT 9h handler and so the TSR interprets this as a "short pause", the low byte representing the number of thicks, 0 interpreted again as 65536. The KBSTFRES.COM's buffer is a circular buffer similarly to the key- board buffer, but it's bigger and could be made even bigger, alloca- ting memory, even if the TSR is already installed. The KBSTFRES.COM's companion program KBSTUFFR.COM is used to store keys in the TSR's buffer. It could be even used as a scheme for ad- ding other options as allocating another buffer. The way to use KBSTUFFR is simple for c programmers. syntax: KBSTUFFR [/R] [/U] [/G] [/S] /R Option. If present must be the first parameter, other- wise is interpreted as two characters to store. Reset the TSR's buffer. /U Option. If present must be the first parameter, other- wise is interpreted as two characters to store. Whatever follow this option is obviously ignored. Uninstall the TSR and remove it from memory. /R and /U options are mutually excluding. Both must be the first option. The use of both is, however, a nonsense. /S Stops the TSR. |_ Can appear anywhere outside of /G Restarts the TSR. | C-strings are the characters to store in the buffer. Blanks and tabs are generally skipped, but you can use a C-type string, as, for example, "pippo a:\r" "\r\n\t\aError in C:\\work\r\n" "\76\xFDThis are octal and hexadecimal notation\?" \OOO and \xHHH are accepted as for ANSI C, but if the value of FFh is exceeded only the low byte is conside- red and the high is stripped. With this "normal" use only ASCII translation are sto- red, without scan code, as the keys would have been ge- nerated with the ALT-key+Keypad numbers combination. My extensions to C-string allow to store extended keys with a low byte of 0 and special pause sequences. To store the word 6800h, for example, many methods can be used: "\0\x68","\ex68" (where the escape sequence \e is an extension to the standard C-string syntax), "\0h" or "\eh" (where ascii('h')=0x68) The x is used as an escape character for the \e escape sequence, so if 7800h(=) has to be stored can be used: "\ex78","\0\x78","\0x" or "\exx" To store a pause, the other extension "\pDDDDD" has to be used where DDDDD is a decimal number. If only "\p" or "\p0" is entered the pause is set to the default of 1 clock-tick. (c) 1996 by Luigi Mancinelli manci@alpha.science.unitn.it Note: If the program has to be recompiled, the tiny model has to be used and the resulting .exe has to be converted in .com (with the DOS utility EXE2BIN for example) or the program doesn't work. ++++++++++++++++++++++++++++++++++++++++++++++++++++ UNINSTKL.C - UNINSTKL.COM == DISKBD.ASM - DISKBD.COM The little assembly TSR DISKBD.COM hooks INT 09h (keyb. interrupt), complying with IBM's INTERRUPT-SHARING PROTOCOL and disables the key- board accepting only the combination , which allows to toggle between keyboard enabled and disabled. Why one could use a similar program? For example to disable keyboard during execution of batch file, or when a keyboard stuffer, like the combination of KBSTFRES.COM and KBSTUFFR, is used and the user input is desired to be temporarily disabled. In both cases disabling and enabling keyboard should be possible from a batch file to be really useful. This is what this program does, allowing to change the state of the previously loaded TSR and even to uninstalling it (supposing that no not IBM's ISP compliant TSR are loaded after it). syntax: UNINSTKL /U uninstall DISKBD.COM TSR from interrupt chain of inter- rupt 09h and remove it from memory. UNINSTKL /E enable keyboard. UNINSTKL /D disable keyboard. (c) 1996 by Luigi Mancinelli manci@alpha.science.unitn.it Note: If the program has to be recompiled, the tiny model has to be used and the resulting .exe has to be converted in .com (with the DOS utility EXE2BIN for example) or the program doesn't work. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ KBDOSRES.C - KBDOSRES.COM == KBRESDIS.ASM - KBRESDIS.COM The little assembly TSR KBRESDIS.COM hooks INT 21h (dos functions), complying with IBM's INTERRUPT-SHARING PROTOCOL, and traps the dos function AH=0Ch, function that resets the keyboard and, eventually, call a keyboard function. Many programs use this to prevent charac- ters stored in the keyboard buffer are used and to force a wait for a user input. For example dos format does it when asks user to confirm an hard disk format request. When you are creating complex batch files that use keyboard buffer stuffing this could be useful. The companion program KBDOSRES allows to toggle the state of the TSR between "trap" and "don't trap" and allows to uninstall the TSR too. syntax: KBSTUFFR /U uninstalls the TSR. KBSTUFFR /P[0|1] disables trapping (0) or enables it (1 and default) (c) 1996 by Luigi Mancinelli manci@alpha.science.unitn.it Note: If the program has to be recompiled, the tiny model has to be used and the resulting .exe has to be converted in .com (with the DOS utility EXE2BIN for example) or the program doesn't work. =========================================================================== LICENCE ------- The files here included can be freely distributed, provided that they're distributed together, without stripping copyright informations and without any change (I'd like to get blame for my own errors and credit only where it is due - as Chris Dun- ford says). Commercial use couldn't be done without contact the author. (c) 1996 by Luigi Mancinelli E-Mail: manci@alpha.science.unitn.it Post : Luigi Mancinelli c/o Laboratori Didattici Facolt… di Scienze Universit… degli Studi di Trento 38050 POVO-TRENTO (TN) ITALY