*****************************************************************************
*									    *
*	PROGRAM: LAlert (LastAlert)					    *
*	VERSION: 1.0							    *
*   SOURCE CODE: 7							    *
*	   DATE: 3.5.2002						    *
*      LANGUAGE: Assembler (DevPac V3.14)				    *
*	 SYSTEM: A1200	KS 40.68 WB 40.42 2MB chip 64MB fast 68030/50mhz    *
*									    *
*	 AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany	    *
*	  EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de 	    *
*									    *
*	COMMENT: displays the GURU's last meditation number		    *
*									    *
*		 getting information about the last alert is a bit	    *
*		 tricky. because both, the guru-number and the address 	    *
*		 where it happened, only stored at the zero-page.	    *
*		 both values are survive any reset as long as the	    *
*		 machine is not switched off. but due to the fact,	    *
*		 many programming errors cause invalid access to these	    *
*		 addresses, this memory is marked as invalid by the	    *
*		 enforcer. LAlert reads both longwords by an enforcer	    *
*		 friendly way. just a tiny blitter operation is used	    *
*		 to avoid any hit. the blitter copys both longwords to	    *
*		 a readable area from where they will printed to the	    *
*		 current output.					    *
*									    *
*    KNOWN BUGS: hmm?... LAlert is much short to make relevant mistakes.    *
*									    *
*		 LAlert is available at AmiNet util/moni/...		    *
*									    *
*		 for suggestions, hints/tips, and/or questions,		    *
*		 send an email! (see above for address)			    *
*									    *
*****************************************************************************

_custom	equ	$00DFF000

bltcon0	equ	$00000040
bltcon1	equ	$00000042
bltdpt	equ	$00000054
bltbpt	equ	$0000004C
bltapt	equ	$00000050
bltafwm	equ	$00000044
bltbmod	equ	$00000062
bltamod	equ	$00000064
bltcdat	equ	$00000070
bltsize	equ	$00000058
bltdmod	equ	$00000066

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

_LVOAllocMem          	equ	-198
_LVOFreeMem            	equ	-210
_LVOCloseLibrary       	equ	-414
_LVOOpenLibrary        	equ	-552

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

_LVOOwnBlitter		equ	-456
_LVODisownBlitter	equ	-462
_LVOWaitBlit		equ	-228

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

_LVOVPrintf		equ	-954

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

OpenLibs	movea.l	4.w,A6			;set EXEC to call a function

		moveq	#37,D0			;set version number
		lea	_DOSName(pc),A1		;set library name
		lea	_DOSBase(pc),A2		;set buffer for base
		jsr	_LVOOpenLibrary(A6)	;use EXEC to (openlibrary)
		move.l	D0,(A2)			;save base

		beq.b	CloseLibs		;no dosbase returned; quit

		moveq	#00,D0			;set version number
		lea	_GFXName(pc),A1		;set library name
		lea	_GFXBase(pc),A2		;set buffer for base
		jsr	_LVOOpenLibrary(A6)	;use EXEC to (openlibrary)
		move.l	D0,(A2)			;save base

		beq.b	CloseLibs		;no gfxbase returned; quit

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

		bsr.b	Main			;go mainpart

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

CloseLibs	movea.l	4.w,A6			;set EXEC to call a function

		move.l	_GFXBase(pc),D1		;get gfxbase
		beq.b	.skip			;branch if not open
		movea.l	D1,A1			;set gfxbase
		jsr	_LVOCloseLibrary(A6)	;use EXEC to (closelibrary)

.skip		move.l	_DOSBase(pc),D1		;get dosbase
		beq.b	.quit			;branch if not open
		movea.l	D1,A1			;set dosbase
		jsr	_LVOCloseLibrary(A6)	;use EXEC to (closelibrary)

.quit		rts				;go back (quit program)

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

_DOSBase	dc.l	0
_GFXBase	dc.l	0

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

_DOSName	dc.b	"dos.library",0
_GFXName	dc.b	"graphics.library",0

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

	dc.b "$VER: LAlert 1.0 7 (3.5.2002) by joerg riemer may'02",0

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

		cnop	0,4

************************************************ alloc a bit memory *********

Main		moveq	#8,D0			;required size of memory
		moveq	#2,D1			;chip memory, please!
		movea.l	4.w,A6			;set EXEC to call a function
		jsr	_LVOAllocMem(A6)	;use EXEC for (AllocMem)
		tst.l	D0			;got some memory ?
		beq.b	.quit			;NO?, isn't that realistic?!?

************************************************ read zero-page ($100,$104) *

		movea.l	D0,A2			;set memory_base

		movea.l	_GFXBase(pc),A6		;set GFX to call a function
		jsr	_LVOOwnBlitter(A6)	;use GFX to (OwnBlitter)
		jsr	_LVOWaitBlit(A6)	;wait for blitter finished

		lea	_custom,A5		;set custom_base
		move.l	A2,bltdpt(A5)		;set destination memory
		moveq	#0,D0
		move.l	D0,bltamod(A5)		;set blitter modulo (source)
		move.w	#$100,D0		;get source (z-page $100)
		move.l	D0,bltapt(A5)		;set source memory
		moveq	#-1,D0
		move.l	D0,bltafwm(A5)		;set blitter mask (source)
		move.l	#$9F00000,bltcon0(A5)	;set blitter control 1+2
		move.w	#$44,bltsize(A5)	;set size and start operation

		jsr	_LVOWaitBlit(A6)	;wait for blitter finished
		jsr	_LVODisownBlitter(A6)	;thanks a lot, no more blits!

************************************************ guru available? ************

		moveq	#-1,D0			;prepare register
		cmp.l	(A2),D0			;any meditation available?
		beq.b	.quit			;no, quit in silence

************************************************ print some information *****

		lea	Info(pc),A1		;get text "The GURU's..."
		move.l	A1,D1			;set text ...
		move.l	A2,D2			;set array

		movea.l	_DOSBase(pc),A6		;set DOS to call a function
		jsr	_LVOVPrintf(A6)		;use DOS to (vprintf) text

************************************************ free memory ****************

		movea.l	A2,A1			;set memory_base
		moveq	#8,D0			;set size
		movea.l	4.w,A6			;use EXEC to call a function
		jsr	_LVOFreeMem(A6)		;use EXEc to (freemem)

.quit		rts				;go back

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

Info	dc.b	$A,"The GURU's last meditation: $%08lx.$%08lx",$A,$A,0

 end of source **************************************************************
