home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * in_test.c - interrupt test program.
- *
- * Purpose: This file contains functions to test the interrupt functions.
- * It also shows how to design a TSR (terminate and stay resident)
- * function.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985 Sterling Castle Software
- *
- * NOTES:
- * Demonstration of interrupt capability. This program
- * hooks the timer tick interrupt 0x1c. Every 18 ticks it will
- * output a message to the screen. Striking any key will terminate
- * this test. The system then hooks the print screen interrupt
- * (activated by SHIFT-PRTSC) and terminates and stays resident.
- * Afterward, SHIFT-PRTSC prints 'hello'.
- *
- ******/
-
- #include <stdio.h>
- #include <dos.h>
- #include "blackstr.h"
- #include "sc_head.h"
- #include "in_head.h"
- #include "co_head.h"
-
- char cstack[256];
- int itest();
- int hello1();
- int count;
- int onec[2];
-
- void main()
- {
- int intno;
- struct SREGS segs;
-
- /*******************************************
- INITIALIZE AND EXPLAIN DEMO WORKINGS
- ********************************************/
- sc_init(3,7,0);
- kb_init(NULL,NULL,NULL);
- printf("\n\r This program hooks the timer interrupt and outputs a hello");
- printf("\n\r message. Striking any key will terminate the timer test and");
- printf("\n\r the print screen interrupt will then be hooked with a hello ");
- printf("\n\r message using terminate and stay resident. Push shift-prtscr");
- printf("\n\r to see the message 'hello' printed at the top of the screen.");
- printf("\n\n\r strike any key to continue...\n");
- kb_pause();
- segread(&segs);
- count = 0;
-
- /**********************************************
- USE LOW LEVEL INTERRUPT SET/GET FOR TIMER
- ***********************************************/
- co_init(0); /* ibm console */
- co_mode(BW80,FWHITE,BBLACK);
- co_clr();
-
- sy_getintv(0x1c, onec); /* save the real one */
- intno = in_setint(0x1c, itest, &cstack[255], INTHDWR);
- while(!kb_hit())
- printf(".");
- in_remint(intno); /* restore the real tick */
-
- /*************************************************
- INSTALL TERMINATE AND STAY RESIDENT PROCESS
- **************************************************/
-
- /*
- Now set a terminate and stay resident process. Use NULL to use
- the current C stack setup by the compiler. The current stack
- size is set using the compiler global.
- */
- intno = in_setint(05, hello1, NULL, INTSOFT); /* set prtscr to hello1 */
-
-
-
- in_tsr(); /* Now use terminate and stay resident */
-
- printf("\n\nEND OF TEST - Press any key to exit...");
- kb_getc();
- co_clr(); /* clear screen */
- }
-
-
- /**********************************
- TSR PROGRAM JUST TYPES HELLO
- **********************************/
- int hello1()
- {
- sc_setcur(30,6);
- sc_puts("****** Hello, World! ******\n");
- return 0;
- }
-
-
- int itest() /* the interrupt service routine */
- {
- if(count++>18) {
- sc_puts("\n\rhello from interrupt 0x1C\n\r");
- count = 0;
- }
- return 0;
- }
-
-
-