home *** CD-ROM | disk | FTP | other *** search
- *
- * Name: libhdr.a
- *
- * Description: Universal Amiga shared library controller
- *
- * Copyright: 1991-1992 by David Jones.
- *
- * Distribution:
- * This source file is released under the terms and conditions of the
- * GNU General Public Library License, which should have been included
- * ith this source distribution. If you do not have a copy of this
- * license, then write to both of the following:
- *
- * The Free Software Foundation David Jones
- * 675 Mass Ave 6730 Tooney Drive
- * Cambridge, MA Orleans, Ontario
- * 02139 K1C 6R4
- * USA Canada
- *
- * Usenet: gnu@prep.ai.mit.edu dej@qpoint.amiga.ocunix.on.ca
- * Fidonet: 1:163/109.8
- *
- *
- * There is NO WARRANTY associated with this software; refer to "gpll.doc"
- * for details.
- *
- * $Log: $
- *
- *
-
- include 'exec/types.i'
- include 'exec/libraries.i'
- include 'exec/resident.i'
- include 'exec/alerts.i'
- include 'exec/semaphores.i'
- include 'dejmac.i'
- include 'exec.offsets'
-
- STRUCTURE myLibBase,0
- STRUCT ml_LibNode,LIB_SIZE
- APTR ml_ID
- BYTE ml_Flags
- BYTE ml_Pad
- LONG ml_A4
- LONG ml_Data
- STRUCT ml_Lock,SS_SIZE
- LABEL MYLIB_SIZEOF
-
- XREF _LibName
- XREF _LibID
- XREF LibVersion
- XREF LibRevision
- XREF _LibVersion
- XREF _LibRevision
- XREF _FuncTable
- XREF _LibInit
- XREF _LibOpen
- XREF _LibClose
- XREF _LibExpunge
-
- XREF _LinkerDB
- XREF _LibBase
- XREF _DOSBase
- XREF _SysBase
-
- XDEF _aLibOpen
- XDEF _aLibClose
- XDEF _aLibExpunge
- XDEF _aLibExtFunc
-
- *
- * You will always get some doofus who will try to execute us. Let's
- * execute him instead.
- *
-
- DoofusKick:
- moveq #-1,D0
- rts
-
- *
- * This is the RomTag structure.
- *
-
- RomTag:
- dc.w RTC_MATCHWORD
- dc.l RomTag
- dc.l EndCode
- dc.b RTF_AUTOINIT
- dc.b LibVersion ; version
- dc.b NT_LIBRARY
- dc.b LibRevision ; pri
- dc.l _LibName
- dc.l _LibID
- dc.l InitTab
-
- ds.w 0 ; force word alignment
-
- InitTab:
- dc.l MYLIB_SIZEOF
- dc.l _FuncTable
- dc.l 0 ; we do our own init
- dc.l _aLibInit
-
- _aLibInit:
- move.l A6,_SysBase
- move.l D0,_LibBase ; set global variables
- move.l D0,A0 ; initialize base
- move.l #_LinkerDB,ml_A4(A0)
- move.b #NT_LIBRARY,LN_TYPE(A0)
- move.l #_LibName,LN_NAME(A0)
- move.b #LIBF_SUMUSED!LIBF_CHANGED,LIB_FLAGS(A0)
- move.w _LibVersion,LIB_VERSION(A0)
- move.w _LibRevision,LIB_REVISION(A0)
- move.l #_LibID,LIB_IDSTRING(A0)
- moveq #0,D0
- move.w D0,ml_Flags(A0)
- lea ml_Lock(A0),A0
- LINKSYS InitSemaphore,_SysBase
- lea DosName(PC),A1 ; open DOS
- moveq #0,D0
- CALL OpenLibrary
- move.l D0,_DOSBase
- bne.s 1$
- ALERT AG_OpenLib!AO_DOSLib
- 1$ jsr _LibInit ; call user init
- rts
-
-
- _aLibOpen:
- lea ml_Lock(A6),A0
- LINKSYS ObtainSemaphore,_SysBase
- addq.w #1,LIB_OPENCNT(A6)
- bclr #LIBB_DELEXP,ml_Flags(A6)
- jsr _LibOpen ; call user init
- move.l D0,-(SP)
- lea ml_Lock(A6),A0
- LINKSYS ReleaseSemaphore,_SysBase
- move.l (SP)+,D0
- rts
-
- _aLibClose:
- lea ml_Lock(A6),A0
- LINKSYS ObtainSemaphore,_SysBase
- jsr _LibClose
- moveq #0,D0
- subq.w #1,LIB_OPENCNT(A6)
- bne.s 1$
- btst #LIBB_DELEXP,ml_Flags(A6)
- beq.s 1$
- bsr _aLibExpunge
- 1$ move.l D0,-(SP)
- lea ml_Lock(A6),A0
- LINKSYS ReleaseSemaphore,_SysBase
- move.l (SP)+,D0
- rts
-
- _aLibExpunge:
- move.l A6,-(SP)
- move.l _LibBase,A1
- lea ml_Lock(A1),A0
- LINKSYS AttemptSemaphore,_SysBase
- tst.l D0
- beq.s 2$ ; seglist is zero, just like D0
- move.l _LibBase,A1
- tst.w LIB_OPENCNT(A1)
- beq.s 1$
- bset #LIBB_DELEXP,ml_Flags(A1)
- moveq #0,D0
- bra.s 2$
- 1$
- jsr _LibExpunge
- tst.l D0
- bne.s 3$
-
- move.l _LibBase,A1
- lea ml_Lock(A1),A0
- CALLSYS ReleaseSemaphore,_SysBase
- moveq #0,D0
- beq.s 2$
- 3$
- move.l _LibBase,A1
- CALLSYS Remove,_SysBase
- move.l _DOSBase,A1
- CALL CloseLibrary
- moveq #0,D0
- move.l _LibBase,A1
- move.l A1,A0
- move.w LIB_NEGSIZE(A0),D0
- sub.l D0,A1
- add.w LIB_POSSIZE(A0),D0
- CALL FreeMem
- move.l #DoofusKick-4,D0
- lsr.l #2,D0
- 2$
- move.l (SP)+,A6
- rts
-
-
- _aLibExtFunc:
- moveq #0,D0
- rts
-
- DosName:
- dc.b 'dos.library',0
- ds.w 0
- EndCode:
-
- END
-