Solved

How to setup an ISR in Turbo C++.

Posted on 1997-08-07
2
822 Views
Last Modified: 2012-08-13
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
Comment
Question by:e92fb
2 Comments
 

Accepted Solution

by:
tomii earned 50 total points
ID: 1252966
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
 

Author Comment

by:e92fb
ID: 1252967
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question