home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
-
- FILE
- timebios.c - how to chain routine to BIOS timer interrupt service
-
- REMARKS
- This program can only be compiled with Microsoft C version 5.00.
-
- It demonstrates how to chain a timer interrupt service routine
- to the BIOS timer interrupt service routine. Normally, a timer
- interrupt service routine must save registers, switch to the
- program data segment, service the interrupt, send EOI bytes to
- the 8259 interrupt controller, restore the registers and execute
- an iret instruction. With Microsoft C version 5.00, there is a
- special Microsoft specific keyword, interrupt, which tells the
- compiler to generate code to switch and restore register context.
- On IBM-PC's, timer interrupts vector to a BIOS timer interrupt
- service routine which updates the computer's date and time-of-day
- clock. This routine then performs a software interrupt to vector
- 28, allowing routines to be chained to it.
-
- This example shows how to chain to the timer vector 28 using
- Microsoft C version 5.00 and services in timeinta.asm.
-
- masm timeinta /ml;
- cl /Gs timebios.c timeint
-
- You must compile with the /Gs option. Do not use any optimization
- options as there may be problems using optimizations with routines
- declared with the "interrupt" keyword.
-
- Notice how the declarations for setivec() and getivec() differs
- from those in timeintc.c. Wierd, isn't it?
-
- LAST UPDATE
- 26 January 1988
-
- Copyright(c) 1987-1988 D.M. Auslander and C.H. Tham
-
- ***********************************************************************/
-
- /***********************************************************************
- I M P O R T S
- ***********************************************************************/
-
- #include "envir.h"
-
- extern void (interrupt far *getivec(int))();
- extern void setivec(int, unsigned, void (interrupt far *)());
-
-
- /***********************************************************************
- P R I V A T E D A T A
- ***********************************************************************/
-
- #define VECTOR 28 /* called by BIOS timer isr */
-
- 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 interrupt far tick(void)
-
- REMARKS
- Count 18 timer interrupts (equivalent to 1 second) and set flag
-
- LAST UPDATE
- 26 January 1988
- ----------------------------------------------------------------------*/
-
- void interrupt far tick()
- {
- if (++tock >= 18)
- flag = 1;
- }
-
-
-
- /*----------------------------------------------------------------------
- PROCEDURE
- MAIN - the main program
-
- LAST UPDATE
- 26 January 1988
- take advantage of new setivec() and getivec()
- ----------------------------------------------------------------------*/
-
- main()
- {
- void (interrupt far *orig_isr)(); /* original vector */
- int seconds = 0; /* elasped time in seconds */
-
-
- orig_isr = getivec(VECTOR); /* save original vector contents */
-
- setivec(VECTOR, sizeof(tick), tick); /* install tmrisr() */
-
- while (seconds < 10) /* not 10 seconds yet */
- {
- while (!flag) /* wait for 1 second indication */
- ;
-
- tock = 0; /* reset interrupt count */
- flag = 0; /* reset flag */
-
- printf("%d\n", ++seconds); /* print elasped time in seconds */
- }
-
- setivec(VECTOR, sizeof(orig_isr), orig_isr);
-
- }
-
-
-