How 2 write TSR's by Viper / Serenity

In my previous efforts to help you, I've manage to confuse you more than help you. I tried to give you some clues on a smaller TSR.

What is a TSR ( Terminate and Stay Resident ) ?
A tsr is a program that goes memory resident. Control of this program is freed from the user and the system ( DOS/WINDOWS ) takes control.

What is a ISR ?
A ISR (Interrupt Service Routine) is a program that goes resident but as soon as the program is terminated it DOES NOT stay resident.

TSR vs ISR
So whats the deal here? A TSR always starts out as an ISR and only if a special set of interrups are called will it Terminate and go memory resident.

So what does the TSR do?
Most times you program will chain itself to an interrupt like 0x9 which is the keyboard interrupt. Everytime you press a key interrupt 0x9 get polled ( called). Our TSR will attach itself on 0x9 so that our program also gets called. We can find out where the Adress of the program is that gets called by default. We then change the 0x9 vector to point to our program instead and when our program is done we call the old routine that would have been called. This is refered to as chaining the interrupt.

So how do we write a TSR ?
Here is the procedure you should follow

For our TSR problem int 0x8 is just fine. Beware of int 0x1c if you don't give controll back critical system functions could be lost.

Example of a ISR going TSR. TASM example.asm ; TLINK /t example.obj