home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / saslib.lzh / libhdr.a < prev    next >
Encoding:
Text File  |  1992-02-03  |  4.0 KB  |  209 lines

  1. *
  2. *    Name:                libhdr.a
  3. *
  4. *    Description:    Universal Amiga shared library controller
  5. *
  6. *    Copyright:        1991-1992 by David Jones.
  7. *
  8. *    Distribution:
  9. *    This source file is released under the terms and conditions of the
  10. *    GNU General Public Library License, which should have been included
  11. *    ith this source distribution.  If you do not have a copy of this
  12. *    license, then write to both of the following:
  13. *
  14. *                The Free Software Foundation        David Jones
  15. *                675 Mass Ave                            6730 Tooney Drive
  16. *                Cambridge, MA                            Orleans, Ontario
  17. *                02139                                        K1C 6R4
  18. *                USA                                        Canada
  19. *
  20. *    Usenet:    gnu@prep.ai.mit.edu                    dej@qpoint.amiga.ocunix.on.ca
  21. *    Fidonet:                                                1:163/109.8
  22. *
  23. *
  24. *    There is NO WARRANTY associated with this software; refer to "gpll.doc"
  25. *    for details.
  26. *
  27. *        $Log: $
  28. *
  29. *
  30.  
  31.         include 'exec/types.i'
  32.         include 'exec/libraries.i'
  33.         include 'exec/resident.i'
  34.         include 'exec/alerts.i'
  35.         include 'exec/semaphores.i'
  36.         include 'dejmac.i'
  37.         include 'exec.offsets'
  38.         
  39.         STRUCTURE    myLibBase,0
  40.           STRUCT    ml_LibNode,LIB_SIZE
  41.           APTR        ml_ID
  42.           BYTE        ml_Flags
  43.           BYTE        ml_Pad
  44.           LONG        ml_A4
  45.           LONG        ml_Data
  46.           STRUCT        ml_Lock,SS_SIZE
  47.         LABEL        MYLIB_SIZEOF
  48.  
  49.         XREF    _LibName
  50.         XREF    _LibID
  51.         XREF    LibVersion
  52.         XREF    LibRevision
  53.         XREF    _LibVersion
  54.         XREF    _LibRevision
  55.         XREF    _FuncTable
  56.         XREF    _LibInit
  57.         XREF    _LibOpen
  58.         XREF    _LibClose
  59.         XREF    _LibExpunge
  60.         
  61.         XREF    _LinkerDB
  62.         XREF    _LibBase
  63.         XREF    _DOSBase
  64.         XREF    _SysBase
  65.         
  66.         XDEF    _aLibOpen
  67.         XDEF    _aLibClose
  68.         XDEF    _aLibExpunge
  69.         XDEF    _aLibExtFunc
  70.  
  71. *
  72. *    You will always get some doofus who will try to execute us.  Let's
  73. *    execute him instead.
  74. *
  75.  
  76. DoofusKick:
  77.         moveq        #-1,D0
  78.         rts
  79.  
  80. *
  81. *  This is the RomTag structure.
  82. *
  83.  
  84. RomTag:
  85.         dc.w    RTC_MATCHWORD
  86.         dc.l    RomTag
  87.         dc.l    EndCode
  88.         dc.b    RTF_AUTOINIT
  89.         dc.b    LibVersion    ; version
  90.         dc.b    NT_LIBRARY
  91.         dc.b    LibRevision    ; pri
  92.         dc.l    _LibName
  93.         dc.l    _LibID
  94.         dc.l    InitTab
  95.  
  96.         ds.w    0        ; force word alignment
  97.         
  98. InitTab:
  99.         dc.l    MYLIB_SIZEOF
  100.         dc.l    _FuncTable
  101.         dc.l    0        ; we do our own init
  102.         dc.l    _aLibInit
  103.  
  104. _aLibInit:
  105.         move.l    A6,_SysBase
  106.         move.l    D0,_LibBase    ; set global variables
  107.         move.l    D0,A0        ; initialize base
  108.         move.l    #_LinkerDB,ml_A4(A0)
  109.         move.b    #NT_LIBRARY,LN_TYPE(A0)
  110.         move.l    #_LibName,LN_NAME(A0)
  111.         move.b    #LIBF_SUMUSED!LIBF_CHANGED,LIB_FLAGS(A0)
  112.         move.w    _LibVersion,LIB_VERSION(A0)
  113.         move.w    _LibRevision,LIB_REVISION(A0)
  114.         move.l    #_LibID,LIB_IDSTRING(A0)
  115.         moveq        #0,D0
  116.         move.w    D0,ml_Flags(A0)
  117.         lea        ml_Lock(A0),A0
  118.         LINKSYS    InitSemaphore,_SysBase
  119.         lea        DosName(PC),A1    ; open DOS
  120.         moveq        #0,D0
  121.         CALL        OpenLibrary
  122.         move.l    D0,_DOSBase
  123.         bne.s        1$
  124.         ALERT        AG_OpenLib!AO_DOSLib
  125. 1$        jsr        _LibInit    ; call user init
  126.         rts
  127.  
  128.  
  129. _aLibOpen:
  130.         lea        ml_Lock(A6),A0
  131.         LINKSYS    ObtainSemaphore,_SysBase
  132.         addq.w    #1,LIB_OPENCNT(A6)
  133.         bclr        #LIBB_DELEXP,ml_Flags(A6)
  134.         jsr        _LibOpen    ; call user init
  135.         move.l    D0,-(SP)
  136.         lea        ml_Lock(A6),A0
  137.         LINKSYS    ReleaseSemaphore,_SysBase
  138.         move.l    (SP)+,D0
  139.         rts
  140.  
  141. _aLibClose:
  142.         lea        ml_Lock(A6),A0
  143.         LINKSYS    ObtainSemaphore,_SysBase
  144.         jsr        _LibClose
  145.         moveq        #0,D0
  146.         subq.w    #1,LIB_OPENCNT(A6)
  147.         bne.s        1$
  148.         btst        #LIBB_DELEXP,ml_Flags(A6)
  149.         beq.s        1$
  150.         bsr        _aLibExpunge
  151. 1$        move.l    D0,-(SP)
  152.         lea        ml_Lock(A6),A0
  153.         LINKSYS    ReleaseSemaphore,_SysBase
  154.         move.l    (SP)+,D0
  155.         rts
  156.  
  157. _aLibExpunge:
  158.         move.l    A6,-(SP)
  159.         move.l    _LibBase,A1
  160.         lea        ml_Lock(A1),A0
  161.         LINKSYS    AttemptSemaphore,_SysBase
  162.         tst.l        D0
  163.         beq.s        2$        ; seglist is zero, just like D0
  164.         move.l    _LibBase,A1
  165.         tst.w        LIB_OPENCNT(A1)
  166.         beq.s        1$
  167.         bset        #LIBB_DELEXP,ml_Flags(A1)
  168.         moveq        #0,D0
  169.         bra.s        2$
  170. 1$
  171.         jsr        _LibExpunge
  172.         tst.l        D0
  173.         bne.s        3$
  174.         
  175.         move.l    _LibBase,A1
  176.         lea        ml_Lock(A1),A0
  177.         CALLSYS    ReleaseSemaphore,_SysBase
  178.         moveq        #0,D0
  179.         beq.s        2$
  180. 3$
  181.         move.l    _LibBase,A1
  182.         CALLSYS    Remove,_SysBase
  183.         move.l    _DOSBase,A1
  184.         CALL        CloseLibrary
  185.         moveq        #0,D0
  186.         move.l    _LibBase,A1
  187.         move.l    A1,A0
  188.         move.w    LIB_NEGSIZE(A0),D0
  189.         sub.l        D0,A1
  190.         add.w        LIB_POSSIZE(A0),D0
  191.         CALL        FreeMem
  192.         move.l    #DoofusKick-4,D0
  193.         lsr.l        #2,D0
  194. 2$
  195.         move.l    (SP)+,A6
  196.         rts
  197.  
  198.  
  199. _aLibExtFunc:
  200.         moveq        #0,D0
  201.         rts
  202.  
  203. DosName:
  204.         dc.b    'dos.library',0
  205.         ds.w    0
  206. EndCode:
  207.  
  208.         END
  209.