home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / DEMOS / IN_TEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-18  |  3.2 KB  |  110 lines

  1. /*********************
  2.  *
  3.  *  in_test.c - interrupt test program.
  4.  *
  5.  *  Purpose: This file contains functions to test the interrupt functions.
  6.  *           It also shows how to design a TSR (terminate and stay resident)
  7.  *           function.
  8.  *
  9.  *  Blackstar C Function Library
  10.  *  (c) Copyright 1985 Sterling Castle Software
  11.  *
  12.  *  NOTES:
  13.  *  Demonstration of interrupt capability.  This program
  14.  *  hooks the timer tick interrupt 0x1c. Every 18 ticks it will
  15.  *  output a message to the screen. Striking any key will terminate
  16.  *  this test. The system then hooks the print screen interrupt
  17.  *  (activated by SHIFT-PRTSC) and terminates and stays resident.
  18.  *  Afterward, SHIFT-PRTSC prints 'hello'.
  19.  *
  20.  ******/
  21.  
  22. #include <stdio.h>
  23. #include <dos.h>
  24. #include "blackstr.h"
  25. #include "sc_head.h"
  26. #include "in_head.h"
  27. #include "co_head.h"
  28.  
  29. char cstack[256];
  30. int itest();
  31. int hello1();
  32. int count;
  33. int onec[2];
  34.  
  35. void main()
  36. {
  37.     int intno;
  38.     struct SREGS segs;
  39.  
  40.     /*******************************************
  41.      INITIALIZE AND EXPLAIN DEMO WORKINGS
  42.     ********************************************/
  43.     sc_init(3,7,0);
  44.     kb_init(NULL,NULL,NULL);
  45.     printf("\n\r This program hooks the timer interrupt and outputs a hello");
  46.     printf("\n\r message. Striking any key will terminate the timer test and");
  47.     printf("\n\r the print screen interrupt will then be hooked with a hello ");
  48.     printf("\n\r message using terminate and stay resident. Push shift-prtscr");
  49.     printf("\n\r to see the message 'hello' printed at the top of the screen.");
  50.     printf("\n\n\r strike any key to continue...\n");
  51.     kb_pause();
  52.     segread(&segs);
  53.     count = 0;
  54.  
  55.     /**********************************************
  56.      USE LOW LEVEL INTERRUPT SET/GET FOR TIMER
  57.     ***********************************************/
  58.     co_init(0);             /* ibm console */
  59.     co_mode(BW80,FWHITE,BBLACK);
  60.     co_clr();
  61.  
  62.     sy_getintv(0x1c, onec);       /* save the real one */
  63.     intno = in_setint(0x1c, itest, &cstack[255], INTHDWR);
  64.     while(!kb_hit())
  65.     printf(".");
  66.     in_remint(intno);            /* restore the real tick */
  67.  
  68.     /*************************************************
  69.      INSTALL TERMINATE AND STAY RESIDENT PROCESS
  70.     **************************************************/
  71.  
  72.     /*
  73.        Now set a terminate and stay resident process. Use NULL to use
  74.        the current C stack setup by the compiler.  The current stack
  75.        size is set using the compiler global.
  76.     */
  77.     intno = in_setint(05, hello1, NULL, INTSOFT);    /* set prtscr to hello1 */
  78.  
  79.  
  80.  
  81.     in_tsr();               /* Now use terminate and stay resident */
  82.  
  83.     printf("\n\nEND OF TEST - Press any key to exit...");
  84.     kb_getc();
  85.     co_clr();               /* clear screen */
  86. }
  87.  
  88.  
  89. /**********************************
  90.  TSR PROGRAM JUST TYPES HELLO
  91. **********************************/
  92. int hello1()
  93. {
  94.     sc_setcur(30,6);
  95.     sc_puts("****** Hello, World! ******\n");
  96.     return 0;
  97. }
  98.  
  99.  
  100. int itest()        /* the interrupt service routine */
  101. {
  102.     if(count++>18) {
  103.     sc_puts("\n\rhello from interrupt 0x1C\n\r");
  104.     count = 0;
  105.     }
  106.     return 0;
  107. }
  108.  
  109.     
  110.