Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setvect and getvect

Status
Not open for further replies.

mehmetnal

Programmer
Dec 6, 2003
4
TR
I have to write my own code for setvect and getvect functions instead of using turbo c's setvect and getvect. The prototypes are:

void interrupt (*getVect(int intNo)) ();
void interrupt setVect(int intNo, void interrupt(*isr) ());

I tried to use far pointers but i had errors(cannot convert from void far * to void interrupt far *). I tried to cast void far to void interrupt far, this time compiler said: "Not an allowable type". I tried writing assembly code in turbo c, it didn't work either. Can somebody help pls. I think the trouble is in generating a void interrupt far pointer.
 
Something along the lines of
Code:
void interrupt myISR ( ) {
    // do something, but not too much
}

Then later on in your code
Code:
int myVector = 0x21;
void interrupt (*old)() = getVect(myVector); // save the old
setVect(myVector,myISR);  // install the new

--
 
I know how to use turbo c's setvect and getvect. My problem is how to implement my own setvect and getvect functions.
 
Well post what you did try then.

Code:
void interrupt setVect(int intNo, void interrupt(*isr) ()) {
    void interrupt(**vector)();
    intNo *= 4;  // each vector takes 4 bytes
    vector = (void interrupt(**)())intNo;
    *vector = isr;
}

void interrupt (*getVect(int intNo))() {
    void interrupt(**vector)();
    intNo *= 4;  // each vector takes 4 bytes
    vector = (void interrupt(**)())intNo;
    return *vector;
}

Or use a typedef to hide all that pointer to function trickery
Code:
typedef void interrupt (*fnptr)();
void interrupt setVect(int intNo, fnptr isr ) {
    fnptr *vector;
    intNo *= 4;  // each vector takes 4 bytes
    vector = (fnptr *)intNo;
    *vector = isr;
}

fnptr getVect(int intNo) {
    fnptr *vector;
    intNo *= 4;  // each vector takes 4 bytes
    vector = (fnptr *)intNo;
    return *vector;
}
Typedefs for function pointer types really help tidy up the profusion of * and () they typically generate.

--
 
Salem,

I thought your code would work when i compiled it. It compiles but it doesnt do the job. I tried my program with turbo c's setvect and getvect, it worked, but it doesnt work with your code, although it looks like correct. I couldn't find out where the mistake is.
 
> vector = (fnptr *)intNo;
You'd better check some compiler options (like which memory model you're using).
If you're using small say, then this will be
DS:intNo*4

Not
0000:intNo*4
which it needs to be to access the vectors


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top