; Reset v1.2 : Reset the Amiga
; by Kyzer/CSG
; $VER: Reset.asm 1.3 (08.04.98)
;
	incdir	include:
	include	lvo/dos_lib.i
	include	lvo/exec_lib.i
	include	lvo/graphics_lib.i
	include	lvo/intuition_lib.i
	include	exec/libraries.i
	include	dos/dosextens.i

Reset	move.l	4.w,a6
	sub.l	a1,a1
	jsr	_LVOFindTask(a6)
	move.l	d0,a4
	moveq	#0,d0
	tst.l	pr_CLI(a4)
	bne.s	.nomsg
	lea	pr_MsgPort(a4),a0
	jsr	_LVOWaitPort(a6)
	lea	pr_MsgPort(a4),a0
	jsr	_LVOGetMsg(a6)
.nomsg	tst.l	d0
	beq.s	.reset
	move.l	d0,-(sp)

	lea	intname(pc),a1
	moveq	#36,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.s	.noint
	move.l	d0,a6
	suba.l	a0,a0
	move.l	a2,a3
	suba.l	a2,a2
	pea	resp(pc)
	pea	body(pc)
	pea	title(pc)
	pea	0.w
	pea	20.w
	move.l	sp,a1
	jsr	_LVOEasyRequestArgs(a6)
	adda.w	#20,sp
	tst.l	d0
	bne.s	.reset

	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
.noint
	move.l	(sp)+,d0
	beq.s	.exit
	move.l	d0,a2
	jsr	_LVOForbid(a6)
	move.l	a2,a1
	jsr	_LVOReplyMsg(a6)
	jsr	_LVOPermit(a6)
.exit	moveq	#0,d0
	rts

.reset	move.l	4.w,a6
	lea	dosname(pc),a1
	moveq	#32,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.s	.die
	move.l	d0,a6
	moveq	#30,d1
	jsr	_LVODelay(a6)
	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
.die	lea	gfxname(pc),a1
	moveq	#32,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.s	.kill
	move.l	d0,a6
	suba.l	a1,a1
	jsr	_LVOLoadView(a6)
	jsr	_LVOWaitTOF(a6)
	jsr	_LVOWaitTOF(a6)
	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
.kill	move.w	#$000,$dff180	; custom.color00 == black
	cmp.w	#36,LIB_VERSION(a6)
	bcc.s	.wb13
	jmp	_LVOColdReboot(a6)
	; pre-v36 reset routine
.wb13	lea	$1000000,a0	; end of ROM
	sub.l	-$14(a0),a0	; (end of ROM)-(ROM size)=ROM start
	move.l	4(a0),a0	; Get initial PC
	subq.l	#2,a0		; now points to second RESET
	lea	.sup(pc),a5
	jmp	_LVOSupervisor(a6)
	cnop	0,4
.sup	reset			;\_ these two instructions must
	jmp	(a0)		;/  share a longword.


intname	dc.b	"intuition.library",0
dosname	dc.b	"dos.library",0
gfxname	dc.b	"graphics.library",0
title	dc.b	"Reset",0
body	dc.b	"This will reset your Amiga!!!",10
	dc.b	"Are you sure you want to go ahead?",0
resp	dc.b	"Reset|Cancel",0
