home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17471 < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.4 KB  |  76 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!stanford.edu!rock!concert!samba!usenet
  3. From: Todd_Lewis@unc.edu (Todd M. Lewis)
  4. Subject: Re: Does opening libraries require a fixed varname?
  5. Message-ID: <1992Dec17.143826.15942@samba.oit.unc.edu>
  6. Sender: usenet@samba.oit.unc.edu
  7. Nntp-Posting-Host: guitar.oit.unc.edu
  8. Organization: UNC Office of Information Technology
  9. References: <BzDnFz.FM5@usenet.ucs.indiana.edu>
  10. Date: Thu, 17 Dec 1992 14:38:26 GMT
  11. Lines: 63
  12.  
  13. In article <BzDnFz.FM5@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu  
  14. (Sam Hulick) writes:
  15. >
  16. >If I wanted, for instance, to open intuition.library, does the line
  17. >*HAVE* to be:
  18. >
  19. >IntuitionBase = OpenLibr.......
  20. >
  21. >Can it be something like "IBase = OpenLibrary(.." or "blech = Open..."
  22. >In other words, does it matter what you call the variable?
  23. >GadToolsBase, ExecBase, GfxBase, etc.
  24.  
  25. It doesn't have to be anything in particular, unless of course you actually
  26. want to call one of the routines in the library.  There is a little black
  27. magic going on in the background which, once you understand it, will make
  28. the variable names make sense.
  29.  
  30. Let's say you want to call the intuition.library function OpenWindow().
  31. The autodoc synopsis for OpenWindow() says this:
  32.     SYNOPSIS
  33.        Window = OpenWindow( NewWindow )
  34.     D0                   A0
  35.  
  36.     struct Window *OpenWindow( struct NewWindow * );
  37.  
  38. What this means is that when the function is called, register A0
  39. should contain the address of a NewWindow structure, and the result
  40. of the function (a pointer to a Window) will be in D0. What the synopsis
  41. leaves out is that register A6 is supposed to contain the address of
  42. the library you are calling (in this case, the result of a previous
  43. call to OpenLibrary("intuition.library",...);). 
  44.  
  45. That's cool, except that C doesn't normally allow any control over
  46. specific registers.  In fact, it pushes function arguments onto the stack
  47. and doesn't use register parameters at all.  Here's where the black magic
  48. comes in.
  49.  
  50. The function you actually call when you say "OpenWindow(&mywin);" is not
  51. in the intuition.library at all.  You actually call a function in one
  52. of your linker libraries, which was written in assembler, and takes
  53. the parameters off the stack and puts them in the right registers.
  54. The it looks for your global variable (in this case IntuitionBase)
  55. and puts its value in register A6.  Then it calls Intuition's
  56. OpenWindow() function.  The important thing with respect to your
  57. question is that this so-called stub function is looking for
  58. a library base _by_name_.  So the name of your global variable
  59. has to be right, i.e. it has to match what the stub is looking for.
  60.  
  61. The other method compilers use nowadays is to have a #pragma for each
  62. system function that describes what parameters are supposed to go
  63. into which registers so you can call functions with registerized
  64. parameters without the stubs from your linker libraries.
  65. The #pragma for OpenWindow tells your compiler that the
  66. first parameter should be placed in A0, IntuitionBase's value
  67. should be placed in A6, and the result should come back
  68. in register D0.  Still, the #pragma is referencing your
  69. global variable by name, so the name still has to be right.
  70.  
  71. Hope this clears things up for you.
  72. --
  73.  _/_/_/  _/     Todd_Lewis@unc.edu          You can lead a horse to 
  74.   _/    _/     utoddl@guitar.oit.unc.edu   Mohammad, but you can't make
  75.  _/    _/_/_/                             a mountain drink a mole hill.
  76.