[comp.os.cpm] Zcpr & High Level Languages

dgee@cup.portal.com (David O Goodman) (12/24/88)

Does anyone have suggestions for a graceful way in which to pass the
address of a ZCPR 3.x environment descriptor to a program written in a
high level language, so that the program can make use of the various ZCPR
facilities?  Specifically, rather than hard-wiring the environment
descriptor address into the program, thus making it non-portable, what
would be a good way for a utility written in bds-c to learn the
environment descriptor address?


Discussion:
----------

As some of you know, an assembly language program using the zcpr
environment is written with a header which tells the command processor
that it is a 'Z3ENV' program.  At run time, the command processor plugs
the environment descriptor address into a specific location in this
header; now the program contains the address needed to get information on
its environment.

Since the object code of a program compiled under bds-c starts with the
bds runtime package, there seems to be no way to create the required
header, other than (perhaps) relocating the runtime package and finding
some way to link in a header underneath the package.  I have not yet
played with this approach, but it does not seem very fruitful, since 1)
the bds documentation indicates that all code must run directly above the
runtime package, and 2) even if it could be done, relocating the runtime
package would require a full reassembly and/or recompilation of the
libraries, making them completely non-standard.

A second mechanism for communicating the environment descriptor address
from the command processor to a transient program apparently exists.
Inspection of the source code for ZCPR 3.3 (I haven't checked other
versions, yet) reveals that when zcpr 'calls' the transient program,
register pair HL contains the desired address.  However, upon entry into
the runtime package, this register is immediately clobbered.

Any ideas, suggestions, or further discussion would be appreciated.  If I
receive mail on this subject, I will summarize to the net.

Thanks.

--

Dave Goodman
dgee@cup.portal.com
...sun!portal!cup.portal.com!dgee

mwilson@crash.cts.com (Marc Wilson) (12/26/88)

In article <12879@cup.portal.com> dgee@cup.portal.com (David O Goodman) writes:
>Does anyone have suggestions for a graceful way in which to pass the
>address of a ZCPR 3.x environment descriptor to a program written in a
>high level language, so that the program can make use of the various ZCPR
>facilities?

     The *easiest* way is to code a loop that begins at the top of memory
and scans downwards for the string "Z3ENV".  As long as you're between the
BIOS and the top of memory, the only place that that string should appear
is at address ENV+3.  That'll give you the environment address.

     Note that this technique is *extremely* dangerous on any system that
supports memory-mapped I/O ( i.e. Apple CP/M ), for obvious reasons.

     This technique is not new.  Several of the Z-System utilities include
a routine called FENV.  This is the _F_ind _ENV_ironment routine, originally
developed by Joe Wright.  The first program I saw use this technique was a
version of LX.

     Note that this method *should* work under NZ-COM, as long as you use
the address of the pseudo BIOS, rather than the real one.

>--
>
>Dave Goodman
>dgee@cup.portal.com
>...sun!portal!cup.portal.com!dgee


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Marc Wilson
     ARPA: ...!crash!mwilson@nosc.mil
           ...!crash!pnet01!pro-sol!mwilson@nosc.mil
     UUCP: [ cbosgd | hp-sdd!hplabs | sdcsvax | nosc ]!crash!mwilson
     INET: mwilson@crash.CTS.COM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~