Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

How to setup an ISR in Turbo C++.

I'm having problems getting my interrupt service routines to work properly. I use the good old Borland TC and follow the examples when setting up my ISR and when saving old vectors and plugging new ones. But still, it doesn't matter how I excite the IRQ-channels, I never manage to enter the ISR. I use IRQ11 on an embedded 386-system. Can you give mee a hint about what could be the problem, I've run out of ideas.

Cheers!
Fredrik Bagenholm
0
e92fb
Asked:
e92fb
1 Solution
 
tomiiCommented:
Is that int 0x11, or int 11 ?  (hex, or decimal)...

from "Teach Yourself Game Programming in 21 Days", SAMs Publishing... (with some modifications).

note, that if you change MY_INTERRUPT to 0x1C, that is the system timer, & this will update the counter about 18.2 times per second....

#include <dos.h>
#include <bios.h>
#include <stdio.h>
#include <conio.h>

#define      MY_INTERRUPT      0x11  /* int 11 hex */

/* Used to hold the old interrupt vector */
void (_interrupt far *Old_Isr)();

long      counter = 0;      /* global for interrupt to use */

void _interrupt far Count_Ints(void)
{
      /* increment counter whenever interrupt is called */
      counter++;

      /* call the old int handler if there was one (next
            ISR in the chain.  If you want to disable the
            other interrupts (no chain), then do not
            call this next function... WARNING!!  you
            can mess things up doing this, as some
            system processes _need_ some interrupts! */

      Old_ISR();
}

void main()
{
      /* save old ISR */
      Old_Isr = _dos_getvect(MY_INTERRUPT);

      /* install my ISR */
      _dos_setvect(MY_INTERRUPT, Counter);

      /* wait for keyhit */
      while(!kbhit())
      {
            /* print current value of counter - note that it
            is being changed by th ISR */
            printf("The ISR has been called %ld times", counter);

      }

      /* Replace the old ISR */
      _dos_setvect(MY_INTERRUPT, Old_Isr);

}
0
 
e92fbAuthor Commented:
Hi and thanks!
I've actually managed to get it going, but I had to change the IRQ-mask to enable IRQ10 and IRQ11. This wasn't done by BIOS at start-up as I expected. Also an EOI has to be sent (both to address 0xA0 and 0x20) to the PIC just before leaving the ISR.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now