home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / M2V11-2.LHA / modula / dice / dice.lha / examples / shared_lib / README < prev    next >
Encoding:
Text File  |  1991-04-15  |  3.8 KB  |  98 lines

  1.  
  2.             SHARED_LIB EXAMPLE CODE
  3.  
  4.     This is a fully compilable shared library implemented for DICE
  5.     demonstrating how one can write their very own shared library.  Some
  6.     knowledge in shared libraries is required to understand the code..
  7.     the basic thing to remember is (1) that a shared library is NOT a
  8.     normal C program, and (2) the interface calls MUST be reentrant...
  9.     i.e. multiple tasks can make a library call simultaniously.
  10.  
  11.     The only limitation with this example is that I use -mRR which turns on
  12.     registered arguments.  The limitation is that currently DICE will only
  13.     generated registered functions for those routines that take no more
  14.     than 2 integers and 2 pointers.  Routines that take more than that
  15.     limit or take other types (structures, floating pt, etc...) will
  16.     not have a registered entry point.
  17.  
  18.                 SHARED LIBRARY
  19.  
  20.     DEFS.H    contains header stuff
  21.     TAG.A    library independant basic code
  22.     LIB.C    library independant basic code
  23.     INIT.C    library dependant initialization routines
  24.     FUNCS.C    library dependant routines
  25.  
  26.     TAG.A and LIB.C are almost self contained with only a few modifications
  27.     required to use them for other library projects... basically the
  28.     name of the library in TAG.A and the function list in LIB.C
  29.  
  30.     TAG.A contains a subset of the standard startup code, LIB/AMIGA/C.A,
  31.     and assumes non-resident compilation (i.e. you cannot use the -r
  32.     option).  This isn't a problem since the -r option doesn't gain you
  33.     anything as far as shared libraries go.
  34.  
  35.     The individual library interface routines are declared with the LibCall
  36.     macro, defined in DEFS.H, which ensures the small-data pointer is set
  37.     up for all interface calls allowing use of the small-data model.
  38.  
  39.                 LIBRARY INTERFACE
  40.  
  41.     LIB.FD    The .FD file must match library prototypes.  The first two
  42.         integer arguments are stuck in D0 & D1 while the first
  43.         two pointer arguments are stuck in A0 & A1.
  44.  
  45.     AUTO.A    This is extremely DICE specific in that it gives programs
  46.         that link with the interface .lib (link library) the
  47.         capability to auto-open & close test.library without
  48.         having to explicitly do so in main().
  49.  
  50.         Notice that test.c doesn't explicitly OpenLibrary() or
  51.         CloseLibrary() "test.library".  DICE provides such
  52.         capabilities for most standard amiga libraries in the
  53.         same fashion.
  54.  
  55.     ---
  56.  
  57.     To compile, be sure that -2.0 is specified in your DCCOPTS an the
  58.     2.0 registered libraries are unpacked:
  59.  
  60.     DLIB:amigasr20.lib
  61.     DLIB:cr.lib
  62.  
  63.     DINCLUDE:AMIGA20/*/*.h
  64.  
  65.     Create a temporary directory to hold the resulting objects and the
  66.     resulting .lib tag library.  The resulting .library file will be placed
  67.     in LIBS: and the test program will be T:test
  68.  
  69.     DTMP:sharlib/        (to hold the objects & .lib file)
  70.  
  71.     Note that you will get warnings from FDTOLIB, these can be ignored. A
  72.     non-registered and registered version of the interface link library
  73.     required when linking TEST.C is generated, and two versions of TEST.C
  74.     are included to show what is required to compile either a normal
  75.     program or registered-args program that talks to the registered-args
  76.     library.
  77.  
  78.     1> dmake
  79.     ... compiles it all ...
  80.     1> test.script
  81.  
  82.  
  83.                 THE LINK LIB
  84.  
  85.     You will notice that the test program must be linked with test.lib
  86.     from DTMP:sharlib/ .. this is the library interface tag library
  87.     which interfaces C calls to a shared library.  Under DICE, a twist
  88.     is added in the form of a special auto-open module appended to the
  89.     .lib file.
  90.  
  91.     This auto-open module allows the TEST program to make library calls
  92.     without explicitly openning the shared library!  This greatly simplifies
  93.     the complication that using shared libraries generally adds.
  94.  
  95.     If you are interested, you should run 'DOBJ DTMP:SHARLIB/TEST.LIB' to
  96.     see how the link library works.
  97.  
  98.