Close Back

#pragma inline

#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<alloc.h>
#include"tsr.h"

#undef putchar()
#undef getchar()

#define ALT 8
#define C 46

#define CHECK_INSTALLED 0xC001
#define SUCCESS 0xC002
#define FAILURE 0xC003
#define UNINSTALL 0xC004

struct INTERRUPT
{
	unsigned bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
};

void interrupt (*prev_8)();
void interrupt our_8();

void interrupt (*prev_9)();
void interrupt our_9();

void interrupt (*prev_28)();
void interrupt our_28();

void interrupt (*prev_2f)();
void interrupt our_2f();

unsigned size,key,ss,sp,px,py,our_psp;

unsigned short want_to_popup,active;

unsigned char far *dosbusy,far *kb = (unsigned char far *)0x417;

char far (stack[4000]);

union REGS ip,op;

int store;

main(int no_of_args,char *args[])
{
	if(no_of_args == 1)
	{
		ip.x.ax = CHECK_INSTALLED;
		int86(0x2f,&ip,&op);
		if(op.x.ax != SUCCESS)
		{
			buffer = malloc((16-10)*160+(76-2)*2);
			if(buffer == NULL)
				printf("\nInsufficient memory.. Try quitting one or more TSRs");
			else
			{
				our_psp=getpsp();

				getdosflag();

				captureint();
				/*
				ebptr=MK_FP(our_psp,0x2c);
				freemem(*ebptr);
				*/
				size = (_DS - _psp)+((unsigned)buffer+((15-10)*160+(75-2)*2));

				keep(0,size);
			}
		}
		else
			printf("\nTSR already in memory ! .. Try pressing ALT + C");
	}
	else if(no_of_args == 2 && !strcmpi(args[1],"\\u"))
	{
		ip.x.ax = CHECK_INSTALLED;
		int86(0x2f,&ip,&op);
		if(op.x.ax == SUCCESS)
		{
			printf("\nUninstalling...");

			ip.x.ax = UNINSTALL;
			int86(0x2f,&ip,&op);

			if(op.x.ax == FAILURE)
				printf("\nUninstalling failed ! please reboot the computer");
			else if(op.x.ax == SUCCESS)
				printf("\nUninstallation successfull");
		}
		else
			printf("\nTSR not in memory");
	}
}

getdosflag()
{
	input.h.ah = 0x34;
	intdosx(&input,&output,&sregisters);
	dosbusy = (char far *) MK_FP(sregisters.es,output.x.bx);
}

captureint()
{
	prev_8 = getvect(8);
	setvect(8,our_8);

	prev_9 = getvect(9);
	setvect(9,our_9);

	prev_28 = getvect(0x28);
	setvect(0x28,our_28);

	prev_2f = getvect(0x2f);
	setvect(0x2f,our_2f);
}

void interrupt our_8()
{
	(*prev_8)();

	if(want_to_popup==1 && *dosbusy == 0 && active == 0)
		popup();
}

void interrupt our_9()
{
	key = inportb(0x60);
	if(key == C && (*kb&ALT) == ALT)
		want_to_popup=1;

	(*prev_9)();
}

void interrupt our_28()
{
	(*prev_28)();

	if(want_to_popup==1 && *dosbusy <= 1 && active == 0)
		popup();
}

popup()
{
	active = 1;

	ss = _SS;
	sp = _SP;

	savewin(10,2,16,76);

	disable();
	_SS = FP_SEG(stack);
	_SP = FP_OFF(stack+3999);
	enable();

	px=wherex();
	py=wherey();

	realfunction();

	disable();
	_SS=ss;
	_SP=sp;
	enable();

	gotoxy(px,py);

	restorewin(10,2,16,76);

	active = 0;
	want_to_popup=0;
}
realfunction()
{

}
void interrupt (*prev_1b)();
void interrupt (*prev_23)();
void interrupt ctrlbrk_dis();

void interrupt ctrlbrk_dis()
{
}

capctrlbrk()
{
	prev_1b = getvect(0x1B);
	setvect(0x1B,ctrlbrk_dis);

	prev_23 = getvect(0x23);
	setvect(0x23,ctrlbrk_dis);
}

relctrlbrk()
{
	setvect(0x1B,prev_1b);
	setvect(0x23,prev_23);
}

void interrupt our_2f(struct INTERRUPT r)
{
	if(r.ax == CHECK_INSTALLED)
	{
		r.ax = SUCCESS;
		return;
	}
	if(r.ax == UNINSTALL)
	{
		r.ax = uninstall();
		return;
	}
	asm pop bp
	asm pop di
	asm pop si
	asm pop ds
	asm pop es
	asm pop dx
	asm pop cx
	asm pop bx
	asm pop ax
	asm jmp cs:_prev_2f;
}
int uninstall()
{
	if(our_2f == getvect(0x2f))
	{
		setvect(0x2f,prev_2f);
		setvect(9,prev_9);
		setvect(8,prev_8);
		setvect(0x28,prev_28);

		freemem(our_psp);

		return(SUCCESS);
	}
	else
		return(FAILURE);
}

getstring(char chr[])
{
	char ch;
	int i;
	while((ch = getchar()) != '\n')
		chr[i++]=ch;
	chr[i]='\0';
}