1. T S R

TSR which give programming in C and C++ a Big and Wide Diversion and  opens a new world of Hackers and Crackers and normal programmers.

1. Hackers are Programmers which are sitting on Pc's for a long time in trying to give world some new and amazing. They are not like the one who destroys something but they are the one's who invent  new languages and utilities.Like Brian W kernighan and Denis M Ritiche were hackers who invented C language in Bell Laborataries.

2. Crackers are the one whose sole intention is to enter in to some on'e security and delete files or do some destructive works.


What Is TSR

Programs which remain running and resident in memory while other programs are running are the most exciting line of programming for many PC developers. This type of program is known as a "Terminate and Stay Resident" or "TSR" program. eg.(Operating Doskey, etc.)

In theory a TSR is quite simple. It is an ordinary program which terminates not through the usual DOS terminate function, but through the DOS "keep" function - interrupt 27h. This function reserves an area of memory, used by the program so that no other programs will overwrite it. This in itself is not a very difficult task, excepting that the program needs to tell DOS how much memory to leave it!

Basically to make a TSR program we have to decide which interrupt to catch.What i mean is that we have to decide when to pop up the TSR. Like if we want that it should popup when user has pressed F1 key or any key we have to catch the keyboard interrupt.

Likewise if you wanna popup TSR after every 2 minutes we have to capture Timer interrupt or if you wanna make TSR active when any reading or writing on hard disk is done you have to capture that interrupt which governs the task.Poping a TSR means that the code executes from the ashes ie. the code portion which we make resident and was not responding is now to be executed. In our TSR code first we have to capture the interrupt ie we have to get it's address where in the memory it is stored then we have to replace the address with the address of our code and then within our code we have to call the actual procedure after or before executing our code.

The difficulties in programming TSRs comes from the limitations of DOS which is not a multi-tasking operating system, and does not react well to re-enterant code. That is it's own functions (interrupts) calling themselves. The problems stem mainly from not being able to use DOS function calls within the TSR program once it has "gone resident".

There are a few basic rules which help to clarify the problems encountered in programming TSRs:

1. Avoid DOS function calls
2. Monitor the DOS busy flag, when this flag is nonzero, DOS is executing an interrupt 21h function and MUST NOT be disturbed!
3. Monitor interrupt 28h. This reveals when DOS is busy waiting for console input. At this time you can disturb DOS regardless of the DOS busy flag setting.
4. Provide some way of checking whether the TSR is already loaded to prevent multiple copies occuring in memory.
5. Remember that other TSR programs may be chained to interrupts, and so you must chain any interrupt vectors that your program needs.
6. Your TSR program must use its own stack, and NOT that of the running process.
7. TSR programs must be compiled in a small memory model with stack checking turned off.
8. When control passes to your TSR program, it must tell DOS that the active process has changed.


TSR To Trap Keyboard Interrupt

This program if you press DEL key from the keyboard it automatically adds the CTRL and ALT key so that your system(if run from dos mode) or your dos prompt. To run this program at the dos prompt type DELETEKEYTSR.EXE and see the output at top of the screen.


/* DeletekeyTSR.C */

#include<dos.h>

void interrupt our();
void interrupt (*prev)();
char far *kb=(char *)0x417;

void main()
{
 prev=getvect(9);/*get the keyboard ISR address*/
 setvect(9,our);/*set our function address*/
 keep(0,1000);
}

void interrupt our()
{
  if(inportb(0x60)==0x53 &&(*kb&12)==12)
    outportb(0x20,0x20);
   else
    (*prev)();/*call the ISR*/
}


TSR To Trap Timer Interrupt

This is a simple program which displays my name starting from 'S' to 'K' and then again starting from 'S'  at the top of screen at fifth position. To run this program at the dos prompt type TIMERTSR.EXE and see the output at top of the screen.

/*TimerTSR.C*/

#include<dos.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void interrupt our(...);
void interrupt (*prev)(...);
char far *scr=(char far*)0xB0008000L;
int ticks;
int i=67;
int j=0;
char str[]="SATENDRA PAL";

void main()
{
 prev=getvect(8);/*get the timer ISR address*/
 setvect(8,our);/*set our function address*/
 keep(0,500);
}
void interrupt our(...)
{
 ticks++;
 if(ticks==18)
  {
   *(scr+5*2)=str[j];
   *(scr+72*2)=str[j];
   *(scr+24*80*2+5*2)=str[j];
   *(scr+24*80*2+72*2)=str[j++];
   if(j==13)
      j=0;
   ticks=1;
  }
 (*prev)();/*call the actual ISR*/
}


Under Construction


About Me  ||   My Family  ||   My Friends  ||   Photo Gallery  ||   My Diary  ||   My Resume
Few Treasures   ||   Music   ||   Some Cool Links  ||   Contact Address
Back To Home