Solved

DOS TSR's with file access (2)

Posted on 1998-08-31
1
191 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

687 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