qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
TIMER.PAS
  Example Contents Index                                    Back
 
PROGRAM timer;
 
{ TIMER.PAS demonstrates the use of GetIntVec and SetIntVec to install
  an interrupt service routine to handle the timer interrupt, which is
  called roughly 18.2 times per second.
}
 
USES
    Crt, Dos;
 
CONST
    program_name = 'TIMER ';
    program_desc = ' sets up an interrupt routine for the timer.';
    timerint     = $1C;
    maxtime      = 18;
 
VAR
    oldvect : POINTER;
    clicks  : Integer;
    key     : Char;
 
PROCEDURE newtimer; INTERRUPT;
{ Decrement counter with each call to timer interrupt. }
BEGIN
    IF( clicks > 0 ) THEN
        clicks := clicks - 1
END;
 
BEGIN
 
    Writeln( program_name, program_desc );
    Writeln;
    Writeln( 'Press a key to quit.' );
 
    { Get and save original vector. }
    GetIntVec( timerint, oldvect );
 
    clicks := maxtime;
 
    { Revector interrupt to point at new function. }
    SetIntVec( timerint, @newtimer );
 
    { Continue until key is pressed. }
    WHILE (KeyPressed = False) DO
        BEGIN
        { Has counter been cleared by interrupt? }
        IF ( clicks = 0 ) THEN
            BEGIN
            Writeln( 'Timer cleared!' );
            clicks := maxtime;
            END;
        END;
    key := ReadKey;
 
    { Set vector back to original value. }
    SetIntVec( timerint, oldvect );
 
END.