Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!rutgers!mtune!westmark!dave From: dave@westmark.UUCP (Dave Levenson) Newsgroups: comp.sys.ibm.pc Subject: Re: Writing a TSR in C Message-ID: <116@westmark.UUCP> Date: 26 Feb 88 02:00:17 GMT References: <5527@burdvax.PRC.Unisys.COM> Distribution: na Organization: Westmark, Inc., Warren, NJ, USA Lines: 40 Summary: MS-C 5.0 Does it for you In article <5527@burdvax.PRC.Unisys.COM>, coltoff@PRC.Unisys.COM (Chilly Willy) writes: > I need to write a TSR in C. Actually I want to write it in C > since assembler is a royal pain in the posterior end. It is > actually a very simple task that I need to do but I'm a PC > novice and don't know about all the little gotchas hiding > hither and yon. Joel: In Microsoft C Release 5.0 (the latest, as of this date) you can code a function as: interrupt void foo() { ... } The code generated for such a function saves the machine state, and upon reaching the return (or final } of the code) generates an iret rather than a subroutine return. This means that you can write your interrupt service routine in C. They also supply runtime library calls to several MS-DOS system functions that are helpful here: Terminate and stay resident (aka keep process) and set vector. If your main() function sets a the interrupt vector to be a pointer to another function of type interrupt, and then calls the keep process function, you've installed your code. The gotchas begin when your interrupt service function issues dos system calls. If dos was executing when the interrupt happened, you may run into the lack of re-entrancy in the dos kernel. There are arcane and poorly-documented ways of handling this, depending on what your interrupt function has to do. -- Dave Levenson Westmark, Inc. A node for news. Warren, NJ USA {rutgers | clyde | mtune | ihnp4}!westmark!dave