home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TANK11.ZIP / SOURCE.ZIP / GR.C < prev    next >
C/C++ Source or Header  |  1993-01-16  |  3KB  |  95 lines

  1. /**********************************************************************
  2. * gr.c
  3. *
  4. * Support routines for graphics mode.
  5. **********************************************************************
  6.                     This file is part of
  7.  
  8.          STK -- The sprite toolkit -- version 1.0
  9.  
  10.               Copyright (C) Jari Karjala 1990
  11.  
  12. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  13. resolution sprite graphics with PCompatible hardware. This toolkit
  14. is provided as is without any warranty or such thing. See the file
  15. COPYING for further information.
  16.  
  17. **********************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <stdarg.h>
  22. #include <string.h>
  23. #include <signal.h>
  24. #include <conio.h>
  25. #include <graphics.h>
  26. #include <dos.h>
  27.  
  28.  
  29.  
  30. /**********************************************************************
  31. * Array of booleans for each key of the keyboard (indexed by the scan
  32. * code value). Non-zero if key pressed, zero otherwise.
  33. * The array is updated during the kbd_grab, see the function
  34. * gr_start_kbd_grab below.
  35. **********************************************************************/
  36. char gr_keys[128];
  37.  
  38.  
  39. /** Vector to the old keyboard interrupt handler **/
  40. void interrupt (*gr_old_int9)(void);
  41.  
  42. static unsigned int far *fp_kbd_tail, far *fp_kbd_head;
  43.  
  44. /** The new keyboard interrupt handler, see start_kbd_grab() in gr.c **/
  45. void interrupt gr_int9(void)
  46. {
  47.     unsigned char a;
  48.  
  49.     a = inp(0x60);              /** read key code and (re)set it to table **/
  50.     if (a & 0x80)
  51.         gr_keys[a & 0x7F] = 0;
  52.     else
  53.         gr_keys[a] = 1;
  54.  
  55.     fp_kbd_tail = MK_FP(0x40,0x1A);
  56.     fp_kbd_head = MK_FP(0x40,0x1C);
  57.     *fp_kbd_tail = *fp_kbd_head;          /** flush keyboard buffer **/
  58.  
  59.     gr_old_int9();                 /** allow old handler (eg breakon.com) **/
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. /**********************************************************************
  72. * Restore the original keyboard handler
  73. **********************************************************************/
  74. void gr_end_kbd_grab(void)
  75. {
  76.     setvect(9, gr_old_int9);
  77. }
  78.  
  79. /**********************************************************************
  80. * Set a new handler for the keyboard. This handler sets and resets
  81. * the gr_keys array values for each scancode received, flushes the
  82. * keyboard buffer and then calls the original handler.
  83. **********************************************************************/
  84. void gr_start_kbd_grab(void)
  85. {
  86.     static int first_time = 1;
  87.  
  88.     gr_old_int9 = getvect(9);
  89.     memset(gr_keys, 0, sizeof(gr_keys));
  90.     setvect(9, gr_int9);
  91.     if (first_time) {
  92.         atexit(gr_end_kbd_grab);
  93.         first_time = 0;
  94.     }
  95. }