1 /* Thanks to Alex Russell for example code */
2 /* Thanks to Gary Neal for example code */
\r
3 #include "src\lib\dos_comm.h"
6 static byte key[NUM_SCANCODES]; // pressed
7 static byte kea[NUM_SCANCODES]; // released
9 #ifdef __cplusplus /* Function must be declared C style */
\r
12 static void interrupt (far *oldkb)(void) = NULL; /* BIOS keyboard handler */
16 /*****************NEW KEYBOARD 09h ISR***********************/
\r
17 void interrupt newkb(void){
21 kee = inp(0x60); /* Read the keyboard scan code */
23 /* Clear keyboard controller on XT machines */
\r
24 qx = inp(0x61); /* Get keyboard control register */
\r
26 outp(0x61, qx); /* Toggle acknowledge bit high */
\r
28 outp(0x61, qx); /* Toggle acknowledge bit low */
30 /* Interpret the scan code and set our flags */
32 printf("%d[%d]\n",kee,key[kee]);
34 key[kee & 0x7F] = 0; // a key is released
\r
36 key[kee] = kea[kee] = 1; // a key is pressed
38 /* Acknowledge the interrupt to the programmable interrupt controller */
\r
39 outp(0x20, 0x20); /* Signal non specific end of interrupt */
\r
42 /* ---------------------- init_keyboard() ---------------- April 17,1993 */
\r
43 /* restore the bios keyboard handler */
\r
44 /* ---------------------- deinit_keyboard() -------------- April 17,1993 */
\r
46 int i; /* Index variable */
\r
47 if(!vq){ // deinitiation
48 /* Abort if our function pointer has no valid address */
\r
49 if(oldkb == NULL) return;
50 /* Set address in our function pointer in interrupt vector table */
51 _dos_setvect(9, oldkb);
52 /* Reset our function pointer to contain no valid address */
\r
54 /* Print the key heap */
56 for(i=0; i<NUM_SCANCODES; i++){
57 if(i==NUM_SCANCODES/2) printf("================================\n");
58 printf("%03d[%d][%d]",i+1,key[i],kea[i]);
59 if(key[i]==1)printf("====");
62 }else if(vq == 1){ // initiation
65 /* Abort if our function pointer has a valid address. */
\r
66 if(oldkb != NULL) return;
\r
68 /* Clear the keyboard buttons state arrays */
\r
69 for(i = 0; i < NUM_SCANCODES; i++)
\r
72 /* save old BIOS key board handler */
\r
73 oldkb = _dos_getvect(9);
\r
75 // turn off num-lock via BIOS
\r
76 lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
\r
77 *lock_key&=(~(16 | 32 | 64)); // toggle off the locks by changing the values of the 4th, 5th, and 6th bits of the address byte of 0040:0017
\r
78 oldkb(); // call BIOS keyhandler to change keyboard lights
\r
80 /* setup our own handler */
\r
81 _dos_setvect(9, newkb);
\r
85 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
\r
88 * Returns the status of the key requested. *
\r
89 * The status is 1 if the key is pressed or has been pressed since the *
\r
90 * last call to this function for that particular key. *
\r
91 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
\r
93 register char retVal;
\r
95 /* Key value in range of keyboard keys available */
\r
98 /* Get the status of the key requested */
\r
99 retVal = key[c] | kea[c];
\r
101 /* Reset the was pressed status for the requested key */
\r
104 /* Return the requested key's state */
\r