[comp.binaries.ibm.pc.d] Writing TSRs

thf@wind.bellcore.com (Theodore Feyler) (11/02/88)

Hey there,

With all this talk about changing the switch character in dos so that it
appears more like UN*X I got to wondering.....

What I want is a program that, like UNCLE, changes all occurences of the
slash character on the command line to a back slash character.  I would use
UNCLE, but it also changes the back slash to the slash which makes things
worse for me.  BUTTTTT, I don't know how to write a TSR.  I have MS C 5.1
on a ibm ps/2 model 50.  I am a C programmer by trade (and religion), but
this is my first attempt at PC type programming.  The MS C Run Time Library
Reference discusses the system call 0x31 and the function _dos_keep() which
will exit the program leaving it in memory.  I don't get it.  If you're 
gonna exit the progarm, how can it do anything after the system call statement?

Any help would certainly be appreciated.

Thanks in advance,
ted 

P.S.  If anyone has the MS C source (or partial source) for a TSR that
      they could mail me - it would be perfect.

spam@sun.soe.UUCP (Roger Gonzalez,,,) (11/02/88)

> Reference discusses the system call 0x31 and the function _dos_keep() which
> will exit the program leaving it in memory.  I don't get it.  If you're 
> gonna exit the progarm, how can it do anything after the system call statement?

Very briefly, you write a piece of code that you want executed, and put its
address in the interrupt table under whatever interrupt you want to have
activate it (i.e. INT5 (I think) is the print-screen interrupt, and there
are others for various functions like hitting any keyboard key, disk access
(a favorite of virus programs) etc etc ad nauseum)
You then do the *T*erminate and *S*tay *R*esident call, which leaves your
program in memory, and returns to DOS.
When your hooked interrupt is "activated" (or whatever it's called) it
finds the address of *your* routine in the table, and executes it. 
Great. Unfortunately, if you didn't save the original copy of the interrupt
(the address that it was supposed to go to before you hijacked it),
DOS will probably be unhappy with you. So you then do a long jump to 
the address that you saved. By the way, there's some stuff you should
do first, like saving the flags, etc.  
This is how it works in assembly; I've never done it in C, but it
should be similar.

Good luck,
-rg-