?
Solved

DOS TSR's with file access (2)

Posted on 1998-08-31
1
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 900 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

765 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