delorie.com/djgpp/faq/lowlevel/hwint.html   search  
How do I register my djgpp function as a hardware interrupt handler?

The optimal set-up depends on the interrupt and on the environment under which your program will run (VCPI, DPMI, etc.). Therefore, only some basic considerations and techniques are listed below. What combination of these is best for your application is up to you to decide.

First, some background. Hardware interrupts can occur when the processor is either in real mode (like when go32 calls some DOS service) or in protected mode. When your program runs under a DPMI host, hardware interrupts are always passed to protected mode first, and only if unhandled, they are reflected to real mode. In non-DPMI environment, this is only true for interrupts which occur in protected mode; an interrupt which occurs in real mode is never passed to protected mode. So, if your program runs in non-DPMI mode, it must at least install a real-mode handler for the interrupt, or else it will lose interrupts; it is best also to install a protected-mode handler, otherwise for an interrupt which occurs in protected mode, the CPU will have to switch mode twice, which will hurt performance. In contrast, in DPMI mode you can get away by installing only a protected-mode handler. (The tricky one is to write a program which will run in both environments; this is left as an exercise for the reader... ;-)

To install a protected-mode interrupt handler, you do this:

To install a real-mode interrupt handler, you do this: For examples of installing and using hardware interrupt handlers, see the files sb02.zip (Sound Blaster interrupt-driven functions) and ldbgXXX.zip (interrupt-driven serial communications code), both available in the djgpp distribution archive.

  webmaster     delorie software   privacy  
  Copyright © 1995     Updated Feb 1995