home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / LED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-15  |  1.6 KB  |  80 lines

  1. /*
  2.  
  3.     led.c
  4.  
  5.     Internet: alexad3@icebox.iceonline.com
  6.     Copyright 1995, January 15 by Alec Russell, NO rights reserved
  7.  
  8.     Created - 1995/1/15
  9.  
  10.     History:
  11.         New file
  12.  
  13.    code fragments to turn on the LED lights.
  14.    Your program would have to track the status of all lights
  15.    and send the correct bits instead of just CAPLOCK
  16.  
  17.    ONLY use this code in an int 9 replacement.
  18.    If the BIOS keyboard handler is running,
  19.    just set the bit mask in BIOS data area.
  20.  
  21. */
  22.  
  23.  
  24.  
  25.  
  26. /* keyboard controller and LED lights stuff */
  27. #define KEYSTATUS 0x64
  28. #define KEYDATA  0x60
  29. #define LEDUPDATE 0xed
  30. #define OB_FULL 1
  31. #define IB_FULL 2
  32. #define KEY_ACK 0xfa
  33.  
  34. /* bit masks to be sent */
  35. #define SCROLLOCK 1
  36. #define NUMLOCK 2
  37. #define CAPLOCK 4
  38.  
  39.  
  40. /* ---------------------- send_keycontrol() ------------ January 15,1995 */
  41. short send_keycontrol(BYTE v)
  42. {
  43.    short count, err=1;
  44.    BYTE c;
  45.  
  46.    for ( count=0; count < 3; count++ )
  47.       {
  48.       do
  49.          {
  50.          c=inportb(KEYSTATUS);
  51.          }
  52.       while ( c & IB_FULL );
  53.  
  54.       outportb(KEYDATA, v);
  55.       do
  56.          {
  57.          c=inportb(KEYSTATUS);
  58.          }
  59.       while ( c & OB_FULL);
  60.  
  61.       c=inportb(KEYDATA);
  62.       if ( c == KEY_ACK )
  63.          {
  64.          err=0;
  65.          break;
  66.          }
  67.       }
  68.  
  69.    return err;
  70. }
  71.  
  72.  
  73.  
  74. /* ---------------------- cap_light_on() --------------- January 15,1995 */
  75. void cap_light_on(void)
  76. {
  77.    if ( !send_keycontrol(LEDUPDATE) ) /* tell keyboard next byte is led bitmask */
  78.       send_keycontrol(CAPLOCK);       /* the led bitmask */
  79. }
  80.