Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!itsgw!steinmetz!sagittarius!dixon From: dixon@sagittarius.steinmetz (walt dixon) Newsgroups: comp.sys.ibm.pc Subject: Re: Disk I/O in Resident MS-DOS Program Summary: no problem if done correctly Keywords: TSR Message-ID: <13169@steinmetz.ge.com> Date: 17 Feb 89 13:32:33 GMT References: <1872@holos0.UUCP> Sender: news@steinmetz.ge.com Reply-To: dixon@sagittarius.steinmetz.ge.com (walt dixon) Distribution: usa Organization: General Electric CRD, Schenectady, NY Lines: 38 Writing programs which run in the background under MS-DOS is a kludge at best. The existance of the print.com proves that it is possible for one to construct these applications. Print relies on some undocumented DOS services. The bottom line is that you must have a thurough understanding of DOS internals before attempting to write a TSR which needs to make any int 21h requests. I would strongly recommend reading chapter 4 of the MS-DOS Developers Guide 2nd Edition (Howard Sams, 1988). Please note, although I am the author of this chapter, I get no royalties; I'm just citing a known good reference. I'll briefly describe the problem that you are experiencing. MS-DOS stores the address of the Job File Table (JFT) in the program segment prefix. (In most cases the JFT itself is also in the PSP, but there is no guarantee). The file handle is an index into the JFT. JFT entries are System File Numbers (SFNs) which are indicies into the System File Table (SFT). Each SFT entry maintains file position and instructs DOS how to find the correct device driver. When you make a handle i/o request, DOS uses the current PSP to find the correct SFT entry. If your program is in the foreground, DOS will not have any trouble. If a TSR asnychronously decides that it wants to make a handle request, it must ask DOS to change the current PSP. (current PSP is a global variable maintained by MS-DOS). (Int 21H AH=50, BX=PSP changes the current PSP. This function is undocumented). There is a certain amount of houskeeping one must do before changing the PSP including recording the previous PSP and establishing your own break handler. You should set up a critical error handler before performing any io. Now another observation. If you are writting a communications application, you cannot always rely on trapping int 21h requests. Your internal buffer may fill up while then foreground program is compute bound or waiting for console I/O. You should be using int 28H and a timer interrupt as well. You must be particularly careful of the timer interrupt. Walt Dixon {arpa: dixon@ge-crd.arpa } {us mail: ge crd } { po box 8 } { schenectady, ny 12345 } {voice: 518-387-5798 }