Solved

DOS TSR's with file access (2)

Posted on 1998-08-31
1
165 Views
Last Modified: 2006-11-17
(for nietod...)
Hi, I want to code a DOS tsr. When the user press some
kind of "hot key" the tsr must open a text file and read
some lines from it and close it again. As soon as the file
is opened, the pc hangs. Any suggestions?
0
Comment
Question by:Claude050897
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 300 total points
ID: 1171674
My contributions From: http://www.experts-exchange.com/topics/comp/lang/cplusplus/Q.10075784
************************************************
Claude.  DOS was never really meant to have TSRs.  Most DOS procedures are
not reentrant.  Meaning if they are already running, they cannot be run a
second time (safely that is, they can always be run a second time).  This is
because DOS uses static memory to store parameters and other data structures
rather than storing them on the stack.  So if the DOS file procedures are
currently running when you interrupt and reinvoke them you will cause a
crash.

To prevent this you need to check the undocumented "indos" flag.  This is a
flag that DOS sets when it has entered a non-reentrant procedures.  You must
wait until that flag has cleared before calling DOS procedures..

Note that do not want to enable interrupts until you have executed all
non-reentrant code of your own.  Your file procedures use static variables,
so you don't want to enable interrupts while you are using them.  The DOS
handler is not reentrant either, so you don't want to enable interrupts
before calling it.

I see the old handler call now.  but you still need to wory about
reentrancy, both of your procedures and DOS.  The old handler will enable
interrupts so you don't need to.  However, once it does your procedure could
be called again (while already running).  Take that into account.

You can use DOS service function 34H to get a pointer to the indos flag.
Place 34H in AH and execute int 21.  ES:BX points to a 1 byte flag.  If it
is zero, you can safely use DOS functions, if not, you can't Given your
circumstances, you can use the keyboard to set a flag or record other
information, but not actually do the file i/O.  You can do the file I/O on a
timer interrupt.  That way if on one timer interupt you can't use DOS, you
can wait and do it on the next.

Another posibility is to forget DOS altogether and use the BIOS to perform
your I/O.  This is (well was) often done.
******************************************
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Move constructor only called if marked noexcept? 6 98
thread-safe code in c++ 2 84
Setting nameservers after res_init fails doing res_query 2 85
Issues with C++ Class 19 80
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now