home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_5 / keytest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-02  |  3.9 KB  |  142 lines

  1.  
  2. // KEYTEST.C - A demo of the keyboard driver
  3.  
  4. // I N C L U D E S ///////////////////////////////////////////////////////////
  5.  
  6. #include <io.h>
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include <bios.h>
  12. #include <fcntl.h>
  13. #include <memory.h>
  14. #include <malloc.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. // include our graphics library
  19.  
  20. #include "black3.h"
  21. #include "black4.h"
  22. #include "black5.h"
  23.  
  24. // D E F I N E S /////////////////////////////////////////////////////////////
  25.  
  26. #define START_NUMERIC_COLOR 6*16    // start of color register bank that
  27.                                     // keys are drawn with
  28.  
  29. // G L O B A L S  ////////////////////////////////////////////////////////////
  30.  
  31. pcx_picture image_pcx;  // general PCX image used to load background and imagery
  32.  
  33. // M A I N ///////////////////////////////////////////////////////////////////
  34.  
  35. void main(int argc, char **argv)
  36. {
  37.  
  38. RGB_color on  = {0,63,0},   // the color values for the on and off buttons
  39.           off = {0,20,0};
  40.  
  41. // set the graphics mode to mode 13h
  42.  
  43. Set_Graphics_Mode(GRAPHICS_MODE13);
  44.  
  45. // load the screen image
  46.  
  47. PCX_Init((pcx_picture_ptr)&image_pcx);
  48.  
  49. // load a PCX file (make sure it's there)
  50.  
  51. if (PCX_Load("keypad.pcx", (pcx_picture_ptr)&image_pcx,1))
  52.    {
  53.    // copy the image to the display buffer
  54.  
  55.    PCX_Show_Buffer((pcx_picture_ptr)&image_pcx);
  56.  
  57.    // delete the PCX buffer
  58.  
  59.    PCX_Delete((pcx_picture_ptr)&image_pcx);
  60.  
  61.    // install the keyboard driver
  62.  
  63.    Keyboard_Install_Driver();
  64.  
  65.    // enter main evet loop
  66.  
  67.    while(!keyboard_state[MAKE_ESC])
  68.         {
  69.  
  70.         // to avoid video snow wait for vertical retrace
  71.  
  72.         Wait_For_Vertical_Retrace();
  73.  
  74.         // now test all the keys to see if they are pressed or released
  75.         // based on this turn the virtual light that illuminates each
  76.         // button on or off
  77.  
  78.         if (keyboard_state[MAKE_1])
  79.            Write_Color_Reg(START_NUMERIC_COLOR+0, (RGB_color_ptr)&on);
  80.         else
  81.            Write_Color_Reg(START_NUMERIC_COLOR+0, (RGB_color_ptr)&off);
  82.  
  83.         if (keyboard_state[MAKE_2])
  84.            Write_Color_Reg(START_NUMERIC_COLOR+1, (RGB_color_ptr)&on);
  85.         else
  86.            Write_Color_Reg(START_NUMERIC_COLOR+1, (RGB_color_ptr)&off);
  87.  
  88.         if (keyboard_state[MAKE_3])
  89.            Write_Color_Reg(START_NUMERIC_COLOR+2, (RGB_color_ptr)&on);
  90.         else
  91.            Write_Color_Reg(START_NUMERIC_COLOR+2, (RGB_color_ptr)&off);
  92.  
  93.         if (keyboard_state[MAKE_4])
  94.            Write_Color_Reg(START_NUMERIC_COLOR+3, (RGB_color_ptr)&on);
  95.         else
  96.            Write_Color_Reg(START_NUMERIC_COLOR+3, (RGB_color_ptr)&off);
  97.  
  98.         if (keyboard_state[MAKE_5])
  99.            Write_Color_Reg(START_NUMERIC_COLOR+4, (RGB_color_ptr)&on);
  100.         else
  101.            Write_Color_Reg(START_NUMERIC_COLOR+4, (RGB_color_ptr)&off);
  102.  
  103.         if (keyboard_state[MAKE_6])
  104.            Write_Color_Reg(START_NUMERIC_COLOR+5, (RGB_color_ptr)&on);
  105.         else
  106.            Write_Color_Reg(START_NUMERIC_COLOR+5, (RGB_color_ptr)&off);
  107.  
  108.         if (keyboard_state[MAKE_7])
  109.            Write_Color_Reg(START_NUMERIC_COLOR+6, (RGB_color_ptr)&on);
  110.         else
  111.            Write_Color_Reg(START_NUMERIC_COLOR+6, (RGB_color_ptr)&off);
  112.  
  113.         if (keyboard_state[MAKE_8])
  114.            Write_Color_Reg(START_NUMERIC_COLOR+7, (RGB_color_ptr)&on);
  115.         else
  116.            Write_Color_Reg(START_NUMERIC_COLOR+7, (RGB_color_ptr)&off);
  117.  
  118.         if (keyboard_state[MAKE_9])
  119.            Write_Color_Reg(START_NUMERIC_COLOR+8, (RGB_color_ptr)&on);
  120.         else
  121.            Write_Color_Reg(START_NUMERIC_COLOR+8, (RGB_color_ptr)&off);
  122.  
  123.         } // end main event loop
  124.  
  125.    // remove the keyboard driver
  126.  
  127.    Keyboard_Remove_Driver();
  128.  
  129.    // use a screen transition to exit
  130.  
  131.    Screen_Transition(SCREEN_WHITENESS);
  132.  
  133.    } // end if pcx file found
  134.  
  135. // reset graphics to text mode
  136.  
  137. Set_Graphics_Mode(TEXT_MODE);
  138.  
  139. } // end main
  140.  
  141.  
  142.