[comp.lang.pascal] Interrupt programming in TP 5.0

pmk@cip-s01.informatik.rwth-aachen.de (Michael Keukert) (10/23/89)

And here comes  another part in  the famous series  "Turbo-Pascal extreme".
Today: Interrupt programming in Turbo-Pascal 5.0

Only few people now, that TP provides full interrupt programming. I  admit,
that I  haven't knew  it myself  for a  long time.  One reason is, that the
TP manuals aren't very informative  on that theme and, honestly,  who reads
a manual from the beginning to the end?

This is, I think, a pity  because interrupt programming in TP isn't  mystic
nor tricky nor very hard to do. No, it's quite a simple thing to do:

The following  program displays  the current  time in  the leftmost/topmost
corner of the screen while a little junk-program is running:


program interrupt_test;

uses dos,crt;

var a:integer;
    adr:pointer;
    s:string;


{The following procedure is going to be put into an interrupt}

{$F+}  {Far-Compiling is needed for direct adressing}
procedure test(flags,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp:word);
interrupt;

{ This procedure displays the current time in the leftmost/topmost
  corner of the screen }

var hour,minute,second,sec100:word;
    x_pos,y_pos:byte;                  { current cursor-position }

begin
 gettime(hour,minute,second,sec100);   { get current time        }
 x_pos:=wherex;                        { get cursor position     }
 y_pos:=wherey;
 gotoxy(1,1);                          { goto top position       }
 write(hour:2,':',minute:2,':',second:2,'.',sec100);
 gotoxy(x_pos,y_pos);                  { restore cursor position }
end;
{$F-}

{main}
begin

  clrscr;
  writeln;
  writeln;
  writeln('Please enter a word');

  getintvec(28,adr);             { Get's the original interrupt value }
  setintvec(28,@test);           { Enter's the new adress             }

  repeat                         { A "junk" program to demonstrate    }
   readln(s);                    { that the program continous         }
   for a:=length(s) downto 1 do  { running...                         }
    write(s[a]);
   writeln;
  until s='';

  setintvec(28,adr);             { Restores the original value        }

end.


Pay attention to:

The head  of the  interrupt-procedure MUST  contain all  the DOS-Registers,
even  when  they're  not  used  in  the  procedure.  The key-word INTERRUPT
must follow the head immediatly!
Note,  that  the  procedure  isn't  called  in  the  main-program  by name.
It  starts  with  the  line   SetIntVec(28,@test).  The  @  indicates   the
physical address of the procedure.

Summary:

Program name;
	.
	.
procedure to_be_interrupted (flags,,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp:word);
interrupt;
begin
	.
	.
end;
	.
	.
begin {main}
	.
	.
	SetIntVec(IntNo:byte; vector:pointer);
	.
	.
end.


PMK@CIP-S01.INFORMATIK.RWTH-AACHEN.DE     ! Warning! UNIX-Newcomer!
Michael Keukert of 2:242/2 (Fido-Net)     ! No flames please .... 
PMK@EIKO.ZER           (Zerberus-Net)     ! ... I'm still learning.