Solved

DOS TSR's with file access (2)

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

840 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