	SECTION NTRYHUNK,CODE

 NOLIST
 INCLUDE "exec/types.i"
 INCLUDE "exec/execbase.i"
 INCLUDE "exec/libraries.i"
 INCLUDE "exec/initializers.i"
 INCLUDE "exec/resident.i"
 LIST

; if this next equate is set to non-zero then we geneate a second version of
; ODU that has a different name which is useful for debugging a new version
; while keeping the old version around for use by programs normally running
; on the system.  the debug library's name will be OwnDevUnitDebug.library.
; it is recommended that one not modify the setting within this source
; file, but rather specify a BUILD_DEBUG define on the command line of
; whatever assembler one uses.

	IFND	BUILD_DEBUG
BUILD_DEBUG:	EQU	0
	ENDIF

 INCLUDE "version.i"

	XREF	_LinkerDB
	XREF	__BSSBAS
	XREF	__BSSLEN

	XREF	_LibInit
	XREF	_LibOpen
	XREF	_LibClose
	XREF	_LibExpunge

; XREFs to the functions in the library I provide

	XREF	_AllocPagerHandle
	XREF	_FreePagerHandle

	XREF	_ULogA
	XREF	_SetLogLevel
	XREF	_SetLogService
	XREF	_SetLogWho

	XREF	_LockFile
	XREF	_UnLockFile
	XREF	_UnLockFiles

	XREF	_FindPagerConfig
	XREF	_FindPagerConfigDefault
	XREF	_FreePagerConfig
	XREF	_PagerConfigYesNo

	XREF	_FindPagerService
	XREF	_FreePagerService

	XREF	_FindPagerAlias
	XREF	_FreePagerAlias

	XREF	_GetSequenceNumber
	XREF	_SequenceToName

	XREF	_NameInSpool
	XREF	_FreeNameInSpool

; here we define the library base
; do not change this without changing GSTMaker.h along with it!

	STRUCTURE Base,LIB_SIZE
	ULONG	pgr_SegList
	LABEL	Base_SIZEOF

; macro for calling routines in other libraries
CALL	MACRO
	XREF	_LVO\1
	jsr	_LVO\1(a6)
	ENDM

; the first executable location sets an error and returns in case someone
; tries to load the library as a load moudle instead of OpenLibrary()ing it
	moveq	#-1,d0
	rts

; the romtag structure for this library
initDDescrip:
		;STRUCTURE RT,0
	dc.w RTC_MATCHWORD	; UWORD RT_MATCHWORD
	dc.l initDDescrip	; APTR  RT_MATCHTAG
	dc.l EndCode		; APTR  RT_ENDSKIP
	dc.b RTF_AUTOINIT	; UBYTE RT_FLAGS
	dc.b VERSION		; UBYTE RT_VERSION
	dc.b NT_LIBRARY		; UBYTE RT_TYPE
	dc.b 0			; BYTE  RT_PRI
	dc.l PagerName		; APTR  RT_NAME
	dc.l idString		; APTR  RT_IDSTRING
	dc.l Init		; APTR  RT_INIT

; the name of the library
PagerName:
	dc.b	'pager-support'
	IFNE	BUILD_DEBUG
	dc.b	'-debug'
	ENDIF
	dc.b	'.library',0

; text identifier tag for the library
	ds.w 0	; word align info string for programs like XOper...
idString: dc.b 'pager-support.library v'
	  IDSTR
	  dc.b 13,10,'Copyright ',$a9,' 1993 by Christopher A. Wichura',13,10
	  dc.b 'All Rights Reserved.',13,10,0

; word align everything
	ds.w 0

; this is the init structure that our RTF_AUTOINIT told exec to look for
Init:
	dc.l Base_SIZEOF	; size of library base data space
	dc.l funcTable		; pointer to the function initializers
	dc.l dataTable		; pointer to the data initializers
	dc.l initRoutine	; routine to run

; here we have the function table.  it, of course, starts with the standard
; library routines like Open, etc.
funcTable:
	dc.l _LibOpen
	dc.l _LibClose
	dc.l _LibExpunge
	dc.l Null		; reserved routine

; my library routines
	; the hooks into the linker library pools routines are provided
	; at the end of this file
	dc.l LibCreatePool
	dc.l LibDeletePool
	dc.l LibAllocPooled
	dc.l LibFreePooled

	dc.l _AllocPagerHandle
	dc.l _FreePagerHandle

	dc.l _ULogA
	dc.l _SetLogLevel
	dc.l _SetLogService
	dc.l _SetLogWho

	dc.l _LockFile
	dc.l _UnLockFile
	dc.l _UnLockFiles

	dc.l _FindPagerConfig
	dc.l _FindPagerConfigDefault
	dc.l _FreePagerConfig
	dc.l _PagerConfigYesNo

	dc.l _FindPagerService
	dc.l _FreePagerService

	dc.l _FindPagerAlias
	dc.l _FreePagerAlias

	dc.l _GetSequenceNumber
	dc.l _SequenceToName

	dc.l _NameInSpool
	dc.l _FreeNameInSpool

; end of library function list
	dc.l -1

; static data structures initilization table
dataTable:
	INITBYTE LN_TYPE,NT_LIBRARY
	INITLONG LN_NAME,PagerName
	INITBYTE LIB_FLAGS,LIBF_SUMUSED+LIBF_CHANGED
	INITWORD LIB_VERSION,VERSION
	INITWORD LIB_REVISION,REVISION
	INITLONG LIB_IDSTRING,idString
	dc.l 0

; after the library has been allocated this next routine gets called.
; d0 = library's pointer, a0 = segment list
;
; returning non-zero means ok to link library into system list
initRoutine:
	movem.l	a3/a5,-(sp)

	movem.l	d0/a0,-(sp)		; save pointers

; clear the BSS data area
	lea	__BSSBAS,a3
	moveq	#0,d1
	move.l	#__BSSLEN,d0
	bra.s	2$
1$	move.l	d1,(a3)+
2$	dbf	d0,1$

; now call the init routine in the C code to handle any other stuff
	movem.l	(sp)+,d0/a0
	jsr	_LibInit

4$:	movem.l	(sp)+,a3/a5
	rts

Null:				; Commodore reserved routine.  always
	moveq	#0,d0		; return NULL for now!
	rts

POOLHK	MACRO
Lib\1:
	move.l	a6,-(sp)
	move.l	4.w,a6
	XREF	_Asm\1
	jsr	_Asm\1
	move.l	(sp)+,a6
	rts
	ENDM

	POOLHK	CreatePool
	POOLHK	DeletePool
	POOLHK	AllocPooled
	POOLHK	FreePooled

EndCode:	; maker for end of this code

	END
