home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!stanford.edu!rock!concert!samba!usenet
- From: Todd_Lewis@unc.edu (Todd M. Lewis)
- Subject: Re: Does opening libraries require a fixed varname?
- Message-ID: <1992Dec17.143826.15942@samba.oit.unc.edu>
- Sender: usenet@samba.oit.unc.edu
- Nntp-Posting-Host: guitar.oit.unc.edu
- Organization: UNC Office of Information Technology
- References: <BzDnFz.FM5@usenet.ucs.indiana.edu>
- Date: Thu, 17 Dec 1992 14:38:26 GMT
- Lines: 63
-
- In article <BzDnFz.FM5@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu
- (Sam Hulick) writes:
- >
- >If I wanted, for instance, to open intuition.library, does the line
- >*HAVE* to be:
- >
- >IntuitionBase = OpenLibr.......
- >
- >Can it be something like "IBase = OpenLibrary(.." or "blech = Open..."
- >In other words, does it matter what you call the variable?
- >GadToolsBase, ExecBase, GfxBase, etc.
-
- It doesn't have to be anything in particular, unless of course you actually
- want to call one of the routines in the library. There is a little black
- magic going on in the background which, once you understand it, will make
- the variable names make sense.
-
- Let's say you want to call the intuition.library function OpenWindow().
- The autodoc synopsis for OpenWindow() says this:
- SYNOPSIS
- Window = OpenWindow( NewWindow )
- D0 A0
-
- struct Window *OpenWindow( struct NewWindow * );
-
- What this means is that when the function is called, register A0
- should contain the address of a NewWindow structure, and the result
- of the function (a pointer to a Window) will be in D0. What the synopsis
- leaves out is that register A6 is supposed to contain the address of
- the library you are calling (in this case, the result of a previous
- call to OpenLibrary("intuition.library",...);).
-
- That's cool, except that C doesn't normally allow any control over
- specific registers. In fact, it pushes function arguments onto the stack
- and doesn't use register parameters at all. Here's where the black magic
- comes in.
-
- The function you actually call when you say "OpenWindow(&mywin);" is not
- in the intuition.library at all. You actually call a function in one
- of your linker libraries, which was written in assembler, and takes
- the parameters off the stack and puts them in the right registers.
- The it looks for your global variable (in this case IntuitionBase)
- and puts its value in register A6. Then it calls Intuition's
- OpenWindow() function. The important thing with respect to your
- question is that this so-called stub function is looking for
- a library base _by_name_. So the name of your global variable
- has to be right, i.e. it has to match what the stub is looking for.
-
- The other method compilers use nowadays is to have a #pragma for each
- system function that describes what parameters are supposed to go
- into which registers so you can call functions with registerized
- parameters without the stubs from your linker libraries.
- The #pragma for OpenWindow tells your compiler that the
- first parameter should be placed in A0, IntuitionBase's value
- should be placed in A6, and the result should come back
- in register D0. Still, the #pragma is referencing your
- global variable by name, so the name still has to be right.
-
- Hope this clears things up for you.
- --
- _/_/_/ _/ Todd_Lewis@unc.edu You can lead a horse to
- _/ _/ utoddl@guitar.oit.unc.edu Mohammad, but you can't make
- _/ _/_/_/ a mountain drink a mole hill.
-