* Program to display an Intuition alert and recover. *
* By Michael Cobb.  I used CAPE 68K to assemble this. *
* 28 May 88 *

	ObjFile "ram:alert.o"
	INCDIR  "CAPE2.5:includes"
	NOBLANKS
	OPTIMON

	INCLUDE "exec/types.i"
	INCLUDE "intuition/intuition.i"

EXT_SYS	MACRO
	XREF	_LVO\1
	ENDM

SYS	MACRO
	JSR	_LVO\1
	ENDM

	EXT_SYS	OpenLibrary	*same as saying XREF _LVOOpenLibrary
	EXT_SYS	CloseLibrary	*just saves some typing...
	EXT_SYS	DisplayAlert
	
	XREF	_AbsExecBase	*we don't say EXT_SYS _AbsExecBase 'cause
				*it would then be XREF _LVO_AbsExecBase
				*and would be very wrong.

* Open the Intuition library *

	move.l	sp,savesp			*save the stack pointer
	movea.l	_AbsExecBase,a6			*put _AbsExecBase in A6
        lea	intuition,a1			*address of intuition in A1
	moveq	#0,d0				*clear d0 (quicker than CLR)
	SYS	OpenLibrary(a6)			*openlibrary call
	move.l	d0,intuitionbase		*save the intuitionbase
						*pointer	
	beq.s	_error				*if zero bit set, then we
						*couldn't open the library

* Get the alert ready *

	movea.l	intuitionbase,a6		
	move.l	RECOVERY_ALERT,d0		*we can recover
	move.l	#40,d1				*the height
	lea.l	string,a0			*address of string into A0

* Display the routine and exit *

	SYS	DisplayAlert(a6)
	movea.l	savesp,sp			*recover the stack pointer
	moveq	#0,d0				*a 0 means OK!
	rts					*back to CLI
		
* The _Error routine, in case of a library call error.

_error:
	movea.l	savesp,sp		*return stack pointer
	moveq	#20,d0			*a 20 means a SERIOUS error occured
	rts				*return to CLI


		 DATA 				
*initialized data

* Here we define the string to go to the DisplayAlert() function.  The 
* components are:  the X-coordinate, the Y-coordinate, the actual text
* string (null terminated), and a continuation byte (being zero that
* signifies that there are no more sub-strings that follow).
* I had problems with the construction of this string in the beginning.
* But I finally figured it out.  You need to create a string containing
* those components so you can put a pointer to it in A0 for the function
* call. 

string		dc.w	240			* X-Coordinate		
		dc.b	23			* Y-Coordinate
		dc.b	'THIS IS AN ALERT',0	* The actual text 	
		dc.b	0			* The continuation byte
		cnop	0,2			* blank padding

intuition	dc.b	'intuition.library',0
		cnop	0,2

		BSS		
* uninitialized data	

intuitionbase	ds.l	1			* make space for these 
savesp		ds.l	1			* variables


		END
