Thread: ISR problem

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    ISR problem


    hi all , :confused:
    this code is a sample of simple ISR programming. I cant undrestand 3 lines of this code.
    1) void interrupt(*old)(); : where is the codes of this function ? should I write it or it predefined ?

    2) what does keep(0,1000) exacly do ?

    3) (*old)(); ----> what does this line do ?

    Code:
    #include <dos.h>         
    void interrupt(*old)();
    void interrupt newint9();
    void main()
    {
    	old = getvect(0x09);
    	setvect(0x09,newint9);
    	keep(0,1000);
    }
    void interrupt newint9()
    {
    	if (inportb(0x60)==0x1F)
    	{
         		outportb(0x20,0x20);
         		return;
     	}
      	(*old)();
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    First, you should read the intro threads, and learn about [code][/code] tags before posting any more code.

    Next, you might want to ask your tutors about the "wisdom" of learning obsolete technology. Outside of museums and some very niche applications, nobody has programmed seriously in DOS for the last 20 years.

    1) void interrupt(*old)(); : where is the codes of this function ? should I write it or it predefined ?
    It's a pointer to a function. You initialise it by calling getvect()

    2) what does keep(0,1000) exacly do ?
    No idea - is it declared in dos.h?

    3) (*old)(); ----> what does this line do ?
    This calls the old interrupt vector.
    Since you only trap "if (inportb(0x60)==0x1F)", all other INT9 interrupts will be handled by the original function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    2) what does keep(0,1000) exacly do ?
    Wow!!!! This brings back memories of writing code on a old IBM XT pc using DOS 3.3.

    But anyway, if memory serves me correctly, the zero is returned to the "outside world" to indicate the successful installation of your Terminate and Stay Resident (TSR) app. It also keeps allocated a 1000 bytes of memory for use by your TSR.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    thank you all, :)

    but I still have one problem that is, void interrupt(*old)();
    we wrote the code of "void interrupt newint9() " function, but what does we do in the " void interrupt(*old)(); " ? if this function is only for setvect(0x09,old ); so can i change my program to this ?

    Code:
    #include <dos.h>         
    
    void interrupt newint9();
    void main()
    {
    	old = getvect(0x09);
    	setvect(0x09,newint9);
    	keep(0,1000);
    }
    void interrupt newint9()
    {
    	if (inportb(0x60)==0x1F)
    	{
         		outportb(0x20,0x20);
         		return;
     	}
            setvect(0x09,old);
    }
    one else question, i like to learn about resident programs and ISR what is your recommendation ?

    thanx ..............
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    You had a working program, and then you broke it - why!?

    > but what does we do in the " void interrupt(*old)(); " ?
    Like I said it's a POINTER to a function.

    As well as your regular pointers to data, say
    int a;
    int *pa = &a;

    You can also point at functions as well.

    A function pointer is very useful if you don't know the name of the function, or you don't know which one to call until run-time.

    old = getvect(0x09);
    returns a pointer to a function (which you don't know the name of)

    (*old)();
    calls that function (well it would have done, until you deleted it).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    The fun statement is:
    Code:
        outportb(0x20, 0x20);
    Interesting things happen if you forget that line :). It basically tells the 8259 priority interrupt controller chip that you're handling the current interrupt and that it is OK to receive further interrupts of equal or lower priority from other peripherals.

    Writing TSRs is fun. I learned a lot about the internals of DOS and hardware when I was poking around as a kid.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo