Article View: comp.sys.ibm.pc
Article #26030Re: IBM-PC/DOS: Writing TSRs in C.
From: Dipto Chakravarty
Date: Fri, 01 Apr 1988 01:49
Date: Fri, 01 Apr 1988 01:49
80 lines
3852 bytes
3852 bytes
In article <5132@sigi.Colorado.EDU> murillo@boulder.Colorado (Rodrigo) writes:
>
>Does anybody have experience in writing TSRs for DOS in C. I would like
>to get a hold of some C source that would show the basic principles of
>writing a TSR ...
Recently, a couple of books have been published on this topic.
If I remember them right, then they are the following :-
(1) MEMORY RESIDENT PROGRAMMING ON THE IBM PC
Author: Wadlow; Publisher: Addison Wesley
(2) WRITING MEMORY RESIDENT PROGRAMS IN TURBO `C' {Check thru the}
Author: (don't remember ... sorry) {title citation}
{in bookstores.}
The first book is a superb introduction to RAM resident programming
techniques. The second text talks about the Interrupt Vector Table
manipulation, and provides some in-built utilities (pre-written in
Assembly, I think) with the help of which one can alter the IVT of
the PC's memory.
The most fundamental principle of writing these fabulous
RAM resident programs is to understand how to alter the Interrupt
Vector Table.
> ... how to trap the keyboard interrupt to watch for hot keys.
The software keyboard interrupt (I think it is 14H) works at the
DOS level. One should be able to play with this and hack this
code to work by trapping the 14H signal with the int86() function.
Here is a code fragment to trap an interrupt:
----- { I used the Microsoft }
#include <signal.h> { `C' functions here }
#include <dos.h> { The calls in Turbo C }
#include <stdio.h> { differ slightly. }
#include <process.h> { Refer Turbo C manual.}
#define CNTL_C 0x23
/* the e.g. here traps interrupt */
int int_handler(int); /* number 0x23; the values in the */
/* regs struct may/may not matter */
union REGS regs;
.
.
signal(SIGINT, int_handler);
.
.
int86(CNTL_C, ®s, ®s);
Now, you may want to think twice before messing with hardware
keyboard interrupt. The value is interrupt number 09H, I think.
This means that you will begin hacking around at the ROMBIOS
level. This, definitely is a cool way to trap the keyboard signal
but be aware of the facts before this technique is attempted. I
once crippled my keyboard real good! :-)
INCORRECT interrupt trapping techniques at the ROMBIOS level
(specially for the keyboard) is really as messy as getting into
a Lisp interpreter, doing a ``(defun exit (.....))'' incorrectly,
.... and, then attempting to exit out of Lisp in normal ``(EXIT)''
way! :-)
I strongly recommend that program testing should be done using an
innocent interrupt like the "timer tick".
Good Luck!
P.S: I encountered some problems (bugs?) with Turbo `C' at the
time of program development. Microsoft, in my view is safe
to use. At the interrupt driver level, when one is screwing
around with the hardware interrupts and ROMBIOS the compiler
+ the linker + the library ought to be absolutely bug-free.
Enjoy!
--
BITNET : dipto@umbc.BITNET ------\
ARPANET: dipto@umbc3.UMD.EDU -------> In-real-life: Dipto Chakravarty
USMAIL : CMSC, UMBC,Md 21228 ------/
Technical Details
Message-ID:
<917@umbc3.UMD.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!nrl-cmf!cmcl2!brl-adm!umd5!umbc3!diptoReferences:
<5132@sigi.Colorado.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!nrl-cmf!cmcl2!brl-adm!umd5!umbc3!dipto From: dipto@umbc3.UMD.EDU (Dipto Chakravarty) Newsgroups: comp.sys.ibm.pc Subject: Re: IBM-PC/DOS: Writing TSRs in C. Message-ID: <917@umbc3.UMD.EDU> Date: 1 Apr 88 01:49:36 GMT References: <5132@sigi.Colorado.EDU> Reply-To: dipto@umbc3.UMD.EDU (Dipto Chakravarty) Organization: University of Maryland, Baltimore County Lines: 80