; Reset v1.0 - © Fréderic Delacroix
; Usage: Reset [CLEAR|DEEP|GURU GuruNumber]

	incdir	Include:
	include	exec/exec.i
	include	exec/execbase.i
	include	exec/exec_lib.i
	include	exec/alerts.i

MAGIC_ROMEND	EQU	$01000000
MAGIC_SIZEOFFSET	EQU	-$14
V36_EXEC	EQU	36
TEMP_ColdReboot	EQU	-726

	move.l	4.w,a6
	tst.l	d0
	beq	DoReset
	clr.b	-1(a0,d0)
	lea	CLEAR.KWD(pc),a1
	bsr	strcmp
	tst.w	d0
	bne.s	PasCLEAR
	clr.l	ColdCapture(a6)
	clr.l	CoolCapture(a6)
	clr.l	KickMemPtr(a6)
	clr.l	KickTagPtr(a6)
	clr.l	KickCheckSum(a6)
	bra	DoReset
PasCLEAR
	lea	GURU.KWD(pc),a1
	bsr.s	strcmp
	tst.w	d0
	bne.s	PasGURU
	add.l	#GURU.LGT,a0

	moveq	#0,d7
	moveq	#0,d0
nextchar
	cmp.b	#' ',(a0)
	bne.s	testit
	addq.l	#1,a0
	bra.s	nextchar
testit
	move.b	(a0)+,d0
	cmp.b	#"0",d0
	bmi.s	alert
	cmp.b	#"9"+1,d0
	bpl.s	nodigit
	sub.b	#"0",d0
addit
	lsl.l	#4,d7
	add.l	d0,d7
	bra.s	nextchar
nodigit
	cmp.b	#"a",d0
	bmi.s	NoUpper
	sub.b	#"a"-"A",d0
NoUpper
	cmp.b	#"A",d0
	bmi.s	alert
	cmp.b	#"F"+1,d0
	bpl.s	alert
	sub.b	#"A"-$a,d0
	bra.s	addit
alert
	suba.l	a5,a5
	jsr	_LVOAlert(a6)
	rts
PasGURU
	lea	DEEP.KWD(pc),a1
	bsr.s	strcmp
	tst.w	d0
	bne.s	DoReset
	clr.l	ChkBase(a6)
	bra.s	DoReset
strcmp
	move.l	a0,-(sp)
strcmpnextchar
	move.b	(a0)+,d0
	beq.s	strcmpendofstring
	cmp.b	#" ",d0
	beq.s	strcmpendofstring
	move.b	(a1)+,d1
	cmp.b	d0,d1
	beq.s	strcmpnextchar
strcmpdifferent
	moveq	#-1,d0
strcmpret
	move.l	(sp)+,a0
	rts
strcmpendofstring
	tst.b	(a1)
	bne.s	strcmpdifferent
	moveq	#0,d0
	bra.s	strcmpret
DoReset
	cmp.w	#V36_EXEC,LIB_VERSION(a6)	; Thanks to the french
	blt.s	old_exec			; magazine "Amiga NewsTech"
	jmp	TEMP_ColdReboot(a6)		; for this routine
old_exec
	lea	GoAway(pc),a5
	jsr	_LVOSupervisor(a6)
	CNOP	0,4
GoAway
	lea	MAGIC_ROMEND,a0
	sub.l	MAGIC_SIZEOFFSET(a0),a0
	move.l	4(a0),a0
	subq.l	#2,a0
	reset
	jmp	(a0)
	rts

CLEAR.KWD
	dc.b	'CLEAR',0
GURU.KWD
	dc.b	'GURU',0
GURU.LGT	EQU	4
DEEP.KWD
	dc.b	'DEEP',0
