home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_11 / timeint.c < prev    next >
Text File  |  1994-07-05  |  2KB  |  85 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <dos.h>
  5. #include <bios.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <conio.h>
  9.  
  10. #include "graph3.h"  // include graphics our stuff
  11. #include "graph4.h"
  12. #include "graph6.h"
  13.  
  14. // D E F I N E S /////////////////////////////////////////////////////////////
  15.  
  16. #define TIME_KEEPER_INT     0x1C    // the time keeper interrupt
  17.  
  18. // G L O B A L S /////////////////////////////////////////////////////////////
  19.  
  20. void (_interrupt far *Old_Time_Isr)();  // used to hold old interrupt vector
  21.  
  22. long counter=0;                    // global variable to be altered by ISR
  23.  
  24. // F U N C T I O N S ////////////////////////////////////////////////////////
  25.  
  26. void _interrupt far Timer(void)
  27. {
  28.  
  29. // increment value of counter 18.2 times a second
  30.  
  31. counter++;
  32.  
  33. // now call old interrupt handler (if there was one?). This is only needed
  34. // if you want to chain interrupts handlers.  In the case that you want
  35. // total control then the next instruction wouldn't be used.
  36.  
  37. Old_Time_Isr();
  38.  
  39. } // end Timer
  40.  
  41. // M A I N ///////////////////////////////////////////////////////////////////
  42.  
  43. void main(void)
  44. {
  45.  
  46. char string[128]; // working string
  47.  
  48. // set video mode to 320x200 256 color mode
  49.  
  50. Set_Video_Mode(VGA256);
  51.  
  52. // draw instructions
  53.  
  54. Blit_String(2,2,15,"Press any key to exit.",0);
  55.  
  56. // install our time keeper ISR while saving old one
  57.  
  58. Old_Time_Isr = _dos_getvect(TIME_KEEPER_INT);
  59.  
  60. _dos_setvect(TIME_KEEPER_INT, Timer);
  61.  
  62. // wait for user to hit a key
  63.  
  64. while(!kbhit())
  65.      {
  66.  
  67.      // print out current value of "counter", but note how we don't change it!
  68.      // it is being changed by the ISR
  69.  
  70.      sprintf(string,"The interrupt has been called %ld times",counter);
  71.      Blit_String(2,2+2*8,10,string,0);
  72.  
  73.      } // end while
  74.  
  75. // replace old time keeper ISR
  76.  
  77. _dos_setvect(TIME_KEEPER_INT, Old_Time_Isr);
  78.  
  79. // reset the video mode back to text
  80.  
  81. Set_Video_Mode(TEXT_MODE);
  82.  
  83. } // end main
  84.  
  85.