Solved

TSR Guru needed

Posted on 1998-11-13
6
190 Views
Last Modified: 2010-04-15
I have writen a TSR for DOS that displays the current files is use. This is done by traversing the DOS Systems File Table the pointer to which can be retrieved by an INT 21,34 call.
When the Hot Key is detected I need to build my own Stack for the TSR's local variables and functions. Otherwise it will use the foreground program's Stack and the results would be very unpredictable. I achive this with the following code.
1. _asm
2. {
3.    mov ss_register, ss
4.    mov sp_register, sp
5.    mov ax, offset my_stack[499]
6.    mov sp, ax
7.    mov ax, ds
8.    mov ss, ax
9. {
in line 3 & 4 i save the SS and SP in to my own variables. and in line 5 & 6 I move the SP to the top of my newly built Stack (my_stack). My doubt hear is that my_stack is a global variable. Hence I am actually creating this Stack in the Data Segment.
* Firstly is their any problems in doing this??

As to the size of the Stack I allocated 500 bytes taking into account the following local variables and one function which I am using in the code that uses this Stack.
    struct table_tag {
                        struct table_tag * table_previous;
                        struct table_tag * table_next;
                        long int _far * table_sft;
                        int table_sft_entries;
                     };
    typedef struct table_tag * TABLE_POINTER;
    TABLE_POINTER current_table, previous_table,          first_table;
    char * save_screen;
    char page_entry[21];
    long int _far * current_sft;
    char _far * table_sft_file;
    char _far * video_position;
    int no_of_elements, no_of_pages, page_tag_element,         general_counter,general2_counter;
    int table_sft_counter, key_press, key_scan,         element_counter;
/* and the function */
PaintPicture()
{
    int general_counter, general2_counter;
    char _far * video_position;
* Is 500 bytes adequet for these variables and one function??

I am using MS C ver 7. When I call the TSR through the Hotkey, the routine pops us and works fine. But when I exit the routine I get a runtime error "Stack Overflow" and the foreground program terminates to the DOS prompt. I cannot run any more programs thereafter. The COMMAND interpertor gives "Program too big" even for the simple MEM program. When I compile without Code Optimization and without Stack Probes, the program simply hangs along with the OS.

What is wrong in what I am doing? and how could I solve this problem?
Any help would be much apreciated.
0
Comment
Question by:ravipal
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1254249
Did you restore the SS and SP to it's original values (in ss_register and sp_register) when the program finishes?
0
 

Author Comment

by:ravipal
ID: 1254250
Hi scrapdog,

Yes I did restore the SS and SP, with the following code.

    _asm
    {
        mov ss, ss_register
        mov sp, sp_register
    }

0
 

Author Comment

by:ravipal
ID: 1254251
One more thing I fogot to mension. In side my routine I am building a Link List to link all the individual DOS System File Tables into one. For this I use the runtime function "maclloc".

Could their be any problem in using this function in side my TSR routine ??
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 5

Accepted Solution

by:
laeuchli earned 70 total points
ID: 1254252
the site :http://www.fys.ruu.nl/~faber/Amain.html has lots of stuff on tsrs. Take a look.

0
 

Author Comment

by:ravipal
ID: 1254253
Hi Scrapdog,

I am still waiting for your response...


0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1254254
Beats me...you probably know more than I do about TSRs!!

I was just checking if you restored SS and SP, because I know if you didn't that would cause problems.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with MFCApp 78 383
How do I set up two external hard drives with Acronis True Image? 12 87
Super Scope, DHCP 5 77
What is sub-make ? 2 60
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question