Solved

DOS TSR's with file access (2)

Posted on 1998-08-31
1
163 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

15 Experts available now in Live!

Get 1:1 Help Now