🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7980

Re: Need help in TSR (80x86 asm) calling C

#7980
From: Ian MacLennan
Date: Thu, 25 Apr 1996 00:00
30 lines
2379 bytes
Minghua Yao wrote:
> 
> I have a C module which uses "fopen()" to open a file. When called by a C main(), the module works well and the file can be opened. But if 
this module is calle
> 
> The working enviroment is DOS. I use 80x86 assembly for The TSR and Borland C for the C module. The C module is resident part of the TSR.
> 
> Anybody's help will be greatly appreciated.

The problem is likely that you are calling a dos function from a TSR.  
When doing so,  you must check the InDos flag to make sure that the 
Int21h interrupt is not being run.  You see, int 21h is not reentrant, 
which means it can't be run again before it is finished running the 
first time.  If you invoke the TSR while a call to interrupt 21h is 
being made,  the interrupt call will be put on hold and your code will 
be called.  You said that your code opens a file.  This will most likely 
use int 21h to do so.  When int 21h is called again, it is already 
running.  This will have serious consequences on the operation of DOS,  
and usually causes a system crash.  What you need to do,  is call int 
21h, function 34h, before your tsr is loaded.  This will return the 
address of the InDos flag in ES:BX.  By checking this address you can 
tell when dos is running. (if it is, it will be 1, otherwise it will be 
0).  We still have the problem, however.  If dos is at the command line 
the indos flag is still set.  Therefore,  you need to also hook int 28h 
- the Dos idle flag.  Dos calls this interrupt when it is waiting for 
user input.  When everything is clear,  you can run your procedure to 
open a file.
		
						Ian MacLennan
Technical Details
Message-ID: <31801D9F.3A23@wchat.on.ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4ljfha$s8s@independence.ecn.uoknor.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f6aa,c9a50b8babe96bc5
X-Google-Attributes: gid10f6aa,public
X-Google-Thread: 10d683,c9a50b8babe96bc5
X-Google-Attributes: gid10d683,public
X-Google-Thread: f7d8d,c9a50b8babe96bc5
X-Google-Attributes: gidf7d8d,public
From: Ian MacLennan <petermac@wchat.on.ca>
Subject: Re: Need help in TSR (80x86 asm) calling C
Date: 1996/04/25
Message-ID: <31801D9F.3A23@wchat.on.ca>
X-Deja-AN: 151469187
references: <4ljfha$s8s@independence.ecn.uoknor.edu>
content-type: text/plain; charset=us-ascii
organization: WorldCHAT (tm) Internet
mime-version: 1.0
newsgroups: comp.os.msdos.programmer,alt.lang.asm,aus.computers.ibm-pc
x-mailer: Mozilla 2.01 (Win95; I)