Category : Files from Magazines
Archive   : PCTV1N4.ZIP
Filename : TSRMEM2.C

 
Output of file : TSRMEM2.C contained in archive : PCTV1N4.ZIP
/*
These variables define the stack segment and offset
to be used by the TSR.
*/
unsigned my_ss, my_sp;

/*
Minimum number of paragraphs required for TSR's
stack.
*/
#define MIN_STACK 0x40

/*
Install a TSR.
Keep enough memory for the dynamic heap and stack.
The 'heap' and 'stack' parameters are the number of
paragraphs required by the heap and stack
respectively.
*/
void install_tsr(unsigned heap, unsigned stack)
{
unsigned PSP, EODATA, keeplen;

/*
Get beginning and end of program memory.
*/
PSP = GetPSP();
EODATA = EndPrg();

/*
Make sure we have enough stack space.
*/
stack = max(MIN_STACK, stack);

/*
Amount of memory required is (program size + heap +
stack).
*/
keeplen = EODATA - PSP + heap + stack;

/*
Stack comes after data segment and heap and grows
down in memory.
*/
my_ss = EODATA;
my_sp = (heap + stack) * 16;

/*
keep(status, size) is a Turbo C function that keeps
'size' paragraphs in memory and exits to DOS with
status 'status'. It uses DOS function 0x31.
*/
keep(0, keeplen);
}

/*
Initialize TSR stack, run the TSR, restore
interrupted program's stack, and return control to
interrupted program.
*/
void init_tsr(void)
{
/*
These must be static variables because local
variables are addressed from the stack, which we
will be changing.
*/
static unsigned old_ss, old_sp;

/*
Save old stack frame. _SS and _SP are Turbo C
pseudo-variables that directly address the SS and SP
registers.
*/
old_ss = _SS;
old_sp = _SP;

/*
Set up the TSR stack. disable() and enable() are
Turbo C pseudo-functions that disable and enable
interrupts. The last thing we want is for an
interrupt to occur while we're changing the stack!
*/
disable();
_SS = my_ss;
_SP = my_sp;
enable();

/*
run_tsr() is user-defined, i.e. implemented by the
programmer.
*/
run_tsr();

/*
Restore original program's stack.
*/
disable();
_SS = old_ss;
_SP = old_sp;
enable();
}


  3 Responses to “Category : Files from Magazines
Archive   : PCTV1N4.ZIP
Filename : TSRMEM2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/