	section	Expunge,CODE
	IDNT	ALL

**	Expunge
**		for getting rid of libraries from memory
**
**		Copyright ©1990 DigiSoft
**
**	Permission is granted to purchasers of Macro68 to modify this source
**	file.  Permission is further granted to distribute the source code that
**	they have modified subject to the following conditions:
**	1.  That the original, unaltered, source is included with the
**	    distribution.
**	2.  That no charge is made for the distribution, other than the cost of
**	    media.                    (Distribution via Fred Fish is permitted)
**	3.  That my copyright notice remains as part of this and any other
**	    file adapted from this file.
**                                               Paul Coward
**                                                         DigiSoft
**
**	Tabstops : 8
**	Assemble with Macro68


**	18-06-90	** written


		OBJFILE		"ram:Expunge"
	;	ERRORFILE	"ram:Expunge.bugs"

	;	PALL
	;	HALL
		EXEOBJ
	;	LIST
	;	LISTSYMS
	;	ADDSYM
	;	LISTFILE	"ram:Expunge.lst"
	;	CREFFILE	"ram:Expunge.cref"
	;	DEBUG
	;	REALTIME
		STRICT

	VERBOSEFILE	"CON:0/0/600/50/M68"

	ifnd	EXEC_TYPES_I
	if1
	PRINTX	Resident maclib not in use.
	endc
_AbsExecBase		equ	4
_LVOAlert		equ	-108	;exec
_LVOCloseLibrary	equ	-414	;exec
_LVOForbid		equ	-132	;exec
_LVOOpenLibrary		equ	-552	;exec
_LVOPermit		equ	-138	;exec
AT_Recovery		equ	$00000000
AG_OpenLib		equ	$00030000
	endc


_LVOdsAllocCPremember	equ	-30
_LVOdsAllocScratch	equ	-42
_LVOdsClearRemember	equ	-66
_LVOdsFreeScratch	equ	-174
_LVOdsParse		equ	-216
_LVOdsPuts		equ	-648


	ifnd	csd_DSSBase
csd_DSSBase		equ	16
AO_DSSLib		equ	$00008099	;alert number id support library can't be opened
Tab			equ	$09
Lf			equ	$0a
CSI			equ	$9b
	endc


csd_RememberKey		equ	84	
csd_Args		equ	88		;8 bytes required
csd_SIZEOF		equ	96


Release			equ	'1.0 '
VerNo			equ	'0.02'

*************************
*	COLD ENTRY	*
*************************


START:		moveq		#0,d3
		move.l		a0,d6
		move.l		d0,d7
		movea.l		(_AbsExecBase).w,a6	;establish exec for calls

	; --- open the support library

		moveq		#2,d0			;version #
		lea	 	(supportLibName,pc),a1	;point to liberary name
		jsr		(_LVOOpenLibrary,a6)	;exec
		tst.l		d0
		bne.b		1$
		move.l		#AT_Recovery!AG_OpenLib!AO_DSSLib,d7
		jsr		(_LVOAlert,a6)
		bra		Exit_To_DOS

	; --- initialize the scratch area

1$		movea.l		d0,a6
		moveq		#csd_SIZEOF,d0
		moveq		#33,d1
		moveq		#0,d2
		jsr		(_LVOdsAllocScratch,a6)
		bne		Exit_To_DOS

	; --- initialize the argument pointers

		movem.l		d6-d7,(csd_Args,a5)	;& a_Length(A0)

	; --- display banner

		lea		(Title,pc),a1
		jsr		(_LVOdsPuts,a6)

	; --- parse args

		lea		(csd_RememberKey,a5),a0
		move.l		#256,d0
		jsr		(_LVOdsAllocCPremember,a6)
		move.l		d0,(ArgPointers)
		beq		InsufficientMemory

		lea		(csd_Args,a5),a0
		lea		(additionalHelp,pc),a1
		lea		(ArgPointers+4,pc),a2
		lea		(CmdTemplate,pc),a3
		jsr		(_LVOdsParse,a6)
		bpl.b		configure
		movea.l		(ArgPointers,pc),a1
		jsr		(_LVOdsPuts,a6)
		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsClearRemember,a6)
		bra		exitWithError

	; --- any args ?

configure:	move.l		(libraryName,pc),d1
		beq.b		expungeDefault
		movea.l		(4).w,a6
		movea.l		d1,a1
		moveq		#0,d0
		jsr		(_LVOOpenLibrary,a6)
		move.l		d0,d7
		beq.b		libNotFound
		bra.b		expungeIt

expungeDefault:	jsr		(-18,a6)		;EXPUNGE (digisoftSupport.library)
		movea.l		(4).w,a6
		lea		(macro68LibName,pc),a1
		moveq		#0,d0
		jsr		(_LVOOpenLibrary,a6)
		move.l		d0,d7
		beq.b		libNotFound

	; --- expunge the library

expungeIt:	movea.l		d7,a6
		jsr		(-18,a6)		;EXPUNGE (macro68.library)
		movea.l		(4).w,a6
		movea.l		d7,a1
		jsr		(_LVOCloseLibrary,a6)
		movea.l		(csd_DSSBase,a5),a6

	; --- and write it back out

EXIT:		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsClearRemember,a6)
Exit_To_DOS:	jsr		(_LVOdsFreeScratch,a6)
		movea.l		a6,a1
		movea.l		(4).w,a6
		jsr		(_LVOCloseLibrary,a6)
		moveq		#0,d0
		rts					;exit to DOS


	; --- error detected during start - exit gracefully


libNotFound:	lea		(LibNotFound_Msg,pc),a1
		movea.l		(csd_DSSBase,a5),a6
		jsr		(_LVOdsPuts,a6)
		bra		EXIT

exitWithError:	lea		(InitError_Msg,pc),a1
		jsr		(_LVOdsPuts,a6)
		bra		EXIT


InsufficientMemory:
		lea		(InsufficientMemory_Msg,pc),a1
		jsr		(_LVOdsPuts,a6)
		bra		EXIT


***************************************
***************************************
***************************************


ArgPointers:	dl	0
libraryName:	dl	0		;pointer to library


CmdTemplate:
	db	'LIBRARY/K',0


additionalHelp:
	db	'USAGE:',Lf
	db	'Expunge [library]',Lf,Lf,0


***************************************
***************************************
***************************************


supportLibName:
	db	'digisoftSupport.library',0
macro68LibName:
	db	'macro68.library',0
	align	0,2


	oddok
Title:	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'Expunge  '
	db	'Release '
	dl	Release
	db	' Vers '
	dl	VerNo
	db	' CopyRight ©1990 DIGISOFT',Lf
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	db	'  12 Dinmore St.  Moorooka 4105  Brisbane, QLD  Australia',Lf
	db	'       Phone  ISD (617) 277-3255  STD (07) 277-3255'
	db	0
	odderror


InitError_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'INITIALIZATION ERROR !!!',Lf
	db	Tab,Tab,'Bad command line OR Insufficient memory!'
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	db	Lf


LibNotFound_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'Library not found !!!',Lf
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	db	Lf


InsufficientMemory_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'IO ERROR !!!',Lf
	db	Tab,Tab,'Insufficient memory!'
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	db	Lf


*******************************************************************************

	END
