home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / KEYBOARD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  3.0 KB  |  151 lines

  1. //    Zinc Interface Library - KEYBOARD.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #pragma inline
  6.  
  7. #include "ui_evt.hpp"
  8. #include <dos.h>
  9.  
  10. int UI_BIOS_KEYBOARD::breakHandlerSet = FALSE;
  11.  
  12. int enhancedBiosFlag;
  13.  
  14. static int CheckEnhancedBios()
  15. {
  16.     asm {
  17.         mov        ah, 5
  18.         mov        cx, 0FFFFH
  19.         int        16H
  20.         or        al, al
  21.         jnz        NotEnhanced
  22.  
  23.         mov        cx, 16
  24.     }
  25.  
  26. readLoop:
  27.     asm {
  28.         push    cx
  29.         mov        ah, 10H
  30.         int        16H
  31.         pop        cx
  32.         cmp        ax, 0FFFFH
  33.         je        EnhancedKeyboard
  34.  
  35.         loop    readLoop
  36.     }
  37.  
  38. NotEnhanced:
  39.     return (0x00);
  40.  
  41. EnhancedKeyboard:
  42.     return (0x10);
  43. }
  44.  
  45. static int KeystrokeWaiting()
  46. {
  47.     _AH = 1 + enhancedBiosFlag;
  48.     geninterrupt(0x16);
  49.     asm        jz    no_key
  50.  
  51.     return (TRUE);
  52. no_key:
  53.     return (FALSE);
  54. }
  55.  
  56. UI_BIOS_KEYBOARD::UI_BIOS_KEYBOARD(USHORT initialState) :
  57.     UI_DEVICE(E_KEY, initialState)
  58. {
  59.     /* Initialize the keyboard device */
  60.     installed = TRUE;
  61.     enhancedBiosFlag = enhancedBIOS = CheckEnhancedBios();
  62.     _AX = 0x3300;
  63.     geninterrupt(0x21);            // Get state of Control-Break checking
  64.     breakState = _DL;            // and save it
  65.     if (!breakHandlerSet)
  66.     {
  67.         breakHandlerSet = TRUE;
  68.         asm    {
  69.             push    ds
  70.             lea        dx, IntRet
  71.             push    cs
  72.             pop        ds
  73.             mov        ax, 2523H
  74.             int        21H
  75.             pop        ds
  76.             jmp        short SetDone
  77.  
  78. IntRet:        iret                // Note: this produces a warning, but works OK.
  79.         }
  80.  
  81. SetDone:;
  82.     }
  83.     _DL = 0;
  84.     _AX = 0x3301;
  85.     geninterrupt(0x21);            // Now disable Control-Break handling
  86. }
  87.  
  88. UI_BIOS_KEYBOARD::~UI_BIOS_KEYBOARD()
  89. {
  90.     _DL = breakState;            // Restore original break checking state.
  91.     _AX = 0x3301;
  92.     geninterrupt(0x21);
  93. }
  94.  
  95. void UI_BIOS_KEYBOARD::Poll()
  96. {
  97.     /* See if a keystroke is already waiting */
  98.     if (!KeystrokeWaiting())
  99.     {
  100.         // Check the ALT key at the BIOS level.
  101.         UCHAR shiftState = *((UCHAR far *) 0x417L) & 0xFF;
  102.         if ( FlagSet(shiftState, S_ALT) && altPressed == ALT_NOT_PRESSED )
  103.             altPressed = ALT_PRESSED_AND_NO_EVENTS_YET;
  104.         else if ( !FlagSet(shiftState, S_ALT) )
  105.         {
  106.             if (altPressed == ALT_PRESSED_AND_NO_EVENTS_YET)
  107.             {
  108.                 UI_EVENT event;
  109.                 event.rawCode = 0;
  110.                 event.key.value = 0;
  111.                 event.key.shiftState = 0;
  112.                 event.type = S_ALT_KEY;
  113.                 if (state != D_OFF)
  114.                     eventManager->Put(event, Q_END);
  115.             }
  116.             altPressed = ALT_NOT_PRESSED;
  117.         }
  118.         return;
  119.     }
  120.  
  121.     /* Set the key information and call the event manager */
  122.     if (altPressed == ALT_PRESSED_AND_NO_EVENTS_YET)
  123.         altPressed = ALT_PRESSED_AND_EVENTS_RECEIVED;
  124.     UI_EVENT event;
  125.     _AH = enhancedBIOS;
  126.     geninterrupt(0x16);
  127.     event.rawCode = _AX;
  128.     event.key.value = _AL;
  129.     event.key.shiftState = *((UCHAR far *) 0x417L) & 0xFF;
  130.     event.type = E_KEY;
  131.     if (enabled && eventManager)
  132.         eventManager->Put(event, Q_END);
  133. }
  134.  
  135. int UI_BIOS_KEYBOARD::Event(const UI_EVENT &event)
  136. {
  137.     /* Switch on the rawCode */
  138.     switch (event.rawCode)
  139.     {
  140.     case D_OFF:
  141.     case D_ON:
  142.         state = event.rawCode;
  143.         enabled = (event.rawCode == D_OFF) ? FALSE : TRUE;
  144.         break;
  145.     }
  146.  
  147.     /* Return the keyboard state */
  148.     return (state);
  149. }
  150.  
  151.