home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
-
- FILE
- timeintc.c - timer demo program using time1.c
-
- REMARKS
- Prints the seconds for 10 seconds. DOS's time keeping function is
- temporarily suspended, but will be restored at the end of the test.
-
- This program must be linked with the timeinta.asm module. The
- low level timer interrupt service routine in timeinta.asm, tmrisr(),
- will save the registers and call tick(), which is defined in this
- module. Here is how to generate an executable program:
-
- masm timeinta /ml;
- cl /Gs timeintc.c timeinta
-
- This module must be compiled using the /Gs flag because it contains
- a routine that will be called inside an interrupt service routine.
-
- This program uses the PC's system clock frequency of approx. 18.2
- timer interrupts per second. If you want to use a different
- tick frequency, refer to alarm.c for functions to change it.
-
- LAST UPDATE
- 18 January 1988
-
- Copyright(c) 1987-1988 D.M. Auslander and C.H. Tham
-
- ***********************************************************************/
-
- /***********************************************************************
- I M P O R T S
- ***********************************************************************/
-
- #include "envir.h"
-
- #ifdef ANSI
-
- extern void tmrisr(void);
- extern void setivec(int, unsigned, long);
- extern long getivec(int);
-
- #else
-
- extern void tmrisr();
- extern void setivec();
- extern long getivec();
-
- #endif
-
- /***********************************************************************
- P R I V A T E D A T A
- ***********************************************************************/
-
- #define VECTOR 8 /* timer interrupt vector number */
-
- static int tock = 0; /* count of interrupts */
- static int flag = 0; /* flag each 1 second period */
-
-
- /***********************************************************************
- R O U T I N E S
- ***********************************************************************/
-
- /*----------------------------------------------------------------------
- PROCEDURE
- TICK - high level timer interrupt service routine
-
- SYNOPSIS
- void tick(void) - called by low level interrupt handler tmrisr()
-
- REMARKS
- Count 18 timer interrupts (equivalent to 1 second) and set flag
-
- LAST UPDATE
- 26 January 1988
- ----------------------------------------------------------------------*/
-
- void tick()
- {
- if (++tock >= 18)
- {
- tock = 0;
- flag = 1;
- }
- }
-
-
-
- /*----------------------------------------------------------------------
- PROCEDURE
- MAIN - the main program
-
- LAST UPDATE
- 26 January 1988
- take advantage of new setivec() and getivec()
- ----------------------------------------------------------------------*/
-
- main()
- {
- long orig_isr; /* place to save original timer vector */
- int seconds = 0; /* elasped time in seconds, initialized to 0 */
-
-
- orig_isr = getivec(VECTOR); /* save original vector contents */
-
- setivec(VECTOR, sizeof(tmrisr), (long)tmrisr); /* install tmrisr() */
-
- while (seconds < 10) /* not 10 seconds yet */
- {
- while (!flag) /* wait for 1 second indication */
- ;
-
- flag = 0; /* reset flag */
-
- printf("%d\n", ++seconds); /* print elasped time in seconds */
- }
-
- setivec(VECTOR, sizeof(orig_isr), orig_isr);
-
- }
-
-
-