timemachine
Boom Bhadam Dhishkyao
Terminate and Stay Resident(TSR) is a system call in the DOS operating systems that returned control to the system as if the program had quit, but kept the program in memory. Many times reffered as multitasking in DOS.
A DOS based C compiler( such as Turbo C++) offers 640KB of memory and for DOS 1 MB of memory is allocated. TSR uses the extended memory, i.e. the 1MB memory by the use of far pointers. A memory area is allocated and the program actively resides in it. Conventionally, when a program or a command is executed, the whole control is transferred to it. In this case the program actively resides in the memory.
Here is a sample code which shows the working of a TSR. This TSR program hooks itself with timer interrupt and selects a random row and coloums position at each run and writes space at that position, the person using the computer feels that something is eating up the characters from the screen.
Here the hex memory address 0xb8000000 refers to memory location of the VDU memory. In the function mytimer, the random numbers from 80 and 25 are picked. These are the row number and the column number. Then the writechar function puts a blank character at that place. This program continues when the DOS is open. The program name will be displayed in the title bar if you are in the window mode.
Remember that its only in dos. You must go to the command line and then run the exe of the program or you will not be able to view any response of the program. I insist perform a dir command and then you will be able to see the right work of code. By this screen will be filled by some characters and the blank spaces will be seen easily.
More information related to TSR will be attached to the thread. Respond if you like my first post : TIMEMACHINE.
A DOS based C compiler( such as Turbo C++) offers 640KB of memory and for DOS 1 MB of memory is allocated. TSR uses the extended memory, i.e. the 1MB memory by the use of far pointers. A memory area is allocated and the program actively resides in it. Conventionally, when a program or a command is executed, the whole control is transferred to it. In this case the program actively resides in the memory.
Here is a sample code which shows the working of a TSR. This TSR program hooks itself with timer interrupt and selects a random row and coloums position at each run and writes space at that position, the person using the computer feels that something is eating up the characters from the screen.
#include"dos.h"
#include<conio.h>
#include<stdlib.h>
//interrupt declarations
void interrupt (*prevtimer)();
void interrupt mytimer();
void writechar(char ch,int row,int col,int attr);
//a far pointer that will access video memory
char far* scr;
int a,b;
//our real program goes from here
void main()
{
scr=(char far*) 0xb8000000;
prevtimer=getvect( 8 );
setvect(8,mytimer);
keep(0,1000);
}
//timer function
void interrupt mytimer()
{
a=random(25);
b=random(80);
writechar(' ',a,b,0);
(*prevtimer)();
}
//function that writes picked up character
void writechar(char ch,int row,int col,int attr)
{
*(scr+row*160+col*2)=ch;
*(scr+row*160+col*2+1)=attr;
}
Here the hex memory address 0xb8000000 refers to memory location of the VDU memory. In the function mytimer, the random numbers from 80 and 25 are picked. These are the row number and the column number. Then the writechar function puts a blank character at that place. This program continues when the DOS is open. The program name will be displayed in the title bar if you are in the window mode.
Remember that its only in dos. You must go to the command line and then run the exe of the program or you will not be able to view any response of the program. I insist perform a dir command and then you will be able to see the right work of code. By this screen will be filled by some characters and the blank spaces will be seen easily.
More information related to TSR will be attached to the thread. Respond if you like my first post : TIMEMACHINE.
Last edited: