[comp.sys.ibm.pc] _dos_setvect in MS C 5.0

jh@mancol.UUCP (John Hanley) (02/23/88)

Has anyone succesfully used the _dos_setvect() library function in MS C?
A complete example program would be GREATLY appreciated.
Page 224 of the run-time library manual gives the following information:
	#include <dos.h>
	void _dos_setvect( intnum, void(handler)());
	unsigned intnum;           /* Target interrupt vector               */
	interrupt far *handler;    /* Interrupt handler to assign intnum to */

but I have _no_ idea how to call it correctly.  The idea is that you write
a handler function that gets called every INT 'intnum' is generated.  The
handler can be a C function previously declared with the interrupt attribute.
I did that but then none of the dozen or so combinations I tried for calling
_dos_setvect got past the compiler without a 'must be a function/pointer to a 
function' error ocassionally, or a 'redifinition' error when handler was 
declared as a type other than void.

BTW, cdecl (from info-server@sh.cs.net) is usually great for declaration
problems like this, but it doesn't seem to handle "void".

-- 
             --John Hanley
              System Programmer, Manhattan College
              soon to be a former E.E./CS undergrad (May is fast approaching!)
              ..!cmcl2.nyu.edu!manhat!jh  or  hanley@nyu.edu   (CMCL2<=>NYU.EDU)

kworrell@ccvaxa.UUCP (02/25/88)

You should read the document files on your distribution disks.
They give a good idea of how one is to use the interrupt feature
of the language.  Be careful of using the small model since the
interrupt jump table is obviously CS:IP pairs.  I don't have
the any code in front of me but I will post a very short handler
later today.  

------------------------------------------------------------------------
Kurt J. Worrell	                 USEnet1:    ihnp4!uiucuxc!ccvaxa!kworrell
Gould CSD-Urbana                 ARPAnet:    kworrell@gswd-vms.arpa
1101 E. University               !ARPAnet1:  kworrell@Gould.COM
Urbana, IL 61801                 !ARPAnet2:  kworrell@gswd-vms.Gould.COM
                                 BELLnet:    (217) 384-8500, x740                 

kworrell@ccvaxa.UUCP (02/25/88)

This is the program (a bit stripped down to the bar essentials).  All it
does is count clock ticks.  It is just the functions to set up the interrupt
vector, to remove it, and the function which is called when the interrupt
occurs.



#include <dos.h>

#define		CLOCKINTR	0x1C	 	/* clock intr vector */

void (interrupt far *oldtimer)();		/* addr of old clock intr */
long int clock_count = 0;			/* count of ticks */

install()
{
	void interrupt far handler();		/* declare ours */

	oldtimer = _dos_getvect(CLOCKINTR);	/* save old for reset */

	_dos_setvect(CLOCKINTR,handler);	/* set up our interrupt hdlr */
}

remove()
{
	_dos_setvect(CLOCKINTR, oldtimer);	/* unchain */
}

void interrupt far handler()
{
	clock_count++;				/* skip 18 tics */

#if defined(CHAINING)				/* chain to old handler */
	_chain_intr(oldtimer);
#endif	
}

------------------------------------------------------------------------
Kurt J. Worrell	                 USEnet1:    ihnp4!uiucuxc!ccvaxa!kworrell
Gould CSD-Urbana                 ARPAnet:    kworrell@gswd-vms.arpa
1101 E. University               !ARPAnet1:  kworrell@Gould.COM
Urbana, IL 61801                 !ARPAnet2:  kworrell@gswd-vms.Gould.COM
*** Standard Disclaimer ***      BELLnet:    (217) 384-8500, x740