waters@mosaic.dec.com (06/09/86)
The answer is: you can't do it (easily). The problem that you are having is that MS-DOS (PC-DOS) is NOT re-entrant. By re-entrant, I mean that you cannot interrupt DOS while it is doing something and make another DOS call. You may be sitting idle and apparently doing nothing, but DOS is still busy (i.e., the timer tick goes into DOS to update the time, waiting for keyboard input, etc.). There is a flag called the "INDOSFLAG" which you can test to see if you can make a DOS call. When the flag is set, you should not make ANY DOS calls. When it is clear, you can make a DOS call. The flag is NOT a supported feature and is not fullproof (though many people have used it successfully). The location and availability of the flag is also very version dependent. You program should check the DOS version number before making itself resident (and issue an error if it is run under a different version of DOS). There is an undocumented DOS call which you can use to determine the location of the INDOSFLAG. MOV AH,34h INT 21h Now ES:BX points to the location of the flag. The flag does not move, so your program can save the pointer away (i.e., it is not necessary to make this call every time you need to check the INDOSFLAG -- just make it once when your program is first run. Now, there is a problem: what do you do if the flag is set (indicating that DOS is busy)? You can't just loop waiting for the flag to change since DOS needs to get some run time so it can finish what it was doing (when it was interrupted). The only way to do that is to return from your ISR. Yep, this means that you may want to SCHEDULE an event to take place (namely, to make your DOS call). So, you may write a second ISR, which hangs off of the timer tick interrupt 1Ch (see your systems Tech reference). Then, your ISR can set a flag indicating that you want your DOS call to be made (asynchronously to what you are doing). The timer tick ISR will check this flag, and if set, look at the INDOSFLAG. If the INDOSFLAG is clear, it can then make your DOS call. If the INDOSFLAG is still set, just wait till the next clock tick and try again. When writing a clock tick ISR for interrupt 1Ch, remember to chain the old vector (because there may be other processes hooked to the 1Ch vector). What I mean is, instead of doing an IRET from your routine, do a JMP FAR to the old address contained in the vector before you hooked the interrupt. In general, it is not a good idea to make DOS calls from ISR routines. The INDOSFLAG is very version dependent, NOT SUPPORTED, and not the most reliable thing (though, as I have said, many people have used it successfully). I'm sure this message will be one of MANY that you will receive... Good luck! Lester Waters ...!decvax!decwrl!dec-rhea!dec-viking!waters (UUCP) WATERS%VIKING.DEC@DECWRL.COM (Arpa) Disclaimer: These views do not necessarily represent the views of Digital Equipment Corporation, the mailman, or the Pope. The names were changed to protect the innocent. Any similarities to reality are purely coincidental.