;---------------------------------------------------------------------------;
; Obviously, the error routine should not rely upon any libs being open!!   ;
; Temp001(a5) will be used as a base for intuition.library                  ;
; Temp002(a5) will be used as the adr of the allocated mem for Req text.    ;
; - This routine will attempt to bring up a requester showing a list of     ;
;   which libraries couldn't be openned (including the required versions).  ;
; - An EasyRequest is be used, but v1.3 lamers don't have them, so if we    ;
;   can't open v37, a DisplayAlert will tell them they need to upgrade.     ;
;---------------------------------------------------------------------------;
OpnLib_Error_Title
	PROGNAM
	Dc.b	":",0
OpnLib_Error_Body_Header
	Dc.b	"Could not open the following libraries:",10
	Dc.b	"(Minimum version numbers shown.)",10,10,0
OpnLib_Error_Body_Header_Length Equ (*-OpnLib_Error_Body_Header)-1
OpnLib_Error_Body_Main_Length Equ 40
; 30 chars = maximum file length, + " vXX",10,0 + a bit more.
OpnLib_Error_Body_Length Equ OpnLib_Error_Body_Header_Length+(NumLibs*OpnLib_Error_Body_Main_Length)
OpnLib_Error_Gads
	Dc.b	"OK",0
	Even
;---------------------------------------------------------------------------;
OpnLib_Error
	Lea	N_IntName(pc),a1
	Moveq	#37,d0
	N_CallExec	OpenLibrary
	Move.l	d0,Temp001(a5)		Store base adr.
	Beq	OpnLib_Error_Error	If we can't get it, DisplayAlert 'em.

	Bsr.s	BuildLibList		Adr into Temp002(a5)

	Move.l	#N_EasyStruct_Len,N_ES_Length(a5)	Size of structure.
	Move.l	#0,N_ES_Flags(a5)		No flags.
	Lea	OpnLib_Error_Title(pc),a0	-.
	Move.l	a0,N_ES_Title(a5)		 |
	Move.l	Temp002(a5),N_ES_Body(a5)	 |- Texts for req.
	Lea	OpnLib_Error_Gads(pc),a0	 |
	Move.l	a0,N_ES_Gadgets(a5)		-'

	Lea	N_EasyStruct(a5),a1	Point to EasyRequest structure.
	Sub.l	a0,a0			Specify default public screen.
	Move.l	a0,a2			No IDCMP flags.
	Move.l	a0,a3			No arguments.
	Move.l	Temp001(a5),a6
	Jsr	_LVOEasyRequestArgs(a6)	Put up the request.

	Move.l	#OpnLib_Error_Body_Length,d0	-.
	Move.l	Temp002(a5),a1			 |- Deallocate Msg mem.
	Bsr	LeoFreePooled			-'

OpnLib_Error__2
	Move.l	Temp001(a5),a1		-.
	N_CallExec	CloseLibrary	 |- Close intuition.library
	Bra	Finish			-'  and Finish program.
;---------------------------------------------------------------------------;
BuildLibList
	Move.l	#OpnLib_Error_Body_Length,d0	-.  Allocate for
	Bsr	LeoAllocPooled			-'  Error Message.
	Move.l	d0,Temp002(a5)
	Beq.s	OpnLib_Error__2		If Allocation failed, Exit Program

	Move.l	Temp002(a5),a1		Memory to write message into...
	Lea	OpnLib_Error_Body_Header(pc),a0
	Bsr	CopyCN3			Copy it (excluding null).

	Lea	LibData_Start(pc),a2	Start of struc w/ name-ptrs and ver#s
	Lea	LibBases_Start(a5),a3	Start of struc w/ Base-Adrs.

BuildLibList_MainLoop
	Lea	LibBases_Finish(a5),a4
	Cmp.l	a4,a3			All libraries been checked?
	Blt.s	OLEBL_Skp1
	SF	-1(a1)			-._ If so, null terminate
	RTS				-'  and return completed list.
OLEBL_Skp1
	Tst.l	(a3)+			Did this lib fail to open?
	Beq.s	OLEBL_Skp2		If not, don't include in msg.
	Addq.l	#8,a2			Update the other pointer.
	Bra.s	BuildLibList_MainLoop	Check the rest of the libs.

OLEBL_Skp2
	Lea	LibNames_Start(pc),a0	-._ Point to the name of
	Add.l	(a2)+,a0		-'  the lib.
	Bsr	CopyCN3			Copy it (excluding null).
	Move.b	#" ",(a1)+		A space after it.
	Move.b	#"v",(a1)+		version...

	Move.l	(a2)+,d1		Version of lib.
	Bsr	N2A2Dig			Convert number to output.
;	Note: N2A2Dig ONLY uses d1 and a1.
	Move.b	#10,(a1)+		A return after it.

	Bra.s	BuildLibList_MainLoop
;---------------------------------------------------------------------------;
OpnLib_Error_Error
	Lea	N_IntName(pc),a1
	Moveq	#0,d0			ANY version, using DisplayAlert()
	N_CallExec	OpenLibrary
	Move.l	d0,Temp001(a5)		Store base adr.
	Beq	Finish			If we can't get it, just exit!

	Lea	OpnLib_Error_Msg_Header(pc),a0
	Move.l	#OpnLib_Error_Msg_Height,d1
	Moveq	#RECOVERY_ALERT,d0	Not fatal to the rest of the system.
	Move.l	Temp001(a5),a6		-._ Send display alert
	Jsr	_LVODisplayAlert(a6)	-'  using Intuition.library

	Move.l	Temp001(a5),a1		-.
	N_CallExec	CloseLibrary	 |- Close intuition.library
	Bra	Finish			-'  and Finish program.

OpnLib_Error_Msg_Header
OpnLib_Error_Msg_Height	Equ 29
	Dc.w	15		X-coord (word)
	Dc.b	11		Y-coord (byte)
	PROGNAM
	Dc.b	":"
	SPACEEVEN	OpnLib_Error_Msg_Header
	Dc.b	0,1

	Dc.w	15
	Dc.b	20
	Dc.b	" Could not open intuition.library v37 (Kickstart 2.04) or above!"
	SPACEEVEN	OpnLib_Error_Msg_Header
	Dc.b	0,0
	Even
