intpm.pas 1.7 KB

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