1 /* Thanks to Alex Russell for example code */
2 /* Thanks to Gary Neal for example code */
6 static byte key[NUM_SCANCODES]; // pressed
7 static byte kea[NUM_SCANCODES]; // released
9 #ifdef __cplusplus /* Function must be declared C style */
12 static void interrupt (far *oldkb)(void) = NULL; /* BIOS keyboard handler */
18 * Comment out the following #define if you don't want the testing main()
23 /*****************NEW KEYBOARD 09h ISR***********************/
24 void interrupt newkb(void){
28 kee = inp(0x60); /* Read the keyboard scan code */
30 /* Clear keyboard controller on XT machines */
31 qx = inp(0x61); /* Get keyboard control register */
33 outp(0x61, qx); /* Toggle acknowledge bit high */
35 outp(0x61, qx); /* Toggle acknowledge bit low */
37 /* Interpret the scan code and set our flags */
39 printf("%d[%d]\n",kee,key[kee]);
42 key[kee & 0x7F] = 0; // a key is released
44 key[kee] = kea[kee] = 1; // a key is pressed
46 /* Acknowledge the interrupt to the programmable interrupt controller */
47 outp(0x20, 0x20); /* Signal non specific end of interrupt */
50 /* ---------------------- init_keyboard() ---------------- April 17,1993 */
51 /* restore the bios keyboard handler */
52 /* ---------------------- deinit_keyboard() -------------- April 17,1993 */
54 int i; /* Index variable */
55 if(!vq){ // deinitiation
56 /* Abort if our function pointer has no valid address */
57 if(oldkb == NULL) return;
58 /* Set address in our function pointer in interrupt vector table */
59 _dos_setvect(9, oldkb);
60 /* Reset our function pointer to contain no valid address */
63 /* Print the key heap */
65 for(i=0; i<NUM_SCANCODES; i++){
66 if(i==NUM_SCANCODES/2) printf("================================\n");
67 printf("%03d[%d][%d]",i+1,key[i],kea[i]);
68 if(key[i]==1)printf("====");
72 }else if(vq == 1){ // initiation
75 /* Abort if our function pointer has a valid address. */
76 if(oldkb != NULL) return;
78 /* Clear the keyboard buttons state arrays */
79 for(i = 0; i < NUM_SCANCODES; i++)
82 /* save old BIOS key board handler */
83 oldkb = _dos_getvect(9);
85 // turn off num-lock via BIOS
86 lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
87 *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
88 oldkb(); // call BIOS keyhandler to change keyboard lights
90 /* setup our own handler */
91 _dos_setvect(9, newkb);
95 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
98 * Returns the status of the key requested. *
99 * The status is 1 if the key is pressed or has been pressed since the *
100 * last call to this function for that particular key. *
101 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
103 register char retVal;
105 /* Key value in range of keyboard keys available */
108 /* Get the status of the key requested */
109 retVal = key[c] | kea[c];
111 /* Reset the was pressed status for the requested key */
114 /* Return the requested key's state */
120 * The library testing routines follows below.
126 * Library test (program) entry point.