]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/dos_comm.c
modified: CORE16.EXE
[16.git] / src / lib / dos_comm.c
index 371294266200becc8790e5dbc51418b0e6c05ed4..503ff6dc5ae52df075e214ca5e9cfb538e3c0590 100644 (file)
@@ -1,45 +1,48 @@
 /* Thanks to Alex Russell for example code */
 /* Thanks to Gary Neal for example code */\r
-#include "src\lib\dos_comm.h"\r
-\r
-// Q code
-byte kee;\r
-byte keer[128];        /* key pressed */
-byte keep[128];        /* key released */
+#include "src\lib\dos_comm.h"
+
+// keyboard buffer
+static byte key[NUM_SCANCODES]; // pressed
+static byte kea[NUM_SCANCODES]; // released
 
-#ifdef __cplusplus             /* Functions must be declared C style */\r
+#ifdef __cplusplus             /* Function must be declared C style */\r
 extern "C" {\r
-#endif\r
-extern void interrupt (far *oldkb)(void) = NULL; /* BIOS keyboard handler */
+#endif
+static void interrupt (far *oldkb)(void) = NULL; /* BIOS keyboard handler */
 #ifdef __cplusplus\r
 }\r
 #endif\r
 /*****************NEW KEYBOARD 09h ISR***********************/\r
-void interrupt newkb(void){\r
+void interrupt newkb(void){
+       byte kee;
        register char qx;\r
 
        kee = inp(0x60);        /* Read the keyboard scan code */
-\r
+
        /* Clear keyboard controller on XT machines */\r
-       qx = inp(0x61);\r
+       qx = inp(0x61);           /* Get keyboard control register */\r
        qx |= 0x82;\r
-       outp(0x61, qx);\r
+       outp(0x61, qx);           /* Toggle acknowledge bit high */\r
        qx &= 0x7F;\r
-       outp(0x61, qx);
+       outp(0x61, qx);           /* Toggle acknowledge bit low */
 
-       /* Interpret the scan code and set our flags */\r
+       /* Interpret the scan code and set our flags */
+//tt   printf("%d[%d]\n",kee,key[kee]);
        if(kee & 0x80)\r
-               keep[kee & 0x7F] = 0;\r
+               key[kee & 0x7F] = 0; // a key is released\r
        else\r
-               keep[kee] = keer[kee] = 1;
-\r
-       outp(0x20, 0x20);\r
+               key[kee] = kea[kee] = 1; // a key is pressed
+
+       /* Acknowledge the interrupt to the programmable interrupt controller */\r
+       outp(0x20, 0x20);      /* Signal non specific end of interrupt */\r
 }\r
 \r
 /* ---------------------- init_keyboard() ---------------- April 17,1993 */\r
 /* restore the bios keyboard handler */\r
 /* ---------------------- deinit_keyboard() -------------- April 17,1993 */\r
-void setkb(int vq){\r
+void setkb(int vq){
+       int i;  /* Index variable */\r
        if(!vq){ // deinitiation
                /* Abort if our function pointer has no valid address */\r
                if(oldkb == NULL) return;
@@ -47,23 +50,30 @@ void setkb(int vq){
                _dos_setvect(9, oldkb);
                /* Reset our function pointer to contain no valid address */\r
                oldkb = NULL;
+               /* Print the key heap */
+               printf("\n");
+               for(i=0; i<NUM_SCANCODES; i++){
+                       if(i==NUM_SCANCODES/2) printf("================================\n");
+                       printf("%03d[%d][%d]",i+1,key[i],kea[i]);
+                       if(key[i]==1)printf("====");
+                       printf(",\n");
+               }
        }else if(vq == 1){ // initiation
-               int i;  /* Index variable */
                byte far *lock_key;
 
                /* Abort if our function pointer has a valid address. */\r
                if(oldkb != NULL) return;\r
 
                /* Clear the keyboard buttons state arrays */\r
-               for(i = 0; i < 128; i++)\r
-                       keep[i] = keer[i] = 0;
+               for(i = 0; i < NUM_SCANCODES; i++)\r
+                       key[i] = kea[i] = 0;
 \r
                /* save old BIOS key board handler */\r
                oldkb = _dos_getvect(9);\r
 \r
                // turn off num-lock via BIOS\r
-               lock_key = MK_FP(0x040, 0x017); //wtf is going on here?\r
-               *lock_key&=(~(16 | 32 | 64));   // toggle off the lock keys\r
+               lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys\r
+               *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
                oldkb();        // call BIOS keyhandler to change keyboard lights\r
 
                /* setup our own handler */\r
@@ -78,24 +88,18 @@ void setkb(int vq){
  * The status is 1 if the key is pressed or has been pressed since the     *\r
  * last call to this function for that particular key.                     *\r
 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */\r
-char keyp(byte c){\r
+int keyp(byte c){\r
        register char retVal;\r
 \r
        /* Key value in range of keyboard keys available */\r
        c &= 0x7F;\r
 
        /* Get the status of the key requested */\r
-       retVal = keep[c] | keer[c];\r
+       retVal = key[c] | kea[c];\r
 \r
        /* Reset the was pressed status for the requested key */\r
-       keer[c] = 0;
+       kea[c] = 0;
 
        /* Return the requested key's state */\r
        return retVal;\r
 }\r
-
-// tesuto\r
-byte scankey(){\r
-       //if(keyp(kee)) printf("%c %03d %03x\n", kee, kee, kee);\r
-       return kee;\r
-}