	section	Expunge,CODE
	IDNT	ALL

**	SpecialLoadLib
**		for pre-loading any library during startup
**
**		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


**	NOTE
**	This is a quick piece of code to get around the problem of loading
**	the digisoftSupport.library.  The normal LoadLib can't do this since
**	it requires digisoftSupport.library to run.  In keeping with the
**	quick nature of this code a number of shortcuts have been taken.
**	Principally among these is the command line parsing.
**	The command line MUST be enclosed in quotes (").
**		NO ERROR CHECKING IS DONE!!!!!!!


**	 30-08-90	** written


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

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


	ifnd	EXEC_TYPES_I
	if1
	PRINTX	Resident maclib not in use.
	endc
	incpath	includes:
	macfile	"exec/types.i"
	macfile	"exec/execbase.i"
	macfile	"exec/alerts.i"
	macfile	"libraries/dos.i"
	macfile	"libraries/dosextens.i"
	macfile	"AllLibraryOffsets.i"
	endc

	ifnd	Lf
CSI	equ	$9b
Lf	equ	$0a
	endc

Release			equ	'1.0 '
VerNo			equ	'0.01'

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


START:		move.l		a0,d6
		move.l		d0,d7

		lea		(dosLibName,pc),a1
		movea.l		(_AbsExecBase).w,a6	;establish exec for calls
		jsr		(_LVOOldOpenLibrary,a6)
		move.l		d0,(DosBase)
		bne.b		1$
		moveq		#RETURN_FAIL,d0
		rts

	; --- now start seperate processing for workbench or CLI

1$		movea.l		(ThisTask,a6),a3
		tst.l		(pr_CLI,a3)
		bne.b		2$			;branch if from CLI
		rts					;??????????????????

	; --- get the output file handle

2$		movea.l		d0,a6			;DOS
		jsr		(_LVOOutput,a6)
		move.l		d0,d1			;output handle
		move.l		#Title,d2
		move.l		#TitleSize,d3
		jsr		(_LVOWrite,a6)

	; --- this command line parsing assumes strict complience with guidelines

		movea.l		d6,a0
..		cmpi.b		#'"',(a0)+
		bne.b		..
		movea.l		a0,a1			;command line start
..		cmpi.b		#'"',(a0)+
		bne.b		..
		clr.b		-(a0)			;null term

		movea.l		(_AbsExecBase).w,a6
		jsr		(_LVOOldOpenLibrary,a6)	;exec
		tst.l		d0
		bne.b		LibOpen

		lea		(intuitionLibName,pc),a1
		jsr		(_LVOOldOpenLibrary,a6)
		tst.l		d0
		bne.b		.intuitionAvailable
		move.l		#AT_Recovery!AG_OpenLib!AO_Intuition,d7
		jsr		(_LVOAlert,a6)
3$		movea.l		(DosBase,pc),a1
		jsr		(_LVOCloseLibrary,a6)
		moveq		#RETURN_FAIL,d0
		rts

.intuitionAvailable:
		movea.l		d0,a6			;intuition base
		lea.l		(LibLost_AlertMsg,pc),a0
		moveq		#0,d0
		moveq		#50,d1
		jsr		(_LVODisplayAlert,a6)
		movea.l		(_AbsExecBase).w,a6
		bra.b		3$

LibOpen:	movea.l		d0,a1
		jsr		(_LVOCloseLibrary,a6)
		movea.l		(DosBase,pc),a6
		jsr		(_LVOOutput,a6)
		move.l		d0,d1			;output handle
		move.l		#AllOk,d2
		moveq		#AllOkSize,d3
		jsr		(_LVOWrite,a6)
		movea.l		a6,a1
		movea.l		(_AbsExecBase).w,a6
		jsr		(_LVOCloseLibrary,a6)
		moveq		#RETURN_OK,d0
		rts


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


dosLibName:
	cstr	'dos.library'
intuitionLibName:
	cstr	'intuition.library'


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


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


AllOk:	cstr	'Library successfully opened.',Lf
AllOkSize	equ	*-AllOk

LibLost_AlertMsg:
	dw	169
	db	15
	db		'Requested library ------- MISSING',0
	db	-1
	dw	43
	db	35
	db		'LEFT = OK',0
	db	-1
	dw	489
	db	35
	db		'RIGHT = RETRY',0,0
	odderror


	even
***************************************

DosBase:
	dx.l	1

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

	END
