next up previous contents index
Next: TypesVariables and Constants Up: Introduction Previous: Processor access

Interrupt redirection

The GO32 unit helps you to redirect interrupts. SetIntVec and GetIntVec don't work with Free Pascal. This is now done via the functions set_pm_interrupt and get_pm_interrupt.

As an example we show how to redirect the interrupt 8h.

 
{ the unit CRT _is_ needed because the program doesn't get 
  an interrupt while DOS is active }
uses
   go32,crt;

var
   timer : longint;
   ds : word;

procedure s; { interrupt;}
             { comes with versions > 0.9.2 of FPCPascal }

  begin
     asm
        { save used registers }
        pushl %eax
        pushw %ds
        { load ds }
        { prefix for cs }
        .byte 0x2e
        movw ALAB,%ax
        movw %ax,%ds
     end;
     inc(timer);
     asm
        { restore processor state }
        popw %ds
        popl %eax
        leave
        { call old interrupt }
        ljmp %cs:OLDINT
        iret
        { we need some data in the code segment, }
        {  since only CS is set in the }
        { entry point of the procedure }
     ALAB:
        .word 0
        { old vector as 48 bit pointer (16:32) }
     OLDINT:
        .long 0
        .word 0
     end;
  end;

  var
     oldint,myint : tseginfo; 
     i : longint;

  begin 
     timer:=0;
     { save old interrupt }
     get_pm_interrupt(8,oldint); 
     ds:=get_ds; 
     asm 
        { copy some data to the code segment }
        movw _DS,%ax
        movw %ax,ALAB
        movl _OLDINT,%eax
        movl %eax,OLDINT
        movw _OLDINT+4,%ax
        movw %ax,OLDINT+4
     end;
     { new handler }
     myint.segment:=get_cs;
     myint.offset:=@s;
     { install the handler }
     set_pm_interrupt(8,myint);
     { do something }
     for i:=1 to 10000 do
       writeln(timer);
     { install the old handler }
     set_pm_interrupt(8,oldint);
  end.



Michael Van Canneyt
Tue Mar 31 16:46:10 CEST 1998