[comp.sys.ibm.pc] Help with sharing memory in DOS...

mtsu@blake.acs.washington.edu (Montana State) (07/12/89)

I have written a TSR that reads characters off of the comm port, filters them,
and saves the important information in a buffer allocated inside the TSR.

Suppose the buffer name is 'aldsdata', TSR name is 'x100'...  Now I want to
write a program to yank the data out of 'aldsdata', from the foreground...

How do I find the address of 'aldsdata' inside the TSR??


Specifics:

Machine:	Zenith Z-248
Language:	Turbo C 2.0


I'm guessing something like store the address of aldsdata in an interrupt
vector, then declare a far pointer and put the address of aldsdata in that...
But it ain't worked yet.


I'm not a PC person by any means, so please, use simple words :-).

Thanx for any assisstance.

Jaye Mathisen
icsu6000@caesar.cs.montana.edu

You know, this whole problem would be trivial if DOS was Unix...

wnr@otter.hpl.hp.com (Nigel Rea) (07/13/89)

Hi,
   I can think of 2 solutions to the shared memory problem.

1. stick the information ,in a DOS file. If this file is on a RAM disk then
information transfer should be fairly quick. This does raise the problem of
making sure that it is safe to call the DOS file I/O routines if your TSR is
invoked by an interrupt.

2. Write it as a character device driver, and ensure that the buffer is at the
start of the program. you can then read information from the buffer as you 
could read it from a file. You can see this in action of you try to TYPE some
of the drivers already present on your system.
e.g. try TYPE CLOCK$ 
this should freeze the machine for 20 seconds, and then start printing garbage
copied from the device driver called CLOCK$ (assuming that you have this device
driver on your system - it appears to be a MSDOS internal driver).
There exist several programs to allow the loading of device drivers from the
command line without rebooting, and I have seen TSRs which act like device 
drivers.
Lots of useful source code can be found in the Public domain.

hope this helps
......Nigel
 

don@trsvax.UUCP (07/13/89)

> How do I find the address of 'aldsdata' inside the TSR??

> I'm guessing something like store the address of aldsdata in an interrupt
> vector, then declare a far pointer and put the address of aldsdata in that...
> But it ain't worked yet.

That's one way to do it, but that has problems.  For one, if some other program 
calls that interrupt, then you would almost assuredly lock up the machine.

Instead, a more general way is to take over some typically unused interrupt 
with an ISR (interrupt service routine).  The ISR would compare values passed
in AX with a table of commands you support.  For now, you could use AX=0
as a request for the address of aldsdata.  Since the ISR is part of your TSR,
it knows the address of aldsdata and can pass it back to the calling program
in some registers, such as ES:BX.  Your ISR can "chain" into the interrupt
vector, so that if some other program also uses that interrupt, their ISR
will also be called.  In order to use this ISR from another program, merely
call the interrupt with AX having 0, and get the address from ES:BX.

If you need more specific info, let me know.  I don't like to send code
fragments unless specifically requested to do so.  You also said you had
written the TSR, so you probably know more about the PC than you give
yourself credit.
---------------------------------------------------------------------
Computers are just the opposite of people.  With computers, you put
the software in the hardware, while with people, you put the hardware
in the software.

Don Subt			The opinions expressed above are
Tandy Corp.			strictly mine, not my employer's.

817-390-3068			...!killer!ninja!sys1!trsvax!don

schaut@madnix.UUCP (Rick Schaut) (07/15/89)

In article <2752@blake.acs.washington.edu> mtsu@blake.UUCP (Montana State) writes:
>I have written a TSR that reads characters off of the comm port, filters them,
>and saves the important information in a buffer allocated inside the TSR.
>
>Suppose the buffer name is 'aldsdata', TSR name is 'x100'...  Now I want to
>write a program to yank the data out of 'aldsdata', from the foreground...
>
>How do I find the address of 'aldsdata' inside the TSR??

Have the TSR place the addres of 'aldsdata' in the 'Intra-application
Communications Area" (ICA).  This is a sixteen byte area located at
address 0040:00F0H.  I suggest that you also include a checksum so that
the foreground program will know if the pointer has been corrupted.
(The source fo this information is _The New Peter Norton Programmer's
Guide to the IBM PC & PS/2_, p. 62)


>You know, this whole problem would be trivial if DOS was Unix...

But then you wouldn't have TC 2.0 to play with.  Real world choices are
never easy.


-- 
   Richard Schaut     Madison, WI              Madison: an alternative
ArpaNet: madnix!schaut@cs.wisc.edu                      to reality.
UseNet: ...uwvax!astroatc!nicmad!madnix!schaut
             {decvax!att}!