~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to fpcdocs/go32ex/intpm.pas

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ This example shows how to redirect a software interrupt by
 
2
changing the protected mode handler of the DPMI host.
 
3
 
 
4
In more detail it hooks interrupt 1Ch which is called every
 
5
time the timer interrupt (int 08) is executed. This is the
 
6
preferred way to hook the timer, because int 1Ch is a software
 
7
interrupt which doesn't need so much initialization stuff
 
8
compared to hooking a hardware interrupt.
 
9
}
 
10
 
 
11
uses
 
12
        crt,
 
13
        go32;
 
14
 
 
15
const
 
16
        { interrupt number we want to hook }
 
17
        int1c = $1c;
 
18
 
 
19
var
 
20
        { 48 bit pointer to old interrupt handler }
 
21
        oldint1c : tseginfo;
 
22
        { 48 bit pointer to new interrupt handler }
 
23
        newint1c : tseginfo;
 
24
 
 
25
        { increased every time the interrupt is called  }
 
26
        int1c_counter : Longint;
 
27
 
 
28
        { the current data selector }
 
29
        int1c_ds : Word; external name '___v2prt0_ds_alias';
 
30
 
 
31
{ the actual handler code }
 
32
procedure int1c_handler; assembler;
 
33
asm
 
34
   cli
 
35
{ save all registers }
 
36
   pushw %ds
 
37
   pushw %ax
 
38
{ prepare segment registers for FPC procedure }
 
39
   movw %cs:int1c_ds, %ax
 
40
   movw %ax, %ds
 
41
{ simply increase the counter by one }
 
42
   incl int1c_counter
 
43
{ restore registers }
 
44
   popw %ax
 
45
   popw %ds
 
46
   sti
 
47
   iret
 
48
end;
 
49
 
 
50
var i : Longint;
 
51
 
 
52
begin
 
53
     { insert right handler data into new handler variable }
 
54
     newint1c.offset := @int1c_handler;
 
55
     newint1c.segment := get_cs;
 
56
     { get the old handler }
 
57
     get_pm_interrupt(int1c, oldint1c);
 
58
     Writeln('-- Press any key to exit --');
 
59
     { set new handler }
 
60
     set_pm_interrupt(int1c, newint1c);
 
61
     { write the number of interrupts occured }
 
62
     while (not keypressed) do begin
 
63
           gotoxy(1, wherey);
 
64
           write('Number of interrupts occured : ', int1c_counter);
 
65
     end;
 
66
     { restore old handler }
 
67
     set_pm_interrupt(int1c, oldint1c);
 
68
end.
 
 
b'\\ No newline at end of file'