; Program function:
;	install vblank interrupt
;	flick "flicker byte" each half second

; Vertical blank interrupt:
;	Fastest vblank on the Amiga is seventysomthing Hz
;	=> If the "flicker byte" is read being the same 50 times,
;	   the computer is rebooted. (This should give plenty margin
;	   for anomalies.)

; The binary was assembled using Devpac 3.04.

; a5=dosbase
; a4=allocated memory

	include	exec/exec.i
	include	exec/exec_lib.i
	include	dos/dos.i
	include	dos/dos_lib.i
	include	hardware/intbits.i
	
	section	main,CODE

main	movea.l	4.w,a6
	lea	dosname,a1
	moveq.l	#0,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.b	nodoslib
	movea.l	d0,a5
	moveq.l	#IS_SIZE,d0
	move.l	#MEMF_PUBLIC|MEMF_CLEAR,d1
	jsr	_LVOAllocMem(a6)
	tst.l	d0
	beq.b	nofreemem
	move.l	d0,a4
	move.b	#NT_INTERRUPT,(LN_TYPE,a4)
	move.b	#-1,(LN_PRI,a4)
	move.l	#int_nam,(LN_NAME,a4)
	move.l	#flicker,(IS_DATA,A4)
	move.l	#int_hnd,(IS_CODE,a4)
	moveq.l	#INTB_VERTB,d0
	movea.l	a4,a1
	jsr	_LVOAddIntServer(a6)
	tst.l	d0
	beq.b	noaddserv
	movea.l	a5,a6
.wait	moveq.l	#25,d1
	jsr	_LVODelay(a6)
	not.w	flicker
	bra.b	.wait

noaddserv
	movea.l	a4,a1
	moveq.l	#IS_SIZE,d0
	jsr	_LVOFreeMem(a6)
nofreemem
	movea.l	a5,a1
	jsr	_LVOCloseLibrary(a6)
nodoslib
	moveq.l	#20,d0
	rts

	section	data,DATA
	
dosname	DOSNAME
	even
int_nam	dc.b	"Guardhound",0
	even
flicker	dc.w	0
	dc.w	0	state at last test
	dc.b	0	counter for tester

	section	interrupt,CODE
int_hnd
	move.l	(a1),d0
	move.w	d0,d1
	swap	d0
	cmp.w	d0,d1
	beq.b	.liktst
	move.w	d0,(2,a1)
	clr.w	(4,a1)
	moveq.l	#0,d0
	rts

.liktst	addi.b	#1,(4,a1)
	cmpi.b	#50,(4,a1)
	bge.b	.reset
	moveq.l	#0,d0
	rts

	cnop	0,4
.reset	lea.l	2.w,a0	this is inside an interrupt=>we are in supervisor mode
	reset
	jmp	(a0)
