home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / AmigaSystem / AmiStart / ModulesSDK.lha / source / LibInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-23  |  5.6 KB  |  168 lines

  1. /*
  2. **      $VER: LibInit.c 37.32 (2.3.99)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **        modified by Darius Brewka orginal by
  7. **          (C) Copyright 1996-99 Andreas R. Kleinert
  8. **          All Rights Reserved.
  9. */
  10.  
  11. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <exec/libraries.h>
  16. #include <exec/execbase.h>
  17. #include <exec/resident.h>
  18. #include <exec/initializers.h>
  19.  
  20. #ifdef __MAXON__
  21. #include <clib/exec_protos.h>
  22. #else
  23. #include <proto/exec.h>
  24. #endif
  25. #include "compiler.h"
  26.  
  27. #include "amistart_modulebase.h"
  28.  
  29. ULONG __saveds __stdargs L_OpenLibs(struct AmiStartModuleBase *AmiStartModuleBase);
  30. void  __saveds __stdargs L_CloseLibs(void);
  31.  
  32. struct ExecBase      *SysBase       = NULL;
  33. struct IntuitionBase *IntuitionBase = NULL;
  34. struct GfxBase       *GfxBase       = NULL;
  35. struct DosBase         *DOSBase        = NULL;
  36.  
  37. #define VERSION  39
  38. #define REVISION 0
  39.  
  40. #define EXLIBNAME "showwindows"
  41. #define EXLIBVER  " 39.0 (15.03.02)"
  42.  
  43. char __aligned ExLibName [] = EXLIBNAME ".module";
  44. char __aligned ExLibID   [] = EXLIBNAME EXLIBVER;
  45. char __aligned Copyright [] = "(c) by Darius Brewka";
  46.  
  47. char __aligned VERSTRING [] = "\0$VER: " EXLIBNAME EXLIBVER;
  48.  
  49. /* ----------------------------------------------------------------------------------------
  50.    ! ROMTag and Library inilitalization structure:
  51.    !
  52.    ! Below you find the ROMTag, which is the most important "magic" part of a library
  53.    ! (as for any other resident module). You should not need to modify any of the
  54.    ! structures directly, since all the data is referenced from constants from somewhere else.
  55.    !
  56.    ! You may place the ROMTag directly after the LibStart (-> StartUp.c) function as well.
  57.    !
  58.    ! Note, that the data initialization structure may be somewhat redundant - it's
  59.    ! for demonstration purposes.
  60.    !
  61.    ! EndResident can be placed somewhere else - but it must follow the ROMTag and
  62.    ! it must not be placed in a different SECTION.
  63.    ---------------------------------------------------------------------------------------- */
  64.  
  65. extern ULONG InitTab[];
  66. extern APTR EndResident; /* below */
  67.  
  68. struct Resident __aligned ROMTag =     /* do not change */
  69. {
  70.  RTC_MATCHWORD,
  71.  &ROMTag,
  72.  &EndResident,
  73.  RTF_AUTOINIT,
  74.  VERSION,
  75.  NT_LIBRARY,
  76.  0,
  77.  &ExLibName[0],
  78.  &ExLibID[0],
  79.  &InitTab[0]
  80. };
  81.  
  82. APTR EndResident;
  83.  
  84. struct MyDataInit                      /* do not change */
  85. {
  86.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  87.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  88.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  89.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  90.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  91.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  92.  ULONG ENDMARK;
  93. } DataTab =
  94. #ifdef __VBCC__
  95. {
  96.         0xe000,8,NT_LIBRARY,
  97.         0x0080,10,(ULONG) &ExLibName[0],
  98.         0xe000,LIBF_SUMUSED|LIBF_CHANGED,
  99.         0xd000,20,VERSION,
  100.         0xd000,22,REVISION,
  101.         0x80,24,(ULONG) &ExLibID[0],
  102.         (ULONG) 0
  103. };
  104. #else
  105. {
  106.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  107.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  108.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  109.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  110.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  111.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  112.  (ULONG) 0
  113. };
  114. #endif
  115.  
  116.  
  117. /* ----------------------------------------------------------------------------------------
  118.    ! L_OpenLibs:
  119.    !
  120.    ! Since this one is called by InitLib, libraries not shareable between Processes or
  121.    ! libraries messing with RamLib (deadlock and crash) may not be opened here.
  122.    !
  123.    ! You may bypass this by calling this function fromout LibOpen, but then you will
  124.    ! have to a) protect it by a semaphore and b) make sure, that libraries are only
  125.    ! opened once (when using global library bases).
  126.    ---------------------------------------------------------------------------------------- */
  127.  
  128. ULONG __saveds __stdargs L_OpenLibs(struct AmiStartModuleBase *AmiStartModuleBase)
  129. {
  130.  SysBase = (*((struct ExecBase **) 4));
  131.  
  132.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  133.  if(!IntuitionBase) return(FALSE);
  134.  
  135.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  136.  if(!GfxBase) return(FALSE);
  137.  
  138.  DOSBase = (struct DosBase *) OpenLibrary("dos.library", 37);
  139.  if(!DOSBase) return(FALSE);
  140.  
  141.  
  142.  AmiStartModuleBase->exb_IntuitionBase = IntuitionBase;
  143.  
  144.  AmiStartModuleBase->exb_GfxBase       = GfxBase;
  145.  AmiStartModuleBase->exb_SysBase       = SysBase;
  146.  AmiStartModuleBase->exb_DosBase       = DOSBase;
  147.  
  148.  return(TRUE);
  149. }
  150.  
  151. /* ----------------------------------------------------------------------------------------
  152.    ! L_CloseLibs:
  153.    !
  154.    ! This one by default is called by ExpungeLib, which only can take place once
  155.    ! and thus per definition is single-threaded.
  156.    !
  157.    ! When calling this fromout LibClose instead, you will have to protect it by a
  158.    ! semaphore, since you don't know whether a given CloseLibrary(foobase) may cause a Wait().
  159.    ! Additionally, there should be protection, that a library won't be closed twice.
  160.    ---------------------------------------------------------------------------------------- */
  161.  
  162. void __saveds __stdargs L_CloseLibs(void)
  163. {
  164.  if(GfxBase)       CloseLibrary((struct Library *) GfxBase);
  165.  if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  166.  if(DOSBase) CloseLibrary((struct Library *) DOSBase);
  167. }
  168.