C Programming (Turbo C++ Compiler) - Terminate and Stay Resident Program (TSR) Scrolling Text Sample
I have given here a sample program for TSR which stands for Terminate and Stay Resident. It is easy to implement but you need to know about interrupt service routines and their functions.
TSRScrol.EXE -i "welcome to softwareandfinance.com" will install the scrolling text.
TSRScrol.EXE -u will stop the scrolling text.
Source Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <bios.h>
#define INTR 0X1C
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
char far *scr=(char far*)0xB0008000L;
void interrupt ( *oldhandler)(__CPPARGS);
int count=0;
char message[64];
int len = 0;
struct time t;
void interrupt handler(__CPPARGS)
{
static int delayctr = 0;
static int begpos = 0;
int endpos = 79 - len;
int i = 0;
char far *p = scr;
if(++delayctr > 5)
{
delayctr = 0;
}
else
{
oldhandler();
return;
}
for(i = 0; i < begpos; i++)
{
p++;
p++;
}
for(i = 0; i < len; i++)
{
*p++ = message[i];
*p++ = 0x00;
}
p = scr;
begpos++;
if(begpos == endpos)
begpos = 0;
for(i = 0; i < begpos; i++)
{
p++;
p++;
}
for(i = 0; i < len; i++)
{
*p++ = message[i];
*p++ = 0x4f;
}
oldhandler();
}
int main(int argc, char *argv[])
{
if(argc <= 1)
{
printf("Syntax: TSRScroll -I \"Message\" (for Install)\n");
printf("Syntax: TSRScroll -U (for Uninstall)\n");
return 0;
}
strcpy(message, argv[2]);
len = strlen(message);
if(argv[1][1] == 'I' || argv[1][1] == 'i')
{
printf("Installing...\n");
oldhandler = getvect(INTR);
setvect(INTR, handler);
setvect(32, oldhandler);
printf("Done\n");
}
else
{
printf("Uninstalling...\n");
oldhandler = getvect(32);
setvect(INTR, oldhandler);
printf("Done\n");
}
return 0;
}
Click here to download the source code and .EXE application
Output
|